Question: Implement scanner for the provided lexical definitions. The scanner is embedded and thus it will return one token every time it is called. Since the
Implement scanner for the provided lexical definitions.
The scanner is embedded and thus it will return one token every time it is called. Since the parser is not available yet, we will use a tester program to call the scanner.
The scanner could be implemented as
1.) Plain string reader - read strings separated by spaces - (70 points) assuming
all tokens must be separated by spaces
lines may not be counted (75 if counted)
comments may be without spaces
2.) Module generated by lex
3.) FSA table + driver
Requirements:
* Implement a token as a triplet {tokenID, tokenInstance, line#} (if option with line numbers)
*Dont forget EOFtk token
*Implement the scanner in a separate file with basename "scanner"
*For testing purposes, the scanner will be tested using a testing driver implemented in file with basename "testScanner". You need to implement your own tester and include as a part of the project. The tester will ask one token at a time and display the token to the screen one per line, including information (descriptive) on what token class, what token instance, and what line, if applicable.
* Invocation:
scanner [file]
to read from stdin or file file.fs18
*Arguments are the same as P0
*Wrong invocations may not be graded
*Dont confuse executable name with file name with function name
You must have (C++ can be accordingly different)
*types including token type in token.h
*implement scanner in scanner.c and scanner.h
*implement the tester in another file testScanner.c and testScanner.h
*main.c processing the arguments (as P0) then calling testScanner() function with interface and preparation as needed.
Lexical Definitions:
*All case sensitive
*Each scanner error should display "Scanner Error:" followed by details including the line number ff available
*Alphabet
1. All English letters (upper and lower), digits, plus the extra characters as seen below, plus WS
2. No other characters allowed and they should generate errors
*Identifiers
1. begin with a lower case letter and continue with any number of letters or underscores
2. you may assume no identifier is longer than 8 characters
*Keywords (reserved, suggested individual tokens)
A.) start, stop, loop, void, var, return, scan, out, program, if, then, let
*Operators and delimiters group.
A.) = < > : + - * / % . ( ) , { } ; [ ]
*Integers
Any sequence of decimal digits, no sign, no decimal point. You may assume no number longer than 8 characters .Comments start with $ and end with $.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
