Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me with this C code. We are modifying the existing files given to create a predictive parser based on a BNF. All the
Please help me with this C code. We are modifying the existing files given to create a predictive parser based on a BNF. All the code needed is in the file given; however we are to only edit the files: 'parser.c', 'expr.c', 'prog.c', and 'stmt.c' . ALL OTHER FILES STAY THE SAME.
Thank You!
-----------------------------------------------------------------------------------------------------------------
The file: drive.google.com/file/d/1ZkOEkaILlEhbSeI4RNfQDKN9oB42YHhP/view?usp=sharing
contains starter code for a parser. The parser is for a simple language. In this language: a program is one or more statements, and each statement must end with a"" e a statement is either a function call with exactly one argument, or an assignment statement . an expression is either a function call with exactly one argument, a variable, or a non-negative integer (in other words, a string of digits) ere's an example program that shows most of the features of the language x - abs (z); print(x); Note that functions calls always contain exactly one expression within parentheses Your job is to complete the code in prog.tar so that it will parse a program in this language, and then print it. The file prog.tar contains not just code, but a Makefile and some test files you can run Please do the following copy the tar file to your own directory, untar it, and understand it. Start with main.d compile the code (see the Makefile) to make sure it compiles for you write a BNF grammar for the language edit file parser.c to create a predictive parser based on your BNF (see comment "YOUR CODE HERE" edit your parser so that it returns a prog' object, which in turn contains 'stmt' and 'expr' objects edit files prog.c, stmt.c, and expr.c to implement the print functions in those files (see comments YOUR CODE HERE" Do NOT edit any other files, and do not edit the files above except as explained in the comments. When l test your code I will only use your parser.c, prog.c, stmt.c, and expr.c files. The main program will call your parser to get a prog' object, then print the 'prog' object to reconstruct the program from its parse tree. You can test your code using the program run-tests.sh that is provided in the tar file. This program runs the parser on multiple input files, and provides formatted output. Here's what happens when I use run- tests.sh contains starter code for a parser. The parser is for a simple language. In this language: a program is one or more statements, and each statement must end with a"" e a statement is either a function call with exactly one argument, or an assignment statement . an expression is either a function call with exactly one argument, a variable, or a non-negative integer (in other words, a string of digits) ere's an example program that shows most of the features of the language x - abs (z); print(x); Note that functions calls always contain exactly one expression within parentheses Your job is to complete the code in prog.tar so that it will parse a program in this language, and then print it. The file prog.tar contains not just code, but a Makefile and some test files you can run Please do the following copy the tar file to your own directory, untar it, and understand it. Start with main.d compile the code (see the Makefile) to make sure it compiles for you write a BNF grammar for the language edit file parser.c to create a predictive parser based on your BNF (see comment "YOUR CODE HERE" edit your parser so that it returns a prog' object, which in turn contains 'stmt' and 'expr' objects edit files prog.c, stmt.c, and expr.c to implement the print functions in those files (see comments YOUR CODE HERE" Do NOT edit any other files, and do not edit the files above except as explained in the comments. When l test your code I will only use your parser.c, prog.c, stmt.c, and expr.c files. The main program will call your parser to get a prog' object, then print the 'prog' object to reconstruct the program from its parse tree. You can test your code using the program run-tests.sh that is provided in the tar file. This program runs the parser on multiple input files, and provides formatted output. Here's what happens when I use run- tests.sh
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