Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 Your task is to design and implement a lexical anlayzer for a programming language whose specifications are given below. The scanner identifies and
Question
Your task is to design and implement a lexical anlayzer for a programming language whose specifications are given below. The scanner identifies and outputs tokens valid words and punctuation
in the source program. Its output is a token that can thereafter be used by the syntax analyzer to
verify that the program is syntactically valid. When called, the lexical analyzer should extract the
next token from the source program. The syntax of the language will be specified in TMA #
Punctuation Operators Reserved words
; else integer self
float let struct
func private then
: if public var
or impl read void
and inherits return while
not write
Lexical elements
id letter alphanum
letter a z A Z
alphanum letter digit
digit
integer nonzero digit
nonzero
float integer fraction e integer
fraction digit nonzero
Comments:
Inline comments start with and end with the end of the line they appear in
Block comments start with and end with and may span over multiple lines.
Answer to the following tasks:
a Identify the lexical specification, expressed as regular expressions, that you used in the design of the lexical analyzer.
Note: You should completely describe the data structure of your design and any changes
that you may have applied to the original lexical specifications should be also included.
b Describe the complete operation of your lexical analyzer using finite state diagram.
c Write Lex and Yacc files to construct a lexical analyzer that recognizes the abovestated
tokens. It should be a function that returns a token data structure containing the information
about the next token identified in the source program file. The token data structure should
contains: the token type; the lexeme; and the location, of the token in the source
code.
Note: The parser that Yacc generates should be able to call the lexical analyzer generated by
Lex and perform parsing of the code generated by the given grammar. Your Lex file should
be able to remove any white space from the code. All correspondences should be stored in a
symbol table and printed out as output.
d Identify all the possible lexical errors that the lexical analyzer might encounter and the possible error recovery techniques you could use. Choose one of them and discuss why you
have chosen it
e Include many test cases that test a wide variety of valid and invalid cases
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