Tree-based abstract syntax

Similar documents
Basics of interpretation with Haskell as the metalanguage

Type systems (An introduction)

Denotational semantics (An introduction)

Parsing a primer. Ralf Lämmel Software Languages Team University of Koblenz-Landau

Compilation a primer

The lambda calculus (An introduction)

Term rewriting a primer

CSc 520 Principles of Programming Languages

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

Syntax and Grammars 1 / 21

Lab 6: More Steps in Haskell

Programming Languages Fall 2014

Fundamental Concepts. Chapter 1

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

Compilers. Compiler Construction Tutorial The Front-end

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

The SPL Programming Language Reference Manual

More Assigned Reading and Exercises on Syntax (for Exam 2)

Mandatory Exercise 1 INF3110

CSCI 3155: Lab Assignment 2

Intermediate Code Generation

Lecture Compiler Middle-End

Decaf Language Reference Manual

CS 320: Concepts of Programming Languages

CIS 500 Software Foundations Midterm I Answer key October 8, 2003

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Program Representations

Lexical Considerations

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

Introduction to Programming Using Java (98-388)

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Principles of Programming Languages 2017W, Functional Programming

Reusable Components of Semantic Specifications

SECTION II: LANGUAGE BASICS

CA4003 Compiler Construction Assignment Language Definition

The PCAT Programming Language Reference Manual

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Topic 1: Introduction

In Our Last Exciting Episode

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

(Algebraically oriented) domain modeling in Haskell

Lexical Considerations

Reasoning About Programs Panagiotis Manolios

4. Inputting data or messages to a function is called passing data to the function.

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL

CS422 - Programming Language Design

Modules, Structs, Hashes, and Operational Semantics

Introduction to Semistructured Data and XML

Lesson 4 Typed Arithmetic Typed Lambda Calculus

Relation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics

Decaf Language Reference

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Semantics. Semantics

Programming Languages

1 Lexical Considerations

CIS 500 Software Foundations Fall September 25

Programming Languages, Summary CSC419; Odelia Schwartz

Grammar Convergence. Ralf Lämmel and Vadim Zaytsev Software Languages Team Universität Koblenz-Landau. 13 февраля 2009 г.

Lecture 8 CS 412/413 Spring '00 -- Andrew Myers 2. Lecture 8 CS 412/413 Spring '00 -- Andrew Myers 4

CS152: Programming Languages. Lecture 2 Syntax. Dan Grossman Spring 2011

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

ASML Language Reference Manual

CS 320: Concepts of Programming Languages

CSE-304 Compiler Design

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

Metamodeling with Metamodels. Using. UML/MOF including OCL

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

Lecture 4 Abstract syntax

The Decaf language 1

Programming Languages Fall 2013

Declarative Intraprocedural Flow Analysis of Java Source Code

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Formal Systems and their Applications

INSTITUTE OF AERONAUTICAL ENGINEERING

Reflection (in fact, Java introspection)

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

CS 6110 S14 Lecture 38 Abstract Interpretation 30 April 2014

OCL parsing / type checking in the context of GF and KeY. Kristofer Johannisson

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

Oat v. 2 Language Specification

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

More Lambda Calculus and Intro to Type Systems

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences]

Whereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

CSCI 3155: Lab Assignment 2

Introduction to Programming (Java) 2/12

The Decaf Language. 1 Lexical considerations

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences]

Transcription:

Tree-based abstract syntax Ralf Lämmel Software Language Engineering Team University of Koblenz-Landau http://www.softlang.org/

A conditional expression Concrete syntax Abstract syntax Text Tree Tree as term if true then zero else succ zero if true zero succ zero if(true, zero, succ(zero)). N.B.: abstract syntax is relevant in i) programming language theory as foundation for assigning semantics to programs and ii) metaprogramming for object program representation.

Signature-based definition of the abstract syntax of expressions symbol true : æ expr ; // The Boolean "true" symbol false : æ expr ; // The Boolean "false" symbol zero : æ expr ; // The natural number zero symbol succ : expr æ expr ; // Successor of a natural number symbol pred : expr æ expr ; // Predecessor of a natural number symbol iszero : expr æ expr ; // Test for a number to be zero symbol if : expr expr expr æ expr ; // Conditional n N.B.: A signature defines a set of terms. For instance, the set defined by the signature at hand contains the following term: if(true, zero, succ(zero)).

