Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
If statement
Contains a comparison part and body part
The comparison part can contain comparison.
o There will be no && and operation like we did in prelab
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
Declaration statement
There can be types of declarations: int and string
o You can assume that there will be only declaration per line.
int a;
string b;
o In other words, the input file will not contain declarations like:
int abc;
string ab;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started