Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CREATE A RECURSIVE DESCENT PARSER IN C++ FOR THE FOLLOWING GRAMMAR AND ATTRIBUTE RULES PLEASE PROVIDE A MAIN METHOD THAT TEST THE CODE!!!!!!!!!!!!!!!!!!!!!!!!!!! Write a

CREATE A RECURSIVE DESCENT PARSER IN C++ FOR THE FOLLOWING GRAMMAR AND ATTRIBUTE RULES

PLEASE PROVIDE A MAIN METHOD THAT TEST THE CODE!!!!!!!!!!!!!!!!!!!!!!!!!!!

Write a recursive descent parser that will also perform type checking (using static semantics) of a language for assignment statements with arithmetic expressions in which the variables may be of type int or float, mixed-type expressions are allowed with an automatic widening type conversion, but mixed-type assignments are not allowed.

For your recursive descent parser write an unambiguous BNF grammar for assignment statements with arithmetic expressions and follow it strictly. Allow binary operations +, -, *, and / and unary operations + and -. The unary operations should have equal priority which is higher than the priority of * and /; * and / should have equal priority which is higher than the priority of + and -. An expression in parentheses should be possible to use as an operand for any operation. The parentheses have the highest priority. Use as a goal symbol and id as a terminal symbol representing an identifier. Recognize single letters as identifiers. Example sentences:

a = b + a * c;

b = (x + y) * b;

b = ---b;

x = -(a * b) + c;

x = (((a * b))) - + c;

At the first occurrence of each identifier randomly generate its type and store it in a symbol table, so that you can look up the type of any further occurrence of this identifier. Allow the user to see the contents of the symbol table after each assignment statement.

BNF Grammar:

:= =

:=

| +

| -

:=

| *

| /

:= ()

|

|

:= a | b | c

Grammar Attributes and rules:

:= =

.value = .value

:=

.value = .value

:= +

.value = .value + .value

:= -

.value = .value - .value

:=

.value = .value

:= *

.value = .value * .value

:= /

.value = .value / .value

:= ()

.value = (.value)

:=

.value = (.lexeme == '+') = .value

.value = (.lexeme == '-') = - .value

:= a | b | c

.value = Symbol_Table[.lexeme]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

Describe the three parts of developing a new habit.

Answered: 1 week ago

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago