Question: Please write Lexer also if possible! I Will THUMBS UP!!! For this assignment, you will use Racket, a functional programming language, to write a simple

Please write Lexer also if possible! I Will THUMBS UP!!!

For this assignment, you will use Racket, a functional programming language, to write a simple parser. Note that were writing only a parser, not a full interpreter (although interpreters in Racket arent that difficult1). Also, your program only needs to pass a verdict on the syntactical correctness of the program, not produce a full parse tree. The standard interpreter for Racket is DrRacket, and is installed on all Flarsheim lab machines as well as available as a free download from https://racket-lang.org/. Racket is a functional language, so it requires a different approach than what you may be used to. Its expression-oriented; functions take in parameters and return function values, with no side effects. Id suggest spending some time getting familiar with it, perhaps working out some common algorithms in a functional form. Your code should have a function called parse, which takes one parameterthe name of the file of source code to be processed: (parse "source1.txt") It should return a string: either Accept, indicating the program is syntactically correct; or a message as to which line the first syntax error was found: So output will be either: Accept or something like: Syntax error found on line 25 In the case of a syntax error, printing the offending line would also be helpful. It is not necessary to continue scanning for additional syntax errors. The grammar you are to use is listed below. This is a simplified version of 70s-era BASIC: statements are line numbered. There can be more than one statement on a line. You have selection but not iteration. You must define the FIRST, FOLLOW, and PREDICT sets. Programming notes: You will need other functions besides parse, of course. This will be a top-down recursive- descent parser. You will need one function per nonterminal in the grammar. Youre not limited to printing just a final verdict; progress messages will probably be helpful in development. Submit your source code (.rkt file) and a short document listing any resources you used in developing your program. (This refers to things where you copied & modified someone elses

You will be given several sample files, some with syntax errors, some without. Note that lines must begin with a positive integer; there is no syntax requirement that the lines be listed in order or not be duplicates. In other words:

10 a = 5:b = 10

95 c = a + b

12 write c:write a+b-c

10 a = 1

$$

is syntactically correct. (In an actual interpreter, the second definition of line 10 would replace the first. Lines would still execute in numerical order unless overridden with GOTO, GOSUB, or RETURN.) Likewise, a GOTO or GOSUB to a nonexistent line number is a semantic error, not a syntax error.

The grammar you're parsing:

program -> linelist $$ linelist -> line linelist | epsilon line -> idx stmt linetail* [EOL] idx -> nonzero_digit digit* linetail -> :stmt | epsilon stmt -> id = expr | if expr then stmt | read id | write expr | goto idx | gosub idx | return expr -> id etail | num etail | (expr) etail -> + expr | - expr | = expr | epsilon id -> [a-zA-Z]+ num -> numsign digit digit* numsign -> + | - | epsilon nonzero_digit -> 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 digit -> 0 | nonzero_digit 

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!