Declarative Language Definition
|
|
- Miranda Atkins
- 5 years ago
- Views:
Transcription
1 Declarative Language Definition (state-of-the-art & research agenda) Eelco Visser IPA Spring Days 2012 Garderen, Netherlands
2 Software Engineering Problem Domain Machine bridging the gap between problem domain and solution domain
3 High-Level Languages Problem Domain HLL Machine "A programming language is low level when its programs require attention to the irrelevant." Alan J. Perlis (1982) HLLs reduce gap
4 Domain-Specific Languages Problem Domain DSL HLL Machine domain-specific languages support more specialization
5 Software Language Design & Engineering enable software engineers to effectively design, implement, and apply domain-specific software languages
6 Research: Software Language Design systematically design domain-specific software languages with optimal tradeoff between expressivity, completeness, portability, coverage, and maintainability
7 Software Language Design Case Studies Mobl: client-side stateful web applications WebDSL: server-side restful web applications
8 Research: Software Language Engineering automatically derive efficient, scalable, incremental compiler + usable IDE from high-level, declarative language definition
9 The Spoofax Language Workbench creating full featured IDEs for domain-specific languages
10 Language Design
11 Language Design using Web; namespace Web { partial class URL { string GetLocation() { return location; namespace Blogger { class User { string name; URL homepage; class BlogPosting { User poster; string body; URL Homepage() { return poster.homepage; string Location() { return Homepage().GetLocation(); namespace Web { partial class URL { string location;
12 Test-Driven Language Design
13 Language Examples
14 Language Tests test compilation unit [[ using Web; namespace Blogger { class User { string name; class BlogPosting { User poster; string body; URL Homepage() { return poster.homepage; string Location() { return Homepage().GetLocation(); ]] parse
15 Declarative Syntax Definition
16 module Csharp imports Common exports context-free start-symbols CompUnit context-free syntax -> CompUnit {"CompUnit" %%...
17 Grammar Rules Using* Definition* -> CompUnit {"CompUnit" %% Namespaces "namespace" ID "{" Definition* "" -> Definition {"Namespace" "using" UsingPart ";" -> Using {"Using" ID -> UsingPart {"UsingPart" UsingPart "." ID -> UsingPart {"UsingPart"
18 Grammar Rules %% Classes "partial" "class" ID "{" ClassBodyDecl* "" -> Definition {"PartialClass" "class" ID "{" ClassBodyDecl* "" -> Definition {"Class" Type ID ";" -> ClassBodyDecl {"Field" Type ID "(" ")" "{" Stmt* "" -> ClassBodyDecl {"Method"
19 Grammar Rules %% Types ID -> Type {"Type" "string" -> Type {"StringType", prefer "int" -> Type {"IntType", prefer "void" -> Type {"VoidType", prefer %% Statements "return" Expr ";" -> Stmt {"Return" %% Expressions ID -> Expr {"FieldRef" Expr "." ID -> Expr {"FieldAccess" Expr "." ID "(" ")" -> Expr {"MethodCall" ID "(" ")" -> Expr {"ThisMethodCall"
20 Abstract Syntax Trees
21 Syntactic Editor Services module CSharp-Outliner outliner Definition.Namespace Definition.PartialClass Definition.Class ClassBodyDecl.Method module CSharp-Folding folding CompUnit.CompUnit Definition._ ClassBodyDecl.Method
22 Error Recovery
23 Robust Editors editor services based on parse/abstract syntax tree
24
25
26 Permissive Grammars exports sorts WATER WATERTOKEN WATERTOKENSTART WATERTOKENSEPARATOR WATERTOKENSTAR lexical syntax ~[A-Za-z0-9\_] -> WATERTOKENSTART {recover, avoid WATERTOKENSTART [A-Za-z0-9\_]* -> WATERTOKEN ~[A-Za-z0-9\_\ \t\12\r\n\*] -> WATERTOKENSEPARATOR {recover, avoid "*" -> WATERTOKENSTAR {recover, avoid WATERTOKEN -> WATER WATERTOKENSEPARATOR -> WATER WATERTOKENSTAR -> WATER -> WATEREOF lexical restrictions WATERTOKEN -/- [A-Za-z0-9\_] WATERTOKENSTAR -/- [\/] context-free syntax WATER -> LAYOUT {cons("water") Island Grammars [OOPSLA 09]
27 Permissive Grammars lexical syntax %% Lexical insertion recovery rules "\"" -> OQUOTE {recover OQUOTE StringChar* "\n" -> STRING {cons("insertend") OQUOTE StringChar* WATEREOF -> STRING {cons("insertend") "/*" -> ISTART {recover ISTART ( ~[\*] CommentChar )* WATEREOF -> LAYOUT {cons("insertend") -> "" {recover, cons("insertion") -> "using" {recover, cons("insertion") -> ";" {recover, cons("insertion") -> "return" {recover, cons("insertion")
28 Name Resolution
29 Reference Resolution using Web; namespace Web { partial class URL { string GetLocation() { return location; namespace Blogger { class User { string name; URL homepage; class BlogPosting { User poster; string body; URL Homepage() { return poster.homepage; string Location() { return Homepage().GetLocation(); namespace Web { partial class URL { string location;
30 Reference Resolution using Web; namespace Web { partial class URL { string GetLocation() { return location; namespace Blogger { class User { string name; URL homepage; class BlogPosting { User poster; string body; URL Homepage() { return poster.homepage; string Location() { return Homepage().GetLocation(); namespace Web { partial class URL { string location;
31 Testing Name Resolution test Resolve class reference [[ namespace TestsResolving { class [[B]] { [[B]] b; ]] resolve #2 to #1
32 Name Resolution: Classes & Types "class" "{" ClassBodyDecl* "" -> Definition {"Class" -> Type {"Type" test Resolve class reference [[ namespace TestsResolving { class [[B]] { [[B]] b; ]] resolve #2 to #1
33 Name Resolution: Namespace "namespace" "{" Definition* "" -> Definition {"Namespace" "using" ";" -> Using {"Using" UsingPart "." -> UsingPart {"UsingPart" -> UsingPart {"UsingPart"
34 test Resolve field [[ namespace TestsResolving { class B { B [[x]]; B f() { return [[x]]; ]] resolve #2 to #1 Resolving Field References
35 Name Resolution: Fields & Methods %% Declarations Type ";" -> ClassBodyDecl {"Field" Type "(" ")" "{" Stmt* "" -> ClassBodyDecl {"Method" %% Uses "return" Expr ";" -> Stmt {"Return" -> Expr {"FieldRef" Expr "." -> Expr {"FieldAccess" Expr "." "(" ")" -> Expr {"MethodCall" "(" ")" -> Expr {"ThisMethodCall"
36 Scope of Declarations "namespace" "{" Definition* "" -> Definition {"Namespace", scope(type, PartialType, Namespace) "class" "{" ClassBodyDecl* "" -> Definition {"Class", scope(field, Method)
37 "partial" "class" "{" ClassBodyDecl* "" -> Definition {"PartialClass", scope(field,method)
38 Type Analysis
39 Resolving Field Access test Resolve property access [[ namespace TestsResolving { class B { C v; C f() { return v.[[c]]; class C { C [[c]]; ]] resolve #1 to #2 interaction between type analysis and name resolution
40 Type Projection type-of: Field(x, _) -> <type-of> x type-of: PartialClass(x, _) -> TYPE(x) type-of: Class(x, _) -> TYPE(x) type-of: Method(x, _, _) -> <type-of> x type-of: Type(x) -> TYPE(x) type-of: Return(e) -> <type-of> e type-of: FieldRef(f) -> <type-of> <index-lookup> f type-of: FieldAccess(e, f) -> <type-of> <index-lookup> f type-of: MethodCall(e, m) -> <type-of> <index-lookup> m type-of: ThisMethodCall(m) -> <type-of> <index-lookup> m type-of: Def(uri) -> <index-get-value> Type(uri, ()) Stratego Rewrite Rules
41 Types of Definitions adjust-index-def-data(store-results namespace, path): def -> <store-results> Type([namespace path], type) where type := <type-of> def // Return a list of fields in the class on the left hand side. adjust-index-lookup(target namespace, path, prefix): FieldAccess(e, <target>) -> f* with if TYPE(e-type{_) := <type-of> e then f* := <index-lookup-children( Field(), prefix)> e-type else f* := StopLookup() end Adapt Generic Resolution Algorithm
42 Type Constraints
43 Reporting Errors
44 Testing Error Constraints test Resolve function call fails [[ namespace Tests { class B { P p; string f() { return p.geta(); ]] 1 error
45 Constraint Error Rules constraint-error: rhs) -> (e, $[Expected [<print-type> type1] but found [<print-type> type2].]) where type1 := <type-of> lhs; type2 := <type-of> rhs; not(<is-assignable-to> (type1, type2))
46 Unresolved References constraint-error: x{[unresolved(t) _] -> (x, $[Unable to resolve.])
47 Duplicate Definitions constraint-error: def -> (def, $[Duplicate definition]) where key{[ns _] := <nam-get-definition-key> def; <is-unique-namespace> ns; defs := <index-lookup-all> key; <gt> (<length> defs, 1) is-unique-namespace =?Type() is-unique-namespace =?Field() is-unique-namespace =?Method()
48 Code Generation
49 Code Generation to-java: Property(name, type) -> $[private [typename] [name]; public [typename] get_[name] { return [name]; public void set_[name]([typename] [name]) { this.[name] = [name]; ] where typename := <to-java> type
50 More Declarative Language Definition
51 Verifying Language Designs
52 Web IDE
53 Cloud9IDE
54
55
56 spoofax.org
57 Declarative Syntax Definition lexical syntax [a-za-z\_\$][a-za-z0-9\_]* -> ID context-free syntax STRING -> LimitedSetExp {cons("string") NUMBER -> LimitedSetExp {cons("num") LimitedSetExp -> Exp QId -> LimitedExp {cons("var") "(" Exp ")" -> LimitedExp {cons("brackets") Exp BoolMethodId Exp -> Exp {cons("binmethodcall"), left Exp CompareMethodId Exp -> Exp {cons("binmethodcall"), left Exp TermOperatorMethodId Exp -> Exp {cons("binmethodcall"), left Exp OperatorMethodId Exp -> Exp {cons("binmethodcall"), left character-level grammars: integration of lexical and context-free syntax
58 An Interactive Language Workbench develop and use language in same environment
59 Debugging Ambiguities
60 Declarative Disambiguation context-free priorities Exp "." ID -> LimitedExp > Exp "." ID "(" {NamedExp ","* ")" -> LimitedExp > Exp TermOperatorMethodId Exp -> Exp > Exp OperatorMethodId Exp -> Exp > Exp CompareMethodId Exp -> Exp > Exp BoolMethodId Exp -> Exp > "!" Exp -> Exp > Exp "?" Exp ":" Exp -> Exp > LimitedExp Filter+ -> Exp
61 Parsing after Disambiguation
62 Natural and Flexible Error Recovery* permissive grammar + backtracking + region discovery [*OOPSLA & SLE 2009]
63 Syntactic Normalization and Desugaring rules normalize : FunctionNoReturnType(manno*, name, farg*, stat*) -> Function(manno*, name, farg*, SimpleType(QId("mobl", "void")), stat*) normalize : IfNoElse(e, block) -> If(e, block, Block([])) desugar : ForInferred(lvalue, e, elem*) -> For(lvalue, t, e, elem*) where GenericType(_, [t]) := <type-of> e
64 CPS Transform cps-lift-exprs : [Return(e) stats] -> <concat>[stats2, [Return(e2) <cps-lift-expressions> stats]] where not(<is-sync> e) with { Exp : stats2 := <cps-lift-expression> e ; e2 := <Exp>
65 Type Analysis eq-type-of : String(_) -> SimpleType(QId("mobl", "String")) eq-type-of : FieldAccess(e, x) -> t where Property(_, _, t, _) := <lookup-property> (<type-of> e, x)
66 Type Checking constraint-error : t@simpletype(_) -> (t, $[Type is not defined: [<pp-mobl-type> t]]) where not(<lookup-type> t) constraint-error : t@fieldaccess(e, x) -> (t, $[Property [x] not defined]) where <type-of> e where not(type-of) origin tracking
67 Semantic Editor Services editor-analyze: (ast, path, project-path) -> (ast2, errors, warnings, notes) with //... editor-complete-proposal : SimpleType(COMPLETION(_)) -> proposals where all-types := <get-all-types>; proposals := <map(type-name-to-proposal); flatten-list> all-types editor-hover: (t@simpletype(_), position, ast, path, project-path) -> <get-doc> <lookup-type> t2 where t2 := <lookup-node> (position, ast) editor-resolve: (t@simpletype(qid), position, ast, path, project-path) -> target where target := <ensure-origin(lookup-type qid)> t
68 Editor Services Bindings module MoBL-Builders imports MoBL-Builders.generated builders provider : include/mobl.jar observer : editor-analyze on save : generate-artifacts builder : "Show ATerm" = generate-aterm (openeditor) (realtime) (meta) builder : "Format code" = format-code (openeditor) (realtime) builder : "Desugar" = editor-desugar (openeditor) (realtime) (meta) Connect transformations to IDE
69 behind the scenes
70 synchronous programming var results = Task.all().list(); for(var i = 0; i < results.length; i++) { alert(results[i].name);
71 render page query database and process results time...
72 render page browser freeze query database and process results time...
73 render page send query... time process query result...
74 asynchronous programming Task.all.list(function(results) { for(var i = 0; i < results.length; i++) { alert(results[i].name); );...
75 Task.all().list(function(results) { alert("hello, "); ); alert("world!"); breaks sequential execution assumption
76 Task.all().list(function(results) { // make changes... persistence.flush(function() { alert("changes saved!"); ); );
77 continuation-passing style transformation
78 function displaylocationandreturn() : Coordinates { var position = mobl::location::getposition(); log("lat: " + position.latitude); log("long: " + position.longitude); return position; function displaylocationandreturn(callback) { mobl.location.getposition(function(position) { console.log("lat: " + position.latitude); console.log("long: " + position.longitude); callback(position); ); ;
79 function displaylocationandreturn() : Coordinates { var position = mobl::location::getposition(); log("lat: " + position.latitude); log("long: " + position.longitude); return position; function displaylocationandreturn(callback) { mobl.location.getposition(function(position) { console.log("lat: " + position.latitude); console.log("long: " + position.longitude); callback(position); ); ;
80 function displaylocationandreturn() : Coordinates { var position = mobl::location::getposition(); log("lat: " + position.latitude); log("long: " + position.longitude); return position; function displaylocationandreturn(callback) { mobl.location.getposition(function(position) { console.log("lat: " + position.latitude); console.log("long: " + position.longitude); callback(position); ); ;
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 informationCPS 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 informationSERG. Natural and Flexible Error Recovery for Generated Modular Language Environments
Delft University of Technology Software Engineering Research Group Technical Report Series Natural and Flexible Error Recovery for Generated Modular Language Environments Maartje de Jonge, Lennart C.L.
More informationWhat is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done
What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g., C++) to low-level assembly language that can be executed by hardware int a,
More informationDeclaratively Defining Domain-Specific Language Debuggers
Declaratively Defining Domain-Specific Language Debuggers Version of July 19, 2013 Ricky T. Lindeman Declaratively Defining Domain-Specific Language Debuggers THESIS submitted in partial fulfillment of
More informationJavaCC Parser. The Compilation Task. Automated? JavaCC Parser
JavaCC Parser The Compilation Task Input character stream Lexer stream Parser Abstract Syntax Tree Analyser Annotated AST Code Generator Code CC&P 2003 1 CC&P 2003 2 Automated? JavaCC Parser The initial
More informationSERG. Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT
Delft University of Technology Software Engineering Research Group Technical Report Series Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT Karl Trygve
More informationSERG. The Spoofax Language Workbench Rules for Declarative Specification of Languages and IDEs
Delft University of Technology Software Engineering Research Group Technical Report Series The Spoofax Language Workbench Rules for Declarative Specification of Languages and IDEs Lennart C. L. Kats, Eelco
More informationEDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:
EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)
More informationConcrete Syntax for Objects
Realizing Domain-Specific Language Embedding and Assimilation without Restrictions Martin Bravenboer Eelco Visser Institute of Information & Computing Sciences Utrecht University, The Netherlands June
More informationWhat Every Xtext User Wished to Know Industry Experience of Implementing 80+ DSLs
What Every Xtext User Wished to Know Industry Experience of Implementing 80+ DSLs EclipseCon Europe 2016 2016-10-26 Roman Mitin Avaloq Evolution AG Allmendstrasse 140 8027 Zurich Switzerland T +41 58 316
More informationIncremental parsing C++ pre-processing
Incremental parsing C++ pre-processing Olivier Gournet LRDE seminar, June 16, 2004 http://www.lrde.epita.fr/ Copying this document Copying this document Copyright c 2004
More informationChapter 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 informationSpoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT
Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT Karl Trygve Kalleberg 1 Department of Informatics, University of Bergen, P.O. Box 7800, N-5020 BERGEN,
More informationA 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 informationRenaud 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 information9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation
Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to
More informationSERG. Integrated Language Definition Testing: Enabling Test-Driven Language Development
Delft University of Technology Software Engineering Research Group Technical Report Series Integrated Language Definition Testing: Enabling Test-Driven Language Development Lennart C. L. Kats, Rob Vermaas,
More informationEDAN65: 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 informationarxiv: 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 informationSyntax. 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 informationSyntax-Directed Translation. Lecture 14
Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik) 9/27/2006 Prof. Hilfinger, Lecture 14 1 Motivation: parser as a translator syntax-directed translation stream of tokens parser ASTs,
More informationAn Evaluation of Domain-Specific Language Technologies for Code Generation
An Evaluation of Domain-Specific Language Technologies for Code Generation Christian Schmitt, Sebastian Kuckuk, Harald Köstler, Frank Hannig, Jürgen Teich Hardware/Software Co-Design, System Simulation,
More informationTopic 3: Syntax Analysis I
Topic 3: Syntax Analysis I Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Back-End Front-End The Front End Source Program Lexical Analysis Syntax Analysis Semantic Analysis
More informationInteractive Disambiguation of Meta Programs with Concrete Object Syntax
Interactive Disambiguation of Meta Programs with Concrete Object Syntax Lennart Kats Karl T. Kalleberg Eelco Visser (TUDelft) (KolibriFX) (TUDelft) Meta-programming Meta-programming with Template Engines
More informationRYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS
RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name
More informationChapter 4: Syntax Analyzer
Chapter 4: Syntax Analyzer Chapter 4: Syntax Analysis 1 The role of the Parser The parser obtains a string of tokens from the lexical analyzer, and verifies that the string can be generated by the grammar
More informationSyntax 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 informationCSE 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 informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationLecture 8 CS 412/413 Spring '00 -- Andrew Myers 2. Lecture 8 CS 412/413 Spring '00 -- Andrew Myers 4
CS412/413 Introduction to Compilers and Translators Spring 00 Outline Typechecking Symbol tables Using symbol tables for analysis Lecture 8: Semantic Analysis and Symbol Tables Lecture 8 CS 412/413 Spring
More informationCompiling and Interpreting Programming. Overview of Compilers and Interpreters
Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Overview of Compilers and Interpreters Common compiler and interpreter configurations Virtual machines Integrated programming environments
More informationGrammar Composition & Extension
Grammar Composition & Extension vadim@grammarware.net Symposium on Language Composition and Modularity Vadim Zaytsev, SWAT, CWI 2012 Introduction to grammarware What is a grammar? Structural description
More informationSyntax Errors; Static Semantics
Dealing with Syntax Errors Syntax Errors; Static Semantics Lecture 14 (from notes by R. Bodik) One purpose of the parser is to filter out errors that show up in parsing Later stages should not have to
More informationContext-free grammars (CFG s)
Syntax Analysis/Parsing Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax tree (AST) AST: captures hierarchical structure of
More information1 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 informationCS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)
CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going
More informationCS 403: Scanning and Parsing
CS 403: Scanning and Parsing Stefan D. Bruda Fall 2017 THE COMPILATION PROCESS Character stream Scanner (lexical analysis) Token stream Parser (syntax analysis) Parse tree Semantic analysis Abstract syntax
More informationParsing II Top-down parsing. Comp 412
COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled
More informationDEMO 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 informationWhat is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573
What is a compiler? Xiaokang Qiu Purdue University ECE 573 August 21, 2017 What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g.,
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More information4. 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 informationCSCI 1260: Compilers and Program Analysis Steven Reiss Fall Lecture 4: Syntax Analysis I
CSCI 1260: Compilers and Program Analysis Steven Reiss Fall 2015 Lecture 4: Syntax Analysis I I. Syntax Analysis A. Breaking the program into logical units 1. Input: token stream 2. Output: representation
More informationBuilding Compilers with Phoenix
Building Compilers with Phoenix Parser Generators: ANTLR History of ANTLR ANother Tool for Language Recognition Terence Parr's dissertation: Obtaining Practical Variants of LL(k) and LR(k) for k > 1 PCCTS:
More informationSyntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax
Susan Eggers 1 CSE 401 Syntax Analysis/Parsing Context-free grammars (CFG s) Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax
More informationSyntactic Analysis. Syntactic analysis, or parsing, is the second phase of compilation: The token file is converted to an abstract syntax tree.
Syntactic Analysis Syntactic analysis, or parsing, is the second phase of compilation: The token file is converted to an abstract syntax tree. Compiler Passes Analysis of input program (front-end) character
More informationA Domain-Specific Language for Cross- Platform Smartphone Application Development
Master s Thesis A Domain-Specific Language for Cross- Platform Smartphone Application Development Kristoffer Rosén Department of Computer Science Faculty of Engineering LTH Lund University, 2013 ISSN 1650-2884
More informationTHE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES
THE COMPILATION PROCESS Character stream CS 403: Scanning and Parsing Stefan D. Bruda Fall 207 Token stream Parse tree Abstract syntax tree Modified intermediate form Target language Modified target language
More informationSyntax-Directed Translation
Syntax-Directed Translation ALSU Textbook Chapter 5.1 5.4, 4.8, 4.9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is syntax-directed translation? Definition: The compilation
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University January 30, 2007 Outline Recap
More informationCompiler construction
Compiler construction Martin Steffen March 13, 2017 Contents 1 Abstract 1 1.1 Symbol tables. 1 1.1.1 Introduction 1 1.1.2 Symbol table design and interface.. 2 1.1.3 Implementing symbol tables 3 1.1.4
More informationProf. 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 informationUPTR - 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 informationInformal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility
Informal Semantics of Data semantic specification names (identifiers) attributes binding declarations scope rules visibility 1 Ways to Specify Semantics Standards Documents (Language Definition) Language
More informationA 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 informationProgram Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )
Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 ) lizheng@mail.buct.edu.cn Lexical and Syntax Analysis Topic Covered Today Compilation Lexical Analysis Semantic Analysis Compilation Translating from high-level
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 20, 2007 Outline Recap
More informationSyntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing
Syntax/semantics Program program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing Meta-models 8/27/10 1 Program program execution Syntax Semantics
More informationStatic Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1
Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing
More informationEnhancing Xtext for General Purpose Languages
Enhancing Xtext for General Purpose Languages Adolfo Sánchez-Barbudo Herrera Department of Computer Science, University of York, UK. asbh500@york.ac.uk Abstract. Xtext is a popular language workbench conceived
More informationAnatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?
Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator
More informationContext-Free Grammars
CFG2: Ambiguity Context-Free Grammars CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Ambiguity - / - / ( ) - / / - 16-06-22 2 Ambiguity Grammar is ambiguous if more
More informationError Detection in LALR Parsers. LALR is More Powerful. { b + c = a; } Eof. Expr Expr + id Expr id we can first match an id:
Error Detection in LALR Parsers In bottom-up, LALR parsers syntax errors are discovered when a blank (error) entry is fetched from the parser action table. Let s again trace how the following illegal CSX-lite
More informationCOMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview
COMP 181 Compilers Lecture 2 Overview September 7, 2006 Administrative Book? Hopefully: Compilers by Aho, Lam, Sethi, Ullman Mailing list Handouts? Programming assignments For next time, write a hello,
More informationCompiler Design Concepts. Syntax Analysis
Compiler Design Concepts Syntax Analysis Introduction First task is to break up the text into meaningful words called tokens. newval=oldval+12 id = id + num Token Stream Lexical Analysis Source Code (High
More informationCompiler Passes. Syntactic Analysis. Context-free Grammars. Syntactic Analysis / Parsing. EBNF Syntax of initial MiniJava.
Syntactic Analysis Syntactic analysis, or parsing, is the second phase of compilation: The token file is converted to an abstract syntax tree. Compiler Passes Analysis of input program (front-end) character
More informationDomain-Specific Languages for Program Analysis
Domain-Specific Languages for Program Analysis Mark Hills OOPSLE 2015: Open and Original Problems in Software Language Engineering March 6, 2014 Montreal, Canada http://www.rascal-mpl.org 1 Overview A
More informationLexical 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 informationCrafting a Compiler with C (II) Compiler V. S. Interpreter
Crafting a Compiler with C (II) 資科系 林偉川 Compiler V S Interpreter Compilation - Translate high-level program to machine code Lexical Analyzer, Syntax Analyzer, Intermediate code generator(semantics Analyzer),
More informationBook. Signatures and grammars. Signatures and grammars. Syntaxes. The 4-layer architecture
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 13-9-2011 PAGE 1
More informationInfrastructure 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 informationSEMANTIC ANALYSIS TYPES AND DECLARATIONS
SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether
More informationEDA180: Compiler Construc6on. Top- down parsing. Görel Hedin Revised: a
EDA180: Compiler Construc6on Top- down parsing Görel Hedin Revised: 2013-01- 30a Compiler phases and program representa6ons source code Lexical analysis (scanning) Intermediate code genera6on tokens intermediate
More informationIntroduction to Parsing Ambiguity and Syntax Errors
Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors Compiler Design 1 (2011) 2 Languages
More informationProf. 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 informationCS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions
More informationCompilers. Lecture 2 Overview. (original slides by Sam
Compilers Lecture 2 Overview Yannis Smaragdakis, U. Athens Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Last time The compilation problem Source language High-level abstractions Easy
More informationThe role of semantic analysis in a compiler
Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More informationLexical 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 informationA clarification on terminology: Recognizer: accepts or rejects strings in a language. Parser: recognizes and generates parse trees (imminent topic)
A clarification on terminology: Recognizer: accepts or rejects strings in a language Parser: recognizes and generates parse trees (imminent topic) Assignment 3: building a recognizer for the Lake expression
More informationFormal Semantics. Chapter Twenty-Three Modern Programming Languages, 2nd ed. 1
Formal Semantics Chapter Twenty-Three Modern Programming Languages, 2nd ed. 1 Formal Semantics At the beginning of the book we saw formal definitions of syntax with BNF And how to make a BNF that generates
More informationType Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413
Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular
More informationSemantics driven disambiguation A comparison of different approaches
Semantics driven disambiguation A comparison of different approaches Clément Vasseur Technical Report n o 0416, 12 2004 revision 656 Context-free grammars allow the specification
More informationSemantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far
Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages
More informationLecture 4 Abstract syntax
Lecture 4 Abstract syntax Abstract syntax examples for various languages: A simple expression language OCaml MiniJava (a subset of Java) CS 421 Class 4, 1/26/12 1 Ex: Abstract syntax of simple expressions
More informationR13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.
R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is
More informationIntroduction to Parsing Ambiguity and Syntax Errors
Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors 2 Languages and Automata Formal
More informationProgram Representations
Program Representations 17-654/17-765 Analysis of Software Artifacts Jonathan Aldrich Representing Programs To analyze software automatically, we must be able to represent it precisely Some representations
More informationPart 3. Syntax analysis. Syntax analysis 96
Part 3 Syntax analysis Syntax analysis 96 Outline 1. Introduction 2. Context-free grammar 3. Top-down parsing 4. Bottom-up parsing 5. Conclusion and some practical considerations Syntax analysis 97 Structure
More informationSyntax Analysis Check syntax and construct abstract syntax tree
Syntax Analysis Check syntax and construct abstract syntax tree if == = ; b 0 a b Error reporting and recovery Model using context free grammars Recognize using Push down automata/table Driven Parsers
More informationAppendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.
A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators
More informationDerivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012
Derivations vs Parses Grammar is used to derive string or construct parser Context ree Grammars A derivation is a sequence of applications of rules Starting from the start symbol S......... (sentence)
More informationSyntax. In Text: Chapter 3
Syntax In Text: Chapter 3 1 Outline Syntax: Recognizer vs. generator BNF EBNF Chapter 3: Syntax and Semantics 2 Basic Definitions Syntax the form or structure of the expressions, statements, and program
More informationLECTURE 3. Compiler Phases
LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent
More informationDomain-Specific Languages Language Workbenches
Software Engineering with and Domain-Specific Languages Language Workbenches Peter Friese Itemis peter.friese@itemis.de Markus Voelter Independent/itemis voelter@acm.org 1 Programming Languages C# Erlang
More informationCOP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher
COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler
More informationApplying Model Driven Technologies in the Creation. of Domain Specific Modeling Languages
Applying Model Driven Technologies in the Creation Model Driven Development Language Editor Generator Abstraction Model Driven Development Refinement of Domain Specific Modeling Languages Bruce Trask Angel
More information