Question: can anyone explain from the code how recursive decent parse generate the following grammer grammer + * 1 2 * 2 2 NAME Syntax-Directed Translation
can anyone explain from the code how recursive decent parse generate the following grammer grammer
+ * 1 2 * 2 2
NAME Syntax-Directed Translation he following partial expression grammar: 112 : instr. format description semantics memory instructions constant valuc into register T arithmetic instructions add contents of registers r and Ty, and store rcsult into register r. multiply contents of registers rx and ry , and store result into register T r.-T2 * rv Here is a rccursive descent parsor that implements a compiler for the above grammar. Here is the important part of the code: int exprO int reg, left.reg, right.reg; switch (token) case+' next token); left-reg -expr(); right-reg = expr(); CodeGen(ADD, left_reg, right.reg, reg return reg; next-register(); = reg case next_token); left-reg-expr(); right-reg = expr(); reg= next-register(); CodeGen (MULT, leftreg, right_reg, reg) return reg: case '1': case 2' return const); int constO f int reg: switch (token) f case , 1,: next-token(); reg= next-register(); CodeGen (LOADI, 1, reg); return reg: next-register(); = ,2': next-token(); reg case CodeGen (LOADI, 2, reg); return reg