Syntax
Part 2
Andreas Stefik
This Lesson is our second related to "Processing" programming languages
We need to account for Operator Precedence with our Grammars
Consider the following Unambiguous Grammar for Expressions
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <term>
| <term>
<term> → <term> * <factor>
| <factor>
<factor> → ( <expr>)
| <id>
Group Project 1:Develop a derivation and a Parse tree for the string
A = B + C * A
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <term>
| <term>
<term> → <term> * <factor>
| <factor>
<factor> → ( <expr>)
| <id>
Let's discuss this Parse Tree
How do we Handle Associativity?
Group Project 2: Create a Parse Tree with the following input
A ** B
<factor> → <expr> ** <factor>
| <expr>
<expr> → ( <factor> )
| <id>
<id> → A | B | C
There are Extensions to BNF Grammars
<if_stmt> →if (<expression>) <statement> [else <statement>]
<ident_list> →<identifier> {, <identifier> }
<term> → <term> (* | / | % ) <factor>
Group Project 3: Create an EBNF Grammar for +, -, *, /, and ^ (exponentiation). Then derive a parse tree.
a + (b * c) ^ 5 - 4
Summary