Given grammar:
<program> --> <stmts>
<stmts> --> <stmt> | <stmt> ; <stmts>
<stmt> --> <var> = <expr>
<var> --> a | b | c | d
<expr> --> <term> + <term> | <term> - <term>
<term> --> <var> | const
Write down the parse tree and left most derivation of:
c = a + c
Solution:
The Parse tree would be as follows:

The Left most derivation can be written as:
<program> ==> <stmts>
==> <stmt>
==> <var> = <expr>
==> c = <expr>
==> c = <term> + <term>
==> c = <var> + <var>
==> c = a + <var>
==> c = a + c
Given grammar: <program> --> <stmts> <stmts> --> <stmt> | <stmt> ; <stmts> <stmt> --> <var> =...
Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const 1), write down derivation of: c-5+a 2) What are terminals and what are non-terminals in the grammar? Show a complete parse, including the parse stack contents, input string, and action for the string: id - id + id, using the grammar and parse table below. (10 points) 4. Grammar State id S4 4. T F 5. F (E) R2 S7 R4 R4 R2İR2 Parse...
Using the grammar below: <program> → begin <stmt_list> end <stmt_list> <stmt> | <stmt>; <stmt_list> <stmt> <var> = <expression> <var> → ABC <expression> <var> + <var> | <var> - <var> | <var> 1) show a leftmost derivation and draw a parse tree for each of the statements below: (1) begin A=A-B; B=C; C=A end (2) begin A=B+C; C=C+B end 2) try a rightmost derivation and draw a parse tree for each of the statements in Q1).
determine the terminal symbols and non-terminal symbols and the start symbols from the following grammar: <program> ==> <stmts> <stmts> ==> <stmt> | <stmt> ; <stmts> <var> ==> a | b | c | d <expr> ==> <term>+<term>|<term>-<trerm> <term> == > <var>|const
Given a CFG in BNF, (50 points) <stmt_list> → <stmt> | <stmt>; <stmt_list> <stmt> → <var> = <expr> <expr> → <var> + <expr> | <var> * <expr> | <var> <var> →a| b| c| d show a derivation for the given sentence a = b*c - d; b = d - a 2. show a parsing tree for a = b*c - d; b = d - a
This question concerns the following grammar. program -> { stmts } EOF stmts -> stmt stmts | ε stmt -> ID = exp ; | IF ( exp ) stmt exp -> ID tail tail -> + exp | - exp | ε Compute the FIRST and FOLLOW sets for the non-terminals of this grammar.
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...
1 Prog-DCs Strnts $ Terminal Regular Expression floatdcl intdcl I intdcl id print "p" id 6 Stmts- Stmt Simts 8 Strnt →id assign Val Expr 10 Expr → plus Val Expr assign " plus minus inum [0-91 fnum 0-9.0-91 blank ("" 2 I print id I minus Val Expr 12 13 Vai -id 14 15 I inum I fnum (Derivation and parse tree) Consider the above ac grammar, show the derivation and it parse tree of the following ac program
Consider the following grammar: (//some alternative rules are listed on separate lines without using symbol |): stmt −> assignment −> subr call assignment −> id := expr subr call −> id ( arg list ) expr −> primary expr tail expr tail −> op expr −> ε primary −> id −> subr call −> ( expr ) op −> + | - | * | / arg list −> expr args tail args tail −> , arg list −> ε...
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...
) Using the following grammar, show a parse tree and a leftmost derivation for the following sentence (make sure you do not omit parentheses in your derivation): Grammar <assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> + <term> | <term> <term> → <term> * <factor> | <factor> <factor> → (<expr>) | <id> Derive C = (A+B)*(C+A)*(C+B)