SYNTAX DIRECTED TRANSLATION

Slides:



Advertisements
Similar presentations
Compiler Designs and Constructions
Advertisements

SYNTAX DIRECTED TRANSLATION 11CS Types of Attributes There are two types of attributes for non- terminals :- Synthesized Attributes : For a non-terminal.
Chapter 5 Syntax-Directed Translation. Translation of languages guided by context-free grammars. Attach attributes to the grammar symbols. Values of the.
Chapter 5 Syntax Directed Translation. Outline Syntax Directed Definitions Evaluation Orders of SDD’s Applications of Syntax Directed Translation Syntax.
1 Beyond syntax analysis An identifier named x has been recognized. Is x a scalar, array or function? How big is x? If x is a function, how many and what.
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
Abstract Syntax Tree (AST)
Syntax Directed Translation
Syntax-Directed Translation Context-free grammar with synthesized and/or inherited attributes. The showing of values at nodes of a parse tree is called.
CH4.1 CSE244 Syntax Directed Translation Aggelos Kiayias Computer Science & Engineering Department The University of Connecticut 371 Fairfield Road, Unit.
Syntax-Directed Translation
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Chapter 5 Syntax-Directed Translation Section 0 Approaches to implement Syntax-Directed Translation 1、Basic idea Guided by context-free grammar (Translating.
Syntax Directed Definitions Synthesized Attributes
Topic #5: Translations EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
Syntax-Directed Translation
10/13/2015IT 3271 Tow kinds of predictive parsers: Bottom-Up: The syntax tree is built up from the leaves Example: LR(1) parser Top-Down The syntax tree.
COP4020 Programming Languages Semantics Prof. Xin Yuan.
CS 363 Comparative Programming Languages Semantics.
Overview of Previous Lesson(s) Over View  An ambiguous grammar which fails to be LR and thus is not in any of the classes of grammars i.e SLR, LALR.
TDDD55- Compilers and Interpreters Lesson 1 Zeinab Ganjei Department of Computer and Information Science Linköping University.
Chapter 5: Syntax directed translation –Use the grammar to direct the translation The grammar defines the syntax of the input language. Attributes are.
Scribe Sumbission Date: 28 th October, 2013 By M. Sudeep Kumar.
COP4020 Programming Languages Parsing Prof. Xin Yuan.
Lecture 6: YACC and Syntax Directed Translation CS 540 George Mason University.
Chapter 5. Syntax-Directed Translation. 2 Fig Syntax-directed definition of a simple desk calculator ProductionSemantic Rules L  E n print ( E.val.
Overview of Previous Lesson(s) Over View  In syntax-directed translation 1 st we construct a parse tree or a syntax tree then compute the values of.
1 Syntax-Directed Translation Part I Chapter 5 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007.
1 Nonrecursive Predictive Parsing  It is possible to build a nonrecursive predictive parser  This is done by maintaining an explicit stack.
Syntax Directed Definition and Syntax directed Translation
UNIT – 5 SYNTAX-DIRECTED TRANSLATION
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
Chap. 7, Syntax-Directed Compilation J. H. Wang Nov. 24, 2015.
Chapter 8: Semantic Analyzer1 Compiler Designs and Constructions Chapter 8: Semantic Analyzer Objectives: Syntax-Directed Translation Type Checking Dr.
SDTs used to implement SDDs A non-cyclic SDD (having definitions of attributes) can always be implemented by a SDT (having actions that assign values to.
Semantic Analysis Attribute Grammar. Semantic Analysis  Beyond context free grammar  Is x declared before it is used?  Is x declared but never used?
CSE 420 Lecture Program is lexically well-formed: ▫Identifiers have valid names. ▫Strings are properly terminated. ▫No stray characters. Program.
Chapter4 Syntax-Directed Translation Introduction : 1.In the lexical analysis step, each token has its attribute , e.g., the attribute of an id is a pointer.
Semantic analysis Jakub Yaghob
Semantics Analysis.
Syntax-Directed Translation
Programming Languages Translator
Bottom-up parsing Goal of parser : build a derivation
Unit-3 Bottom-Up-Parsing.
Compiler Construction
Chapter 5 Syntax Directed Translation
Syntax-Directed Translation Part I
CS 3304 Comparative Languages
Syntax-Directed Translation
Chapter 5. Syntax-Directed Translation
Syntax-Directed Translation Part I
Syntax-Directed Translation Part I
Syntax-Directed Definition
פרק 5 תרגום מונחה תחביר תורת הקומפילציה איתן אביאור.
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
COMPILER DESIGN 11CS30013 & 11CS30014 Group October 2013
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 4 Action Routines.
Syntax-Directed Translation Part I
SYNTAX DIRECTED DEFINITION
Nonrecursive Predictive Parsing
Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing
Directed Acyclic Graphs (DAG)
Predictive Parsing Program
Syntax-Directed Translation Part I
COP4020 Programming Languages
COP4020 Programming Languages
Chapter 5 Syntax Directed Translation
Presentation transcript:

SYNTAX DIRECTED TRANSLATION COMPILERS 29TH OCTOBER 2013

SDD Semantic Rule A  X1X2X3 A.x = f ( X1.a, X2.b, X3.c )

SDT A  X1X2{A.x = f( X1.a, X2.b) }X3 Embedded

When we perform reduction, we evaluate the attribute to get the result S – attributed SDD SDT A  X1X2X3 {a} When we perform reduction, we evaluate the attribute to get the result

We have the stack X1X2X3  symbols and states X1. a, X2. b, X3 We have the stack X1X2X3  symbols and states X1.a, X2.b, X3.c  values

After Reduction A  replaces X1X2X3 A After Reduction A  replaces X1X2X3 A.x  evaluated by the function f( X1.a, X2.b, X3.c )

L  E { Print (E. val) } E  E + T { E. val = E. val + T L  E { Print (E.val) } E  E + T { E.val = E.val + T.val } E  T {E.val = T.val} T  T * F { T.val = T.val * F.val } T  F { T.val = F.val } F  id { F.val = id }

Stack Symbol Stack Value Input String Syntax Action $ 3*4 $ 3 $3 *4 Semantic Action $ 3*4 $ 3 $3 *4 F  id F.val = id $ F T  F T.Val = F.val $ T Shift $ T * $ 3* 4 $ T*4 $ 3*4 $ T*F T  T * F T.Val = T.val * F.val $ 12

To evaluate T. val = T. val. F To evaluate T.val = T.val * F.val , we need the two values; which we get form the value stack.

L – attributed SDD is suitable for top-down parsing LL (1)  synthesized attributes  inherited attributes

A non-terminal can have multiple inherited attributes ; for each will have some defined action In case of synthesize attribute, we append it to the end of the rule For predictive parsers, for each non-terminal, we have a function

E. G : Recursive Descent Parser A  X1X2X3 A(). {. if ( a == X1 ) E.G : Recursive Descent Parser A  X1X2X3 A() { if ( a == X1 ) move to next symbol if ( X1 is a NT) X1() }

This function invokes the functions of the body of the production To implement predictive parsing, we need to implement those functions

Made By : Mohit Bhura 11CS30019