Question: Problem: Write a Lex specification and use the Lex generator to construct a lexical analyzer for a language with the following lexical properties. Lexical Conventions:

Problem:
Write a Lex specification and use the Lex generator to construct a lexical analyzer for a language with the following lexical properties.
Lexical Conventions:
See Appendix A section A.1 of the Text Book and replace the definition of ID and NUM as follows:
ID = letter (letter | digit )*+((.|@ |_)(letter | digit )|)
) digit ) NUM = digit +| digit+. digit +(((E |e)(+|-|+)|
You need also to consider that the characters in the keywords and identifiers can appear as capital or small letters (i.e. no distinction between capital and small. A is like a and if is like IF and If)
Error Handling
Handle the following errors:
1. Reaching the end of file while a comment is not closed,
2. Finding a character which is not in the alphabet of the language
3. Exiting from the scanning of a token while not reaching the final state. For example, while recognizing an identifier, you find * after -( aaa_*), or while recognizing a number you find a letter after e(2.3eX).
4. Do not handle the problem of having a number followed by an identifier without leavening spaces and similar problems. This will be handled by the parser. For example your scanner will produce as an output num id for the string 12ab because this string, 12 ab, is still erroneous even if you leave spaces.
Print meaningful error messages for these lexical errors, indicating the line number and character position where the error occurs
Output
The output is a list of tokens, and lexemes. Error messages should appear in the proper place indicating the line at which the error has occurred.
What you should submit
1. All source files and executable file to be send by email to the assistant with a copy to me
2. A report in which you discuss any decision you have taken and instructions to the assistant to run your program. Test inputs, and outputs should also be appended to your report.
Grading
Your grade will be divided into the following components:
1. Correctness including Error handling 70%
2. Documentation and structure of lex file and code. 20%
3. Report Content and Presentation 10%

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 Programming Questions!