Question
6.1 Please complete the following sentence level BNF grammar definition for expressions like: int myresult = 5 + 1 2 or int VarA = 2.5
6.1 Please complete the following sentence level BNF grammar definition for expressions like:
int myresult = 5 + 1 2 or int VarA = 2.5 + 1.11 + 1 - 3
For simplicity, we assume some of the token level BNF grammar rules are already defined (identifier and literals are defined and can be directly used). For example, in derivation and tree building, you could directly replace literal with 66 in one step. Also, we do not consider other variable definition expression formats, nor do we consider math operators other than + and -.
Sentence level BNF grammar only here. Please fill in the 4 blanks to make the grammar complete.
int_def_exp -> keyword identifier ___ ___
keyword -> int
equal_op -> =
math_exp -> literal + math_exp | ___ | ___
6.2 Please use the defined BNF grammar and write down the left-most derivation for expression:
int myres = 5.5 + 1 2.1
Left-most derivation:
___
6.3 Please draw the parser tree from your derivation for expression int myres = 5.5 + 1 2.1
Your parser tree here:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started