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

Consider the following grammar with terminals: {x, y, z, +.-, *, /} non-terminal

ID: 3783874 • Letter: C

Question

Consider the following grammar with terminals: {x, y, z, +.-, *, /} non-terminals: {E, T, F, V} start symbol: E production rules: (a) What are the associativities of "+" and "-" operators? Explain your answer. (b) If a grammatically correct (according to the above grammar) expression has more "+" operations than "-" operations, then as per the above grammar, can we infer that the semantics of the "+" operations will be evaluated before that of "-" operations? Explain your answer. (c) Is x + y/z * x + y - x grammatically correct as per the above grammar? Explain your answer.

Explanation / Answer

a) in case of operator precedence

associativity of + - is from right to left

a-b-c so first a-b will get evaluated then the rest the expression will get evaluated as ((a-b)-c)

power has the max priority

mul, divide has the same priority but less than power

+, - also has the same priority but less than power and / and *

b) no in this priority is from the starting to downwards

eg : 4+(5*3) = 19 cause acc to c language compiler * has higher priority then + so depends on the compiler

+ has more priority than -

associativity of + - * / is from right to left while for power it is left to right

means a+b+c acc to rule (a+b) will get calculated and then total of a+b result with c .

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