Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you have a language where a valid program is a sequence of statements an

ID: 3721801 • Letter: S

Question

Suppose you have a language where a valid program is a sequence of statements and

nothing else. Every statement ends with semicolon. A statement is either input

READ(variable) or assignment variable=expression, where expression is C-like

expression involving () and +,-,*,/ all arithmetical binary operators except - which is

both unary and binary, and no other operators. Associativity is set so that all

operators are left to right except * which is right to left, Precedence is set so that ()

overrides anything, the rest, from the strongest to the weakest are:

unary minus

+ and -, the same

* and /, the same.

There are no numbers nor anything else. Variables are not defined.

Example program:

READ(x);

READ(y);

x=y+x/(x*y);

Design unambiguous CFG. Make sure to state what are the tokens.

Explanation / Answer

<STMT>-><EXPR> ;

<EXPR>-> READ(ID)/<ASSIGN>=<EXPR>

<EXPR>-><EXPR>+<TERM>/<TERM>/(EXPR>)

<EXPR>-><EXPR>-<TERM>/-(EXPR)

<TERM>-><FACTOR>*<TERM>/<FACTOR>

<FACTOR>-><FACTOR>/<DENOM>

<EXPR>->ID

THE TOKENS ARE ID ,+ ,*,/ - and READ

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote