Question
Let G =(V, , R,STMT) be the following grammar. STMTASSIGN|IF-THEN|IF-THEN-ELSE IF-THENif condition then STMT IF-THEN-ELSEif condition then STMT else STMT ASSIGNa:=1 ={if,condition,then,else,a:=1} V = {STMT,IF-THEN,IF-THEN-ELSE,ASSIGN}
Let G =(V, , R,STMT) be the following grammar.
STMTASSIGN|IF-THEN|IF-THEN-ELSE
IF-THENif condition then STMT
IF-THEN-ELSEif condition then STMT else STMT
ASSIGNa:=1 ={if,condition,then,else,a:=1} V = {STMT,IF-THEN,IF-THEN-ELSE,ASSIGN} G is a natural-looking grammar for a fragment of a programming language, but G is ambiguous.
Give a new unambiguous grammar for the same language.
Give the pseudo codes of a deterministic finite memory stack program in C-style that parses an if-then/else statement such that an else clause is matched with the closest unmatched if clause.,
your program should be designed as a parser, but for the purpose of the homework, it is not required to build the parse tree or print the parse tree, but just have to report "Yes" or "No".
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