Question: Write a recursive descent parser in c++ that will also perform type checking (using static semantics) of a language for assignment statements with arithmetic expressions

Write a recursive descent parser in c++ 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. 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. the grammar and attributes are the following and should accept sentences like:

Example sentences:

a = b + a * c;

b = (x + y) * b;

b = ---b;

x = -(a * b) + c;

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

BNF Grammar:

:= =

:=

| +

| -

:=

| *

| /

:= ()

|

|

:= a | b | c

Grammar Attributes and rules:

:= =

.type = .type

:=

.type = .type

:= +

Predicate: .type == .type

.type <- .type

:= -

Predicate: .type == .type

.type <- .type

:=

.type == .type

:= *

.type == .type

.type <- .type

:= /

.type == .type

.type <- .type

:= ()

.type = (.type)

:=

.type <- .type

:= a | b | c

.type lookup(.lexeme)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!