1. Given the Grammar
<expr> --> <expr> + <term> | <term>
<term> --> <term> * <factor> | <factor>
<factor> --> ( <expr> ) | number
For the given string 3 * ( 2 + 5 * 6), perform the following:
1. Left-most derivation
2. Draw a parse tree
3. Draw an abstract syntax tree
Note: number as a terminal has multiple values
1. Left-most derivation
<expr>
-> <term>
-> <term> * <factor>
-> <factor> * <factor>
-> number * <factor>
-> 3 * <factor>
-> 3 * ( <expr> )
-> 3 * (<expr> + <term>)
-> 3 * (<term> + <term>)
-> 3 * (<factor> + <term>)
-> 3 * (number + <term>)
-> 3 * (2 + <term>)
-> 3 * (2 + <term> * <factor>)
-> 3 * (2 + <factor> * <factor>)
-> 3 * (2 + number * <factor>)
-> 3 * (2 + 5 * <factor>)
-> 3 * (2 + 5 * number)
-> 3 * (2 + 5 * 6)
--------------------------------------
Hit the thumbs up if you are fine with the answer. Happy
Learning!
Get Answers For Free
Most questions answered within 1 hours.