[SOLVED] Compiler- Lab 9: Attribute Grammars

25.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product

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.

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.