In This Prelab You Will Implement A Lex And Yace Code That Will Read A C Code Snippet That Contains Functions In Input 1 (269.74 KiB) Viewed 85 times
In This Prelab You Will Implement A Lex And Yace Code That Will Read A C Code Snippet That Contains Functions In Input 2 (198.99 KiB) Viewed 85 times
In This Prelab You Will Implement A Lex And Yace Code That Will Read A C Code Snippet That Contains Functions In Input 3 (34.62 KiB) Viewed 85 times
In this prelab, you will implement a lex and yace code that will read a C code snippet that contains functions. In input code, there can be any number of function prototypes, function implementation and function calls. Your program should cover all the valid inputs and, in the end, should print the number of prototypes, implementations and calls. WARNING: You just need to write a lex and yaco file that will accept the given syntax and reject the invalids. You do not need to print an error message for invalid examples except the ones mentioned in "THE RULES" section below ATTENTION: Zip your lex, yace and submit to Yulearn. Your code can be compiled with the Makefile provided to you. Be sure that Makefile works properly. 1) Function prototype (20 pts) has a a) Return type which can be "int" "char", "double" or "float". b) Function names start with a character, then alphanumeric characters follow it. c) List of input parameters separated with commas between open and close parenthesis. There can be zero or an infinite number of parameters, d) A parameter list in a prototype contains variables and their types. e) A function prototype terminates with a semicolon symbol. Examples: int fun10: float (2a(int a, int b float c); 2) Function implementation (20 pts) has the same properties as the function prototype but: a) It has no semicolon at the end. It terminates with consecutive" and symbols. b) it can contain from zero to infinite number of function calls or nested function calls. Examples: Int fun10 float f2a(int a. Int b. floare 12a(fun10.etungo 3
3) Function call (20 pts) has a) Function name b) Between open and alone patentes parameters lo separated with commas, c) A parameter list can contain varascon wipe and function calls recursively Note that there can be any number of Vale and function calls. Examples: fun1(at2n(aba) tun(a, 12a 10x y ), b, c) x ) THE RULES: . Function prototypes should be on the top of the wput You should not accept the input that has function prototype below any function mplementation And print nothing but an error message. (10 pts) o You do not need to detect the error Just write the correct grammar to reject the undesired ones 0 Just print "syntax error in ne x Detect if the input contains a function with an extra in the end. And print an error message like the example below (18 p.) Print number of function prototypes functions, and function calls in the end If there is no error. (15 pts) . Input float 12a(int a int boala Outpur Con Extra > THE SUBMISSION . Submit your lex and yace Mile Your files can be run with the Makehle oven to you Test your code with the examples given to you
Please read the prelab2.pdf file for explanation of Prelab 2. Makefile is for compiling your lex and yacc files. You can use it by "make" command (You need to name your lex and yacc files as "prelab2.l" and "prelab2.y" respectively). After make, you can run your out file by"./prelab2" command. Do not forget to use input file when executing":/prelab2" command.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!