Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler.

Slides:



Advertisements
Similar presentations
AST Generation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 9.
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Cs7120 (Prasad)L21-DCG1 Definite Clause Grammars
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Semantic Analysis Chapter 4. Role of Semantic Analysis Following parsing, the next two phases of the "typical" compiler are – semantic analysis – (intermediate)
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL.
ICE1341 Programming Languages Spring 2005 Lecture #5 Lecture #5 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Domain Specific Embedded Languages Lecture 2, Designing and Using Combinators John Hughes.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap  Syntax and Semantics  Semantics of Expressions 
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Chapter 2 A Simple Compiler
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
ANTLR with ASTs. Abstract Syntax Trees ANTLR can be instructed to produce ASTs for the output of the parser ANTLR uses a prefix notation for representing.
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Syntax Directed Definitions Synthesized Attributes
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
CS 461 – Oct. 7 Applications of CFLs: Compiling Scanning vs. parsing Expression grammars –Associativity –Precedence Programming language (handout)
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Topic #2: Infix to Postfix EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
CS 363 Comparative Programming Languages Semantics.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
CPS 506 Comparative Programming Languages Syntax Specification.
Simple One-Pass Compiler
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Intermediate Code Representations
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
An Attribute Grammar for Tiny Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 18.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Chap. 7, Syntax-Directed Compilation J. H. Wang Nov. 24, 2015.
CSC 4181 Compiler Construction
Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Part 1 : Transformation.
Lecture 9 Symbol Table and Attributed Grammars
Chapter 3 – Describing Syntax
COMPILER CONSTRUCTION
System Software Unit-1 (Language Processors) A TOY Compiler
A Simple Syntax-Directed Translator
Introduction to Parsing
An Attribute Grammar for Tiny
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Basic Program Analysis: AST
Syntax-Directed Definition
Mini Language Interpreter Programming Languages (CS 550)
CSE401 Introduction to Compiler Construction
Syntax-Directed Translation
Programming Languages 2nd edition Tucker and Noonan
Overview of the Course.
Presentation transcript:

Simple Language (SL) Start version 00

Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler written in AG

Atze Dijkstra, 2000IPT - SL3 SL examples let fac :: Int -> Int = \n -> if n > 0 then n * fac (n-1) else 1 fi in fac 6 ni let fac :: Int -> Int = \n -> let cnt :: Ref Int = new 2 ; res :: Ref Int = new 1 in while ( cnt <= n ) do res := res * cnt ; cnt := cnt + 1 od ; res ni in fac 6 ni

Atze Dijkstra, 2000IPT - SL4 SL features Expression evaluation Int, Bool, Array, Product, Data, Ref Assignment Let (blocks), Lambda (functions) If, While, Case Typechecking

Atze Dijkstra, 2000IPT - SL5 SL first version Integer constant Generating: listing + code 55 LDC 55 TRAP 0 HALT.sl.ssmstdout

Atze Dijkstra, 2000IPT - SL6 AG: SL parser Parser combinators + scanner pRoot = sem_Root_Root pExpr pExpr = (sem_Expr_Intexpr. string2int) pInteger string2int = foldl (\val dig -> (10*val + ord dig - ord '0')) 0 Semantic functions?

Atze Dijkstra, 2000IPT - SL7 AG: SL abstract syntax Abstract tree representation DATA Root | Root Expr DATA Expr | Intexpr Int Root Intexpr 55 Root Expr tree node tree node type tree node variant

Atze Dijkstra, 2000IPT - SL8 AG: SL aspects (attributes) Pretty printed output & stack code Root Intexpr 55 Root Expr pp copied synthesized attribute text.show $ int Described by ATTR Root [ || ppexpr: PP_Doc ] SEM Root | Root LHS. ppexpr = "expr_pp" SEM Expr [ || pp: PP_Doc ] | Intexpr LHS. pp = "text.show $ int"

Atze Dijkstra, 2000IPT - SL9 AG notation ATTR Root [ | | ppexpr: PP_Doc ] SEM Root | Root LHS. ppexpr = "expr_pp" SEM Expr [ | | pp: PP_Doc ] | Intexpr LHS. pp = "text.show $ int" Attribution (Hugs) text for definition, specific for: Node type, Node variant, Attribute, Direction Attribute name Attribute type (Hugs or Node) synthesized  inh+synth  inherited 

Atze Dijkstra, 2000IPT - SL10 AG compilation Generates Haskell – Generate SL.hs from SL.ag compile "SL" allc Datastructures, semantics,... data Expr = Expr_Intexpr Int deriving Show -- semantic domains type T_Expr = (SCode,PP_Doc) -- catas sem_Expr (Expr_Intexpr int) = sem_Expr_Intexpr int -- funcs sem_Expr_Intexpr ::Int -> T_Expr sem_Expr_Intexpr int = ( ((S_LDC int:)), (text.show $ int) )

Atze Dijkstra, 2000IPT - SL11 Scanner Transforms character sequences to tokens data TokenType = TkSymbol | TkVarid | TkConid | TkKeyword | TkOp | TkString | TkCharb| TkInteger8 | TkInteger10 | TkInteger16 | TkTextnm | TkTextln | TkError deriving (Eq, Ord) type Linenumber = Int type Filename = String newtype Token = Tok (TokenType, String, String, Linenumber, Filename)

Atze Dijkstra, 2000IPT - SL12 Code Generation For a Simple Stack Machine SEM Root [ || ppscode: PP_Doc ] | Root LHS. ppscode = "( vlist. map (text.textOfS)" ". expr_scode" ". (S_TRAP 0:)" ". (S_HALT:)" "$ []" ")" SEM Expr [ || scode: SCode ] | Intexpr LHS. scode = "(S_LDC int:)" DATA S | HALT | TRAP Int | LDC Int

Atze Dijkstra, 2000IPT - SL13 Simple Stack Machine Memory (Code, Stack) + Registers + Stack manipulating instructions