2a.
An operator is right associative if the variable on the LHS of the associated production is same as the variable to the right of the particular operator on the RHS of the production.
An operator is left associative if the variable on the LHS of the associated production is same as the variable to the left of the particular operator on the RHS of the production.
The production where the * operator appears on RHS is :
<term> :: = <factor> * <term>
In the given production, the variable on LHS is <term> and the same variable <term> is to the right of the * operator on RHS.
Thus, the * operator is right associative.
2b.
If an operator x is present in mth production in the set and another operator y is present in the nth production in the same set and if m < n, then the operator will have higher precedence than x.
In the given set of productions, the production which has the + operator is the 3rd production in the set and the production which has the * operator is the 4th production in the set.
Thus, the * operator has greater precedence than the + operator.
Considering the following BNF grammar, answer the questions. <prog> - <assign> | <expr> <assign> = <id>...
The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...
The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...
Q3. Convert the following recursive BNF grammar to EBNF: (20%) <assign>-> <id> = <expr> <expr> -> <d>+ <expr> | <id> * <expr> 1 (<expr>) | <i>
Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.
Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.
Question 3: Given the following grammar: assign → id := expr expr → expr + term \ term term -term *factor lfactor factor-(expr) id Using the above grammar, show a leftmost derivation (first five steps) for the following assignment statement: A ((A B)+ C) a. [3 marks] b. Using the above grammar, show a rightmost derivation (first five steps) for the following assignment statement: A:-A+B+C)+A [3 marks] Draw the abstract syntax tree for each of the above statements [4 marks]...
Solve the following questions. All questions are mandatory. Q1: What’s wrong in the following grammar? S → ABC A → aA|aa B → bB|B C → cC|cccc Q2: Describe the strings generated by the following grammar S → aSa S → bSb S → aa S → bb Q3: Consider the following grammar: S → ABC A → aA|a B → bB|b C → cC|c Change the above grammar such that it generates L1={anbmck; n>=3,m>=3,k>=4} Q4: Use the following grammar...
21. pts) Given the BNF Grammar ( 5) ID Show a single combined grammar (belo assume ID is just any arbitrary sequence mar (below) with all of the following additions/modifications. TO any arbitrary sequence of characters or digits, ands is the start and S is the "start" symbol. 1) Archi-cassociative binary-operator '@' of lower precedence ower precedence than the exiting + operator. - Add a ler-sociative binary-operator '#' such that its precedence lever existing '*' operator but lesser than the...
2. Consider the following grammar: <assign> à <id> = <expr> <id> à A | B | C <expr> à <id> + <expr> | <id> * <expr> | ( <expr> ) | <id> Show a parse tree and leftmost derivation for the following statements: (a) A = ( A + B ) * C (b) A = A * ( B + C ) 3. [10 Points] Show that the following grammar is...
Students Name and ID: Read the following story and then answer the questions. A scientist wants to find out why sea water freezes at a lower temperature than fresh water. The scientist goes to the library and reads a number of articles about the physical properties of solutions. The scientist also reads about the composition of sea water. The scientist travels to a nearby beach and observes the conditions there. The scientist notes the taste of sea water and other...