LESSON 07. Overview of Previous Lesson(s). Over View. Context Free Grammar is used to specify the syntax of the language. A grammar describes the hierarchical structure of most programming language constructs. It has components A set of tokens (terminal symbols) A set of nonterminals
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
LESSON 07
Overview
of
Previous Lesson(s)
type simple
 ^ id
 array [ simple ] of typesimple integer
 char
 num dotdot num
FIRST(simple) = { integer, char, num }FIRST(^ id) = { ^ }
FIRST(type) = { integer, char, num, ^, array }
i.eA  > A α  β
A  > β R
R  > α R  ɛ
TODAY’S LESSON
expr expr+termexpr exprtermexpr termterm 0term 1…term 9
{ print(“+”) }{ print(“”) }{ print(“0”) }{ print(“1”) }…{ print(“9”) }
expr term restrest +term { print(“+”) } rest  term { print(“”) } rest  term 0 { print(“0”) }term 1 { print(“1”) }…term 9 { print(“9”) }
Abstract Syntax tree for 95+2
A  > Aα  Aβ  γ
into
A  > γR
R  > αR  βR  ɛ
A = expr
α = + term {print(‘+’)}
β =  term {print(‘’)}
γ = term
expr expr+termexpr exprtermexpr termterm 0term 1…term 9
{ print(“+”) }{ print(“”) }{ print(“0”) }{ print(“1”) }…{ print(“9”) }
expr term rest
rest + term { print(“+”) } rest
  term { print(“”) } rest

term 0 { print(“0”) }term 1 { print(“1”) }…term 9 { print(“9”) }
Source
Program(Characterstream)
Lexical analyzer
Syntaxdirectedtranslator
Javabytecode
Tokenstream
Developparser and codegenerator for translator
Syntax definition(BNF grammar)
JVM specification
Ex. Input 16+28+50 It will be transformed into
(num, 31) (+) (num, 28) (+) (num, 59)
Ex. Input:count = count + increment;
Terminal Stream: id = id + id
(id, " count " ) (=) (id, " count " ) (+) (id, " increment " ) ( ; )
Thank You