Question: In this prelab, you will implement a lex and yacc code that will read a C code snippet that contains declarations and comparisons. In the

In this prelab, you will implement a lex and yacc code that will read a C code snippet that contains
declarations and comparisons. In the input code, there can be any number of if statements and
declarations. Your program should cover all the valid inputs, and reject the invalids.
ATTENTION: Zip your lex, yacc and submit to Yulearn. Your code can be compiled with the
Makefile provided to you. Be sure that Makefile works properly.
1) If statement
Contains a comparison part and body part
The comparison part can contain 1 comparison.
o There will be no && and || operation like we did in prelab2.
Comparison will be only ==
.
If the body can contain other if statements or can contain declarations.
Note: There will be no else if or else In the input file
2) Declaration statement
There can be 2 types of declarations: int and string
.
o You can assume that there will be only 1 declaration per line.
int a;
string b;
o In other words, the input file will not contain declarations like:
int a,b,c;
string a,b;
3) Invalid comparison: The input file can contain invalid comparisons. You should detect
and print an error message for that.
The comparisons should be between the same types. If it is not print an error
message: Type mismatch in line x

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!