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 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 ie no distinction between capital and small. A is like a and if is like IF and If
Error Handling
Handle the following errors:
Reaching the end of file while a comment is not closed,
Finding a character which is not in the alphabet of the language
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 eeX
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 ab because this string, 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
All source files and executable file to be send by email to the assistant with a copy to me
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:
Correctness including Error handling
Documentation and structure of lex file and code.
Report Content and Presentation
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