Conformance Term t is of sort s according to signature Σ, if: Σ has a function symbol f such that: f is the outermost symbol of t, the result sort of f is s, the arguments of t are terms of the argument sorts of f according to signature Σ.

Abstract syntax of an imperative programming language // Statements symbol skip : æ stmt ; symbol assign : string expr æ stmt ; symbol seq : stmt stmt æ stmt ; symbol if : expr stmt stmt æ stmt ; symbol while : expr stmt æ stmt ; // Expressions symbol intconst : integer æ expr ; symbol var : string æ expr ; symbol unary : uop expr æ expr ; symbol binary : bop expr expr æ expr ; string is a primitive type integer is a primitive type uop (unary symbols) elided bop (binary symbols) elided

Abstract syntax in the context of metaprogramming Metaprogram program with programs as data Metalanguage language in which metaprograms are written Object program program manipulated by metaprogram Object language language of object programs Object program representation abstract syntax-based representation of object programs in metaprograms N.B.: object language should be understood in a broad sense to include programming languages as well as other kinds of software languages, e.g., modeling languages and exchange formats. Conformance may thus boil down to type checking or schema-based validation.

Object-program representation in Haskell data Expr = TRUE FALSE Zero Succ Expr Pred Expr IsZero Expr If Expr Expr Expr Algebraic data types sampleexpr :: Expr Term construction sampleexpr = Pred (If (IsZero Zero) (Succ Zero) Zero)

Object-program representation in Java public abstract class Expr { } public class True extends Expr { } public class False extends Expr { } public class Zero extends Expr { } public class Succ extends Expr { public Expr e; public Succ(Expr e) { this.e = e; } } public class Pred extends Expr {... } public class IsZero extends Expr {... } public class If extends Expr {... } Object model Expr sample = new Pred( new If( new IsZero(new Zero()), new Succ(new Zero()), new Zero())); Functional construction

Object-program representation in JSON { } "pred": { "if": { "x": { "iszero": { "zero": { } } }, "y": { "succ": { "succ": { "zero": { } } } }, "z": { "zero": { } } } } Instance { } "$schema": "http://json-schema.org/draft-04/schema#", "description": "schema for BTL syntax", "type": "object", "oneof": [ { "properties": { "true" : { "additionalproperties": false } }, "additionalproperties": false },... Schema ]

Object-program representation in XML <pred xmlns="http://www.softlang.org/btl"> <if> <iszero><zero/></iszero> <succ><succ><zero/></succ></succ> <zero/> </if> </pred> Instance <schema...> <element name="true"><complextype/></element> <element name="false"><complextype/></element>... <element name="if"> <complextype> <group ref="tns:expr" minoccurs="3" maxoccurs="3"/> </complextype> </element> <complextype name="expr"> Schema <group ref="tns:expr"/> </complextype> <group name="expr"><choice>...</choice></group> </schema>

The metametalevel: the signature of signatures type signature = decl ; symbol type : sort typeexpr æ decl ; symbol symbol : fsym typeexpr sort æ decl ; symbol boolean : æ typeexpr ; symbol integer : æ typeexpr ; symbol float : æ typeexpr ; symbol string : æ typeexpr ; symbol term : æ typeexpr ; symbol sort : sort æ typeexpr ; symbol star : typeexpr æ typeexpr ; symbol plus : typeexpr æ typeexpr ; symbol option : typeexpr æ typeexpr ; symbol tuple : typeexpr æ typeexpr ; type sort = string ; type fsym = string ; There is one symbol for each construct of the extended signature notation described in ditto notation. We use extended notation: * for lists type for products / structural types N.B.: We may also be interested in the grammar of signatures and the signature of grammars and in a metamodel (i.e., a graphbased abstract syntax definition) of signatures etc.

Online resources YAS (Yet Another SLR (Software Language Repository)) http://www.softlang.org/yas YAS GitHub repository contains all code. See language BTL (for examples). See languages BSL and ESL (for signature notations). The Software Languages Book http://www.softlang.org/book The book discusses tree-based abstract syntax and object-program representation in detail. Other related subjects: concrete syntax, graph-based abstract syntax,