Book. Signatures and grammars. Signatures and grammars. Syntaxes. The 4-layer architecture

Size: px
Start display at page:

Download "Book. Signatures and grammars. Signatures and grammars. Syntaxes. The 4-layer architecture"

Transcription

1 Book Generic Language g Technology (2IS15) Syntaxes Software Language g Engineering g by Anneke Kleppe (Addison Wesley) Prof.dr. Mark van den Brand / Faculteit Wiskunde en Informatica PAGE 1 Definition of a (programming) g) language g involves: abstract syntax, so-called signature concrete syntax: textual syntax graphical syntax semantics: static semantics dynamic semantics Grammar world The 4-layer architecture M3 (E)BNF/SDF grammar defines structure of the (E)BNF in (E)BNF M2 Java grammar defines the structure of Java in (E)BNF M1 Java program describes the manipulation (algorithm) of objects in the object layer M0 Object layer Objects we wish to manipulate / Faculteit Wiskunde en Informatica PAGE 2 / Faculteit Wiskunde en Informatica PAGE 3

2 Abstract syntax: defines basic structure of the language (skeleton) is starting point for defining: concrete syntax static semantics dynamic semantics Abstract syntax is a collection of constructors/- functions No information about keywords, priorities, iti associativities, etc. Abstract syntax definition of Booleans: true () -> BoolCon false () -> BoolCon con (BoolCon) -> Bool and (Bool, Bool) -> Bool or (Bool, Bool) -> Bool not (Bool) -> Bool constructor nonterminal / Faculteit Wiskunde en Informatica PAGE 4 / Faculteit Wiskunde en Informatica PAGE 5 There is no standardized way of defining abstract syntax SSL (specification formalism of the Synthesizer Generator) Signature-like (Meta-modeling) SSL (grammar specification formalism of the Synthesizer Generator) describes it as follows: A collection of rules that define phyla and operators A phylum is a nonempty set of terms A term is the application of a k-ary operator to k terms of the appropriate phylum A k-ary operator is a constructor function mapping k terms to a term A phylum can be considered a nonterminal phyl 0 : op(phyl 1 phyl 2 phyl k ) / Faculteit Wiskunde en Informatica PAGE 6 / Faculteit Wiskunde en Informatica PAGE 7

