Starting from:

$25

Compiler- Lab 9: Attribute Grammars Solved

Developing a simple calculator

Q1.1. Describe Context Free Grammar (CFG) for arithmetic expressions. Operations to consider are addition, subtraction, division and multiplication. Check that your grammar Is suitable for LR parsing.

Q1.2 We recently discussed about attribute grammars. Design an attribute grammar (by adding appropriate attributes and semantic rules) for the CFG developed in 1.1 to be able to evaluate the result of given arithmetic expression.  The starting non-terminal symbol should have a single synthesized attribute whose value should be the result of the expression being parsed. Consider an example expression and illustrate how your solution works (using parse tree, dependency graph etc).

Q2. Implement a simple calculator (use LEX+YACC tools).

You have already designed a solution in Q1. Implement a simple calculator using tools such as YACC where we only need to describe the grammars designed in Q1 in the required format.

OPTIONAL: Consider other operations.

More products