Reference no: EM132272003
Statement → (IF_statement | IFELSE_statement)
IF_statement → if (Condition) {Exp}
IFELSE_statement → if (Condition) {Exp} else { Exp }
Condition → ID Sign Term
Exp→ (Term + Term) | (Term-Term) Term→[0-9]+
ID→ ([A-Z] | [a-z])+
Sign→ > | < | ==
This is a grammar for IF statement
Your task in homework 02 is:
• Fixing the problems in the previous grammar
• Building a parser based on the previous grammar
Task 1:
Show the problems in the previous grammar and then Fix them
Task 2:
Implement a predictive parser using JavaCC
Hints:
• You must identify the tokens in the grammar before the implementation
• If and else are keywords
Take screenshots for:
• Lexical specification part (All tokens definition)
• Parser part
• Output of testing: :if (Ab>10) {1+2}
• Output of testing: :if (Ab<20) {1+2} else {1-2}
• Output of testing: :if (Ab<30) else {1-2}
Attachment:- Compiler Construction.rar