3 SSL notation of the definition of the abstract syntax of Booleans: boolcon : True() False() bool : Con(boolcon) And(bool bool) Or(bool bool) Signature describes it as follows: A collection of functions that define sorts and operators A sort represents a nonempty set of terms A term is the application of a k-ary operator to k terms of the appropriate sort A k-ary operator is a constructor function mapping k terms to aterm A sort can be considered a nonterminal op(sort( 1, sort 2,, sort k ) sort 0 / Faculteit Wiskunde en Informatica PAGE 8 / Faculteit Wiskunde en Informatica PAGE 9 Signature notation of the definition of the abstract syntax of Booleans: true () -> BoolCon false () -> BoolCon con (BoolCon) -> Bool and (Bool, Bool) -> Bool or (Bool, Bool) -> Bool not (Bool) -> Bool Given signatures it is possible to generate APIs Tooling for defining signatures and generating APIs: GOM part of TOM ( php5/documentation:gom) ApiGen part of SDF (see later) / Faculteit Wiskunde en Informatica PAGE 10 / Faculteit Wiskunde en Informatica PAGE 11

4 Definition of a (programming) language involves: lexical syntax, so-called tokens: identifiers, numbers, strings, if, then, class (keywords) context-free syntax, so-called production rules: Statement ::= if Expression then Statements else Statements fi static semantics: identification and scope resolution type checking dynamic semantics: operational semantics interpretation compilation Goal: defining languages g & manipulating programs SDF: Syntax definition Formalism lexical & context-free syntax ASF+SDF SDF Meta-Environment: t IDE for ASF+SDF SDF manuals/documentation: Spoofax/IMP: Eclipse plugin for SDF manuals/documentation: / Faculteit Wiskunde en Informatica PAGE 12 / Faculteit Wiskunde en Informatica PAGE 13 Anatomy of SDF specifications module A imports B C module B imports D module C module D Anatomy of an SDF module module ModuleName ImportSection* ExportOrHiddenSection* ti imports, aliases, sorts, lexical syntax, context-free syntax, priorities, variables Name of this module; may be followed by parameters Names of modules imported by this module; May be followed by renamings Grammar elements that are visible from the outside (exports) or only inside the module (hiddens). / Faculteit Wiskunde en Informatica PAGE 14 / Faculteit Wiskunde en Informatica PAGE 15

5 SDF by examples Boolean language Pico language Boolean Constants module basic/boolcon exports sorts BoolCon context-free syntax "true"" -> BoolCon {cons( true )} "false" -> BoolCon {cons( false )} Sort of Boolean constants Sorts should always start with a capital letter The constants true and false, literals should always be quoted / Faculteit Wiskunde en Informatica PAGE 16 / Faculteit Wiskunde en Informatica PAGE 17 Booleans module basic/booleans imports basic/boolcon exports sorts Boolean context-free syntax BoolCon -> Boolean {cons( con )} Import Boolean constants The sort of Boolean expressions Each Boolean constant is a Boolean Expression, also called injection rule or chain hi rule / Faculteit Wiskunde en Informatica PAGE 18 The infix operators and & and or. Both are left-associative (left) The prefix function not Boolean " " Boolean -> Boolean {cons( ns( or ), left} Boolean "&" Boolean -> Boolean {cons( and ), left} not (Boolean) -> Boolean {cons( not )} "(" Boolean ")" -> Boolean {bracket} ( and ) may be used as brackets in Boolean expressions; they are context-free priorities ignored after parsing Boolean "&" Boolean -> Boolean > & has higher h priority it than Boolean " " Boolean -> Boolean Example: Bool & Bool Bool is interpreted as: (Bool & Bool) Bool / Faculteit Wiskunde en Informatica PAGE 19

6 hiddens context-free start-symbols Boolean The start symbol of a grammar. Without a start symbol the parser does not know how to start parsing an input sentence imports basic/comments Import the standard comments Summary: Each module defines a language; in this case the language of Booleans (synonym: data type) We can use this language definition to Create a (syntax-directed) editor for the Boolean language and create Boolean terms Import it in another module; this makes the Boolean language available for the importing module / Faculteit Wiskunde en Informatica PAGE 20 / Faculteit Wiskunde en Informatica PAGE 21 A toy language g Pico: Pico has two types: natural number and string Variables have to be declared Statements: assign, if-then-else, while-do Expressions: natural, string, +, - and + and - have natural operands; the result is natural has string operands and the result is string Tests (if, while) should be of type natural input value begin declare input : natural, output : natural, repnr : natural, output value rep : natural; input := 14; output := 1; What does this program compute? while input - 1 do rep := output; repnr := input; while repnr - 1 do output := output + rep; repnr := repnr - 1 od; input := input - 1 od end / Faculteit Wiskunde en Informatica PAGE 22 / Faculteit Wiskunde en Informatica PAGE 23

7 begin declare input : natural, output : natural, repnr : natural, rep : natural; input := 14; output := 1; while input - 1 do rep := output; repnr := input; while repnr - 1 do output := output + rep; repnr := repnr - 1 od; input := input - 1 od end input value output value What does this program compute? 14! = 14 * 13 * * 1 Why is it written in this clumsy style? (a) Pico has no input/output statements (b) Pico has no multiplication operator Defining the syntax for Pico basic/natcon basic/whitespace basic/strcon languages/pico/syntax/pico languages/pico/syntax/types languages/pico/syntax/identifiers / Faculteit Wiskunde en Informatica PAGE 24 / Faculteit Wiskunde en Informatica PAGE 25 module languages/pico/syntax/pico imports Sorts and syntax rules lesfor languages/pico/syntax/identifiers program and declarations languages/pico/syntax/types basic/natcon basic/strcon exports List of zero or more sorts statements separated by ; PROGRAM DECLS ID-TYPE STATEMENT EXP zero or more context-free start-symbols * + one or more PROGRAM context-free syntax "begin" DECLS {STATEMENT ";"}* "end" -> PROGRAM {cons( program )} "declare" {ID-TYPE ","}* ";" -> DECLS {cons( decls )} PICO-ID ":" TYPE -> ID-TYPE {cons( id-type )} Syntax rules for statemen PICO-ID ID ":="" EXP -> STATEMENT {cons( assign )} "if" EXP "then" {STATEMENT ";"}* "else" {STATEMENT ";"}* "fi" -> STATEMENT {cons( cond )} "while" EXP "do" {STATEMENT ";"}* "od -> STATEMENT {cons( loop )} / Faculteit Wiskunde en Informatica PAGE 26 / Faculteit Wiskunde en Informatica PAGE 27

8 PICO-ID -> EXP {cons( id )} NatCon -> EXP {cons( nat )} StrCon -> EXP {cons( str )} EXP "+" EXP -> EXP {cons( plus ), left} EXP "-" EXP -> EXP {cons( min ), left} EXP " " EXP -> EXP {cons( conc ), left} "(" EXP ") -> EXP {bracket} context-free priorities EXP " " EXP -> EXP > EXP "-" EXP -> EXP > EXP "+" EXP -> EXP Syntax rules for expressions The sort NatCon is imported from basic/natcon The sort StrCon is imported from basic/strcon Binary operators are left-associative The priorities of the binary operators, a disambiguation construct: 1 - (2 + 3), or (1-2) + 3 Lexical syntax: Identifiers module languages/pico/syntax/identifiers exports sorts PICO-ID lexical syntax [a-z] [a-z0-9]* -> PICO-ID lexical l restrictions PICO-ID -/- [a-z0-9] Repeat zero (*) or one (+)ormoretimes A lexical restriction: is aaa three, two or one identifier? -/- can be used to define longest match A character class: PICO-ID Starts with a lowercase letter / Faculteit Wiskunde en Informatica PAGE 28 / Faculteit Wiskunde en Informatica PAGE 29 Pico-Types module languages/pico/syntax/types exports sorts TYPE context-free syntax "natural" -> TYPE {cons( natural )} "string" " -> TYPE {cons( string )} The sort of possible types in a Pico program The constants natural and string represent types as can be declared in Pico program Summary The modules languages/pico/syntax/pico defines (together with the imported modules) the syntax for the Pico language This syntax can be used to Generate a parser that can parse Pico programs Generate a syntax-directed editor for Pico programs / Faculteit Wiskunde en Informatica PAGE 30 / Faculteit Wiskunde en Informatica PAGE 31

9 An elementary symbol is: Literal: abc Sort (non-terminal) names: INT Character classes: [a-z]: one of a, b,, z ~: complement of character class. /: difference of two character classes. /\: intersection of two character classes. \/: union of two character classes. A complex symbol is: Repetition: S* zero or more times S; S+ one or more times S {S1 S2}* zero or more times S1 separated by S2 {S1 S2}+ one or more times S1 separated by S2 Optional: S? zero or one occurrences of S Alternative: S T an S or a T Tuple: <S,T> shorthand for < S, T > Parameterized sorts: S[[ P1, P2 ]] / Faculteit Wiskunde en Informatica PAGE 32 / Faculteit Wiskunde en Informatica PAGE 33 Productions (functions): General form of a production (function): S1 S2 Sn -> S0 Attributes Lexical syntax and context-free syntax are similar, but Between the symbols in a production optional layout symbols may occur in the input text. A context-free t production is equivalent with: S1 LAYOUT? S2 LAYOUT? LAYOUT? Sn -> S0 Floating point numbers sorts UnsignedInt SignedInt UnsignedReal Number lexical syntax [0] ([1-9][0-9]*) -> UnsignedInt [\+\-]? UnsignedInt -> SignedInt UnsignedInt "." [0-9]+ ([ee] SignedInt)? -> UnsignedReal UnsignedInt [ee] SignedInt -> UnsignedReal UnsignedInt UnsignedReal -> Number e e e e-07 / Faculteit Wiskunde en Informatica PAGE 34 / Faculteit Wiskunde en Informatica PAGE 35

10 Various ways of constructing lists A+ a a a a Assume: a -> A {A ; }+ a a ; a a ; a; a a ; a; a; (A ; )+ a ; a ; a; a ; a; a; a ; a; a (A ;?)+ ;?) a a a a ; a a ; a; / Faculteit Wiskunde en Informatica PAGE 36

