Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Part 1 : Transformation.

Slides:



Advertisements
Similar presentations
Compilers Course 379K, TTH 9:30-11:00 Instructor: Dr. Doron A. Peled Office Hours: Mon 11:00-12:00.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
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
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
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.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Compilers and Syntax.
Lecture 2 Phases of Compiler. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source.
CSE 6341 (755) Programming Languages
CS784 (Prasad)L167AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Syntax Directed Definitions Synthesized Attributes
CS 2104 Prog. Lang. Concepts Dr. Abhik Roychoudhury School of Computing Introduction.
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Part 1 : Programming.
Compiler Construction1 COMP Compiler Construction Lecturer: Dr. Arthur Cater Teaching Assistant:
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Lexical and Syntax Analysis
CS 363 Comparative Programming Languages Semantics.
March 5, ICE 1341 – Programming Languages (Lecture #4) In-Young Ko Programming Languages (ICE 1341) Lecture #4 Programming Languages (ICE 1341)
Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia XL Programming.
May 31, May 31, 2016May 31, 2016May 31, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
Bernd Fischer RW713: Compiler and Software Language Engineering.
Workshop: Towards Highly Portable Software Jakarta, 20 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Using Pretty Printing.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. Ambiguity in Grammars A grammar is ambiguous if and only if it generates a sentential form that has.
YACC. Introduction What is YACC ? a tool for automatically generating a parser given a grammar written in a yacc specification (.y file) YACC (Yet Another.
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Syntax-Directed Definitions and Attribute Evaluation Compiler Design Lecture (02/18/98) Computer Science Rensselaer Polytechnic.
Syntax and Semantics Form and Meaning of Programming Languages Copyright © by Curt Hill.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Part 1 : Programming.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
Chap. 7, Syntax-Directed Compilation J. H. Wang Nov. 24, 2015.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Chapter 3 – Describing Syntax
Introduction to Parsing
Introduction to Parsing (adapted from CS 164 at Berkeley)
Compiler Construction
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
CS 3304 Comparative Languages
Syntax Questions 6. Define a left recursive grammar rule.
Syntax-Directed Translation
Teori Bahasa dan Automata Lecture 9: Contex-Free Grammars
Chapter 3 Describing Syntax and Semantics.
Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CH 4 - Language semantics
Presentation transcript:

Workshop: Towards Highly Portable Software Jakarta, 21 – 23 January 2003 Diselenggarakan oleh Universitas IndonesiaUniversitas Indonesia Part 1 : Transformation Technique Dr. Ir. I.S.W.B. A. Azurat Lecture 1: Attribute Grammar

2 Plan Introduction AG Approach AG Tool Examples Conclusion

3 Transformation sentence transformation result "abba" P A P A P B B a a b b parse tree parser semantic function

4 Example data Form = Form `AND` Form | Form `IMP` Form | Var String | Const Bool Example: (Var "a" `AND` Var "b") `IMP` Var "a"

5 Example simp (Var a)= Var a simp (Const c)= Const c simp (p `AND` q)= case (simp p, simp q) of... (Const True, q') -> q' (p', Const True)-> p' otherwise -> Nothing For every semantic function, you have to code the recursion by hand.

6 Composite Semantic Function repmin t = replace (minT t) t In composition: sequencing computations can be subtle Upgrading a computation: may introduce various intermediate administrative data stucture whose relation can be quite subtle a computation on tree

7 Attribute Grammar Approach It is a formalism to abstractly describe semantic functions AG tool AG description sem. function repmin simplifier type checker compiler test generator... in the same class as compiler compiler (YACC) compiler generator example AG tool: LRC, AG

8 Attributes countVar (Const _) x= 0 countVar (Var y) x= if x==y then 1 else 0 countVar (And p q) x= countVar p x + countVar q x And Var y And x synthesized attribute inherited attribute

9 Defining countVar in AG DATA Form | Const Bool | Var String | And p,q: Form

10 Defining countVar in AG ATTR Form [ x : String | | result : Int ] SEM Form | Const lhs.result= 0 | Var lhs.result = then 1 else 0

11 Defining countVar in AG SEM Form... | And lhs.result

12 Generating the Sem Function Write AG source in file-name.ag –file-name must begin with CAPITAL letter c:/app/hugs/runhugs -98 –mdcfs file-name –Will generate file-name.hs Set the buffered number of lines in your DOS-window to

13 Result data Form = And (Form) (Form) | Const (Bool) | Var (String) sem_Form ((And (_p) (_q))) = sem_Form_Const (_bool) (_lhs_x) = 0 sem_Form (And (Var "x") (Var "y") ) "x" = 1

14 Hurdles SEM... | Var lhs.result = then 1 else 0 cryptic notation ?... sem_Form ((And (_p) (_q))) = currently... each AG description only generate 1 sem-function per data structure.

15 substitution list Example: Renaming rename [ x  a, y  b ] x /\ y /\ z = a /\ b /\ z

16 Writing Rename with AG { type SubsList = [ ( String, String ) ] subst :: String -> SubsList -> String subst x s = case find (\(y,z)-> y==x) s of Just (_,z) ->z otherwise -> x } ATTR Form [ subs : SubsList | | result : Form ] imports { import List }

17 Writing Rename with AG SEM Form | Const lhs.result= | And | Var lhs.result = can be omitted  copy rule

18 Example: Normalizing Names normalizeNames x /\ c /\ z = a /\ b /\ c

19 Strategy normalizeNames x /\ c /\ z = a /\ b /\ c PASS 1: compute subs-list first... [ (x, a), (c, b), (z, c) ] PASS 2 : rename

20 Writing Pass 1 with AG { alreadyIn :: String -> SubsList -> Bool x `alreadyIn` s = find (\(y,k)-> y==x) s /= Nothing } ATTR Form [ | cntVar : Int nsubs : SubsList | ] for generating new (normalized) name

21 can be omitted  copy rule Pass 1 SEM Form | Const lhs.nsubs= Const b cntVar, nsubs

22 Pass 1 SEM Form... | Var loc.seen ++ [chr(ord 'a' + 1 lhs.nsubs

23 Can be omitted  copy rule ! Pass 1 SEM Form... |

24 Pass or Aspect ? Rather than sequencing passes, we will combine aspects ! Each SEM computation may consist of several aspects, rather than passes DATA Root | Root f : Form ATTR Root [ | | result : Form ]

25 no imperative sequencing of passes! copy rule! Combining Aspects SEM Root | Root f.cntVar=0.nsubs=[

26 Resulting AG Code... SEM Form | Const lhs.result= | Var lhs.result = | And SEM Form | Var loc.seen ++ [chr(ord 'a' + 1 @seen SEM Root | Root

27 Conclusion Abstract –recursion is generated –copying and chaining information is generated –sequencing passes is automatic Highly compositional –computation can be split in aspects Highly extensible –extending a computation is just adding a new aspect