


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



- Keywords, operators, identifiers How are they specified?
systematically converted into a parser?
Rules determine: “does this string belong to language?”
combined. Also detect syntactical errors: Examples:
Free Grammars (CFG). Our focus: BNF, EBNF and Syntax Diagrams
Synthesis
Analysis
Source Program
Target Program
Analyzer Lexical Syntax Analyzer Analyzer
Semantic
Generator IC Code Optimizer Generator
Code
Symbol Table
tokens syntax tree
Annotated Tree
Inter. Code
Inter. Code
First used in Algol60 report.
(ii) Rules written as
(a) a terminal, nonterminal, or concatenation of terminal and nonterminals, or
Example:
length 0).
BNF - cont’d.
list the rules for starting NT first.
- beginning with starting NT; - repeatedly replacing a NT by a right hand production for that NT until no more NTs remain. Note: Order of replacement does not matter
- Productions/rules:
- Do the following belong to the language? A, B2D, 2A, A*BL - What is the language?
graphically how a string is generated from rules
form:
input source program. Parse tree (or some representation of it) used as a basis for semantic analysis and code generation
structure
- a parse tree for expression 2 + (3 * 4); - Derivation and corresponding creation of parse tree
Parse tree - cont’d.
evaluation for 2 + 3 * 4 (Show parse tree)
are already specified by the way grammar is written.
left associativity of +
right associativity of +
grammar is ambiguous.
S if E 1 then S if E 2 then S 1
S if E 1 then S if E 2 then S 1 elseS 2
else S 2
if E 1 then if E 2 then S 1 else S 2
Which one to choose?
enclosed in quotes (‘’).
Rewrite the previous grammar:
Rewrite as:
Rewrite as
Stmt
Id
Num
Id :=^ Exp
Block
while (^) Exp do^ Block end
Assgn
While
Block
Assgn
Program
Stmt
Exp
While