Plan. Booleans. Variables have to be dec. Steps towards a Pico environment. Expressions: natural, string, +, - and + and - have natural ope

Plan. Booleans. Variables have to be dec. Steps towards a Pico environment. Expressions: natural, string, +, - and + and - have natural ope Booleans Plan Steps towards a Pico environment Step 1: define syntax Step 2: define a typechecker Step 3: define an evaluat tor Step 4: define a compiler Traversal functions Methodology Introduction to

More information

The Syntax Definition Formalism SDF

The Syntax Definition Formalism SDF Mark van den Brand Paul Klint Jurgen Vinju 2007-10-22 17:18:09 +0200 (Mon, 22 Oct 2007) Table of Contents An Introduction to SDF... 2 Why use SDF?... 2 How to use SDF... 4 Learning more... 4 This document...

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Syntax. A. Bellaachia Page: 1

Syntax. A. Bellaachia Page: 1 Syntax 1. Objectives & Definitions... 2 2. Definitions... 3 3. Lexical Rules... 4 4. BNF: Formal Syntactic rules... 6 5. Syntax Diagrams... 9 6. EBNF: Extended BNF... 10 7. Example:... 11 8. BNF Statement

More information

CPS 506 Comparative Programming Languages. Syntax Specification

CPS 506 Comparative Programming Languages. Syntax Specification CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

More information

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1 Defining Program Syntax Chapter Two Modern Programming Languages, 2nd ed. 1 Syntax And Semantics Programming language syntax: how programs look, their form and structure Syntax is defined using a kind

More information

Model transformations. Model transformations. Model transformations. Model transformations

Model transformations. Model transformations. Model transformations. Model transformations The initialization of the attributes of a generated target model element by assigning references: Model target element generated by current rule Default target model element generated by another rule Non-default

More information

The term. reduces to

The term. reduces to Pico-typech hecking (13) The function startt connects the Pico-typechecker to the Meta-Environm ment (compare with main in C or Java) PROGRAM: the actual sort of the input program Program: the actual Pico

More information

Grammars and Parsing. Paul Klint. Grammars and Parsing

Grammars and Parsing. Paul Klint. Grammars and Parsing Paul Klint Grammars and Languages are one of the most established areas of Natural Language Processing and Computer Science 2 N. Chomsky, Aspects of the theory of syntax, 1965 3 A Language...... is a (possibly

More information

Model transformations. Overview of DSLE. Model transformations. Model transformations. The 4-layer architecture

Model transformations. Overview of DSLE. Model transformations. Model transformations. The 4-layer architecture Overview of DSLE Model driven software engineering g in general Grammars, signatures and meta-models DSL Design Code generation Models increase the level of abstraction used for both hardware and software

More information

Domain-Specific Languages for Composable Editor Plugins

Domain-Specific Languages for Composable Editor Plugins Domain-Specific Languages for Composable Editor Plugins LDTA 2009, York, UK Lennart Kats (me), Delft University of Technology Karl Trygve Kalleberg, University of Bergen Eelco Visser, Delft University

More information

Renaud Durlin. May 16, 2007

Renaud Durlin. May 16, 2007 A comparison of different approaches EPITA Research and Development Laboratory (LRDE) http://www.lrde.epita.fr May 16, 2007 1 / 25 1 2 3 4 5 2 / 25 1 2 3 4 5 3 / 25 Goal Transformers:

More information

3. Context-free grammars & parsing

3. Context-free grammars & parsing 3. Context-free grammars & parsing The parsing process sequences of tokens parse tree or syntax tree a / [ / index / ]/= / 4 / + / 2 The parsing process sequences of tokens parse tree or syntax tree a

More information

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi UNIT I Programming Language Syntax and semantics B y Kainjan Sanghavi Contents Language Definition Syntax Abstract and Concrete Syntax Concept of binding Language Definition Should enable a person or computer

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring SOLUTION CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

DaMPL. Language Reference Manual. Henrique Grando

DaMPL. Language Reference Manual. Henrique Grando DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4

More information

ECE251 Midterm practice questions, Fall 2010

ECE251 Midterm practice questions, Fall 2010 ECE251 Midterm practice questions, Fall 2010 Patrick Lam October 20, 2010 Bootstrapping In particular, say you have a compiler from C to Pascal which runs on x86, and you want to write a self-hosting Java

More information

PL Revision overview

PL Revision overview PL Revision overview Course topics Parsing G = (S, P, NT, T); (E)BNF; recursive descent predictive parser (RDPP) Lexical analysis; Syntax and semantic errors; type checking Programming language structure

More information

Rscript: examples. Rscript in a Nutshell. Rscript: examples. Comprehensions. Set: {3, 5, 3}

Rscript: examples. Rscript in a Nutshell. Rscript: examples. Comprehensions. Set: {3, 5, 3} Rscript in a Nutshell Basic types: bool, int, str, loc (text location in specific file with comparison operators) Sets, relations and associated operations (domain, range, inverse, projection,...) Comprehensions

More information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing Görel Hedin Revised: 2017-09-04 This lecture Regular expressions Context-free grammar Attribute grammar

More information

Flang typechecker Due: February 27, 2015

Flang typechecker Due: February 27, 2015 CMSC 22610 Winter 2015 Implementation of Computer Languages I Flang typechecker Due: February 27, 2015 Project 3 February 9, 2015 1 Introduction The third project is to implement a type checker for Flang,

More information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF) Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical

More information

A simple evaluation function... 1 Symbolic Differentiation... 1 Sorting... 2 Code Generation... 3 Larger ASF+SDF Specifications...

A simple evaluation function... 1 Symbolic Differentiation... 1 Sorting... 2 Code Generation... 3 Larger ASF+SDF Specifications... 2007-10-19 14:28:14 +0200 (Fri, 19 Oct 2007) Table of Contents A simple evaluation function... 1 Symbolic Differentiation... 1 Sorting... 2 Code Generation... 3 Larger ASF+SDF Specifications... 8 Warning

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

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

More Assigned Reading and Exercises on Syntax (for Exam 2) More Assigned Reading and Exercises on Syntax (for Exam 2) 1. Read sections 2.3 (Lexical Syntax) and 2.4 (Context-Free Grammars) on pp. 33 41 of Sethi. 2. Read section 2.6 (Variants of Grammars) on pp.

More information

Modules, Structs, Hashes, and Operational Semantics

Modules, Structs, Hashes, and Operational Semantics CS 152: Programming Language Paradigms Modules, Structs, Hashes, and Operational Semantics Prof. Tom Austin San José State University Lab Review (in-class) Modules Review Modules from HW 1 (in-class) How

More information

The Decaf language 1

The Decaf language 1 The Decaf language 1 In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter 6.037 Lecture 4 Interpretation Interpretation Parts of an interpreter Meta-circular Evaluator (Scheme-in-scheme!) A slight variation: dynamic scoping Original material by Eric Grimson Tweaked by Zev Benjamin,

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder Outline 1 2 3 4 What is Haskell? Haskell is a functional programming language. Characteristics functional non-strict ( lazy ) pure (no side effects*) strongly statically typed available compiled and interpreted

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

CSE 401 Midterm Exam Sample Solution 2/11/15

CSE 401 Midterm Exam Sample Solution 2/11/15 Question 1. (10 points) Regular expression warmup. For regular expression questions, you must restrict yourself to the basic regular expression operations covered in class and on homework assignments:

More information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

CSC 467 Lecture 3: Regular Expressions

CSC 467 Lecture 3: Regular Expressions CSC 467 Lecture 3: Regular Expressions Recall How we build a lexer by hand o Use fgetc/mmap to read input o Use a big switch to match patterns Homework exercise static TokenKind identifier( TokenKind token

More information

Infrastructure for Program Transformation Systems

Infrastructure for Program Transformation Systems Master Course Program Transformation 2004-2005 Martin Bravenboer Institute of Information & Computing Sciences Utrecht University, The Netherlands February 10, 2005 Planet Stratego/XT Stratego Language

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

UPTR - a simple parse tree representation format

UPTR - a simple parse tree representation format UPTR - a simple parse tree representation format Jurgen Vinju Software Transformation Systems October 22, 2006 Quality of Software Transformation Systems Some Questions on Parsing Two pragmatical steps

More information

A simple. programming language and its implementation. P. Klint. J.A. Bergstra J. Heering

A simple. programming language and its implementation. P. Klint. J.A. Bergstra J. Heering 2 A simple programming language and its implementation J.A. Bergstra J. Heering P. Klint In this chapter we give a complete definition of the toy language PICO by specifying the parsing, typechecking and

More information

Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

More information

Language Reference Manual

Language Reference Manual Espresso Language Reference Manual 10.06.2016 Rohit Gunurath, rg2997 Somdeep Dey, sd2988 Jianfeng Qian, jq2252 Oliver Willens, oyw2103 1 Table of Contents Table of Contents 1 Overview 3 Types 4 Primitive

More information

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification Written by Julie Zelenski and updated by Jerry Cain and Keith Schwarz. In this course, we will write a compiler for a simple object oriented

More information

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no Questions? First exercise is online: http://www.win.tue.nl/~mvdbrand/courses/glt/1112/ Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Primitive types Primitive value

More information

Introduction to Programming (Java) 2/12

Introduction to Programming (Java) 2/12 Introduction to Programming (Java) 2/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( ) Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.

More information

Type Checking. Chapter 6, Section 6.3, 6.5

Type Checking. Chapter 6, Section 6.3, 6.5 Type Checking Chapter 6, Section 6.3, 6.5 Inside the Compiler: Front End Lexical analyzer (aka scanner) Converts ASCII or Unicode to a stream of tokens Syntax analyzer (aka parser) Creates a parse tree

More information

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of

More information

IC Language Specification

IC Language Specification CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially

More information

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1 Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part 1 1. Introduction Parsing is the task of Syntax Analysis Determining the syntax, or structure, of a program. The syntax is defined by the grammar rules

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Examples of attributes: values of evaluated subtrees, type information, source file coordinates, 1 2 3 Attributes can be added to the grammar symbols, and program fragments can be added as semantic actions to the grammar, to form a syntax-directed translation scheme. Some attributes may be set by

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction Semantic Analysis David Sinclair Semantic Actions A compiler has to do more than just recognise if a sequence of characters forms a valid sentence in the language. It must

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER COMPILERS ANSWERS. Time allowed TWO hours

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER COMPILERS ANSWERS. Time allowed TWO hours The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER 2009 2010 COMPILERS ANSWERS Time allowed TWO hours Candidates may complete the front cover of their answer book

More information

Semantic Analysis. Compiler Architecture

Semantic Analysis. Compiler Architecture Processing Systems Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Source Compiler Architecture Front End Scanner (lexical tokens Parser (syntax Parse tree Semantic Analysis

More information

Rscript: a Relational Approach to Program and System Understanding

Rscript: a Relational Approach to Program and System Understanding Rscript: a Relational Approach to Program and System Understanding Paul Klint 1 Structure of Presentation Background and context About program understanding Roadmap: Rscript 2 Background Application areas

More information

CMSC 330: Organization of Programming Languages. Context Free Grammars

CMSC 330: Organization of Programming Languages. Context Free Grammars CMSC 330: Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Analyzer Optimizer Code Generator Abstract Syntax Tree Front End Back End Compiler

More information

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

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ Specifying Syntax Language Specification Components of a Grammar 1. Terminal symbols or terminals, Σ Syntax Form of phrases Physical arrangement of symbols 2. Nonterminal symbols or syntactic categories,

More information

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong.

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong. Data Abstraction An Abstraction for Inductive Data Types Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Introduction This lecture

More information

Programming Language Concepts, cs2104 Lecture 04 ( )

Programming Language Concepts, cs2104 Lecture 04 ( ) Programming Language Concepts, cs2104 Lecture 04 (2003-08-29) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-09-05 S. Haridi, CS2104, L04 (slides: C. Schulte, S. Haridi) 1

More information

A simple syntax-directed

A simple syntax-directed Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character

More information

A programming language requires two major definitions A simple one pass compiler

A programming language requires two major definitions A simple one pass compiler A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

CSE 3302 Programming Languages Lecture 2: Syntax

CSE 3302 Programming Languages Lecture 2: Syntax CSE 3302 Programming Languages Lecture 2: Syntax (based on slides by Chengkai Li) Leonidas Fegaras University of Texas at Arlington CSE 3302 L2 Spring 2011 1 How do we define a PL? Specifying a PL: Syntax:

More information

Compilers. Compiler Construction Tutorial The Front-end

Compilers. Compiler Construction Tutorial The Front-end Compilers Compiler Construction Tutorial The Front-end Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:compilers

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Syntax Intro and Overview. Syntax

Syntax Intro and Overview. Syntax Syntax Intro and Overview CS331 Syntax Syntax defines what is grammatically valid in a programming language Set of grammatical rules E.g. in English, a sentence cannot begin with a period Must be formal

More information

Principles of Programming Languages COMP251: Syntax and Grammars

Principles of Programming Languages COMP251: Syntax and Grammars Principles of Programming Languages COMP251: Syntax and Grammars Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong, China Fall 2007

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

More information

CSE 401 Midterm Exam Sample Solution 11/4/11

CSE 401 Midterm Exam Sample Solution 11/4/11 Question 1. (12 points, 2 each) The front end of a compiler consists of three parts: scanner, parser, and (static) semantics. Collectively these need to analyze the input program and decide if it is correctly

More information

4. Semantic Processing and Attributed Grammars

4. Semantic Processing and Attributed Grammars 4. Semantic Processing and Attributed Grammars 1 Semantic Processing The parser checks only the syntactic correctness of a program Tasks of semantic processing Checking context conditions - Declaration

More information

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. Lecture 09: Data Abstraction ++ Parsing Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. program text Parser AST Processor Compilers (and some interpreters)

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

Transition from EBNF to Xtext

Transition from EBNF to Xtext Transition from EBNF to Xtext Jianan Yue State Key Laboratory for Novel Software Technology, Nanjing University Department of Computer Science & Technology, Nanjing University 210023 Nanjing, China b111220168@smail.nju.edu.cn

More information

arxiv: v1 [cs.pl] 21 Jan 2013

arxiv: v1 [cs.pl] 21 Jan 2013 A DSL for Mapping Abstract Syntax Models to Concrete Syntax Models in ModelCC Luis Quesada, Fernando Berzal, and Juan-Carlos Cubero Department Computer Science and Artificial Intelligence, CITIC, University

More information

DEMO A Language for Practice Implementation Comp 506, Spring 2018

DEMO A Language for Practice Implementation Comp 506, Spring 2018 DEMO A Language for Practice Implementation Comp 506, Spring 2018 1 Purpose This document describes the Demo programming language. Demo was invented for instructional purposes; it has no real use aside

More information

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Semantic Analysis Compiler Architecture Front End Back End Source language Scanner (lexical analysis)

More information

... is a Programming Environment (PE)?... is Generic Language Technology (GLT)?

... is a Programming Environment (PE)?... is Generic Language Technology (GLT)? Introduction to Generic Language Technology Today Mark van den Brand Paul Klint Jurgen Vinju Tools for software analysis and manipulation Programming language independent (parametric) The story is from

More information

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS Spoke Language Reference Manual* William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 (yw2347, ct2459, zy2147, xc2180)@columbia.edu Columbia University,

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Software Engineering using Formal Methods Introduction to Promela Wolfgang Ahrendt 03 September 2015 SEFM: Promela /GU 150903 1 / 36 Towards Model Checking System Model Promela Program byte n = 0; active

More information

An Oz Subset. 1 Microsyntax for An Oz Subset. Notational Conventions. COP 4020 Programming Languages 1 January 17, 2012

An Oz Subset. 1 Microsyntax for An Oz Subset. Notational Conventions. COP 4020 Programming Languages 1 January 17, 2012 COP 4020 Programming Languages 1 January 17, 2012 An Oz Subset This document describes a subset of Oz [VH04] that is designed to be slightly larger than the declarative kernel language of chapter 2 (of

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information