[SOLVED] data structure algorithm Hmk2 Scanner

$25

File Name: data_structure_algorithm_Hmk2_Scanner.zip
File Size: 348.54 KB

5/5 - (1 vote)

Hmk2 Scanner
Instructor: Zhiyao Liang
Macau University of Science and Technology 2019 FAll
Purpose
Construct a lexical analyzer, also called a scanner for the specified source language. The source language
The source language is documented in the file . Some sample programs of this language are in the folder .
Implementing the scanner
Use the algorithm of scanner discussed in class, which is also documented in the file scanner_algorithm.pdf .
Do not use some automatically generated scanner code.
Design your program with reasonable modules. A possible choice is as follows
: inlcude the declarations of tools for general purpose. : include the definitions of general-purpose tools.
: include token types, and related function prototypes.
: include token related function definitions.
list.h : include declarations related to the list data structure.
tools.h
The_language_N.pdf
Sample_N_programs
tools.c
token.h
token.c

: include the function definitions for the list data structure. : include the declaration of some DFA.
: include the definitions for the DFA.
: include the main function, the driver of the program. Expected behavior of the scanner
Test your scanner with the provided sample language N programs as the source. When a source program is correct,
some token list should be generated, which will be used by the parser in the future.
The generated token list should be printed. For a token if its string cannot be represented by its type, like ID or Number, its string and type should both be printed; otherwise, only the token type need to be printed.
When some error occurs, some (at least one) corresponding error message should be printed. For example, if there is a file sample.n whose content has only two lines:
When the scanner runs with sample.n , the generated token list could be printed as the following:
list.c
automata.h
automata.c
scanner.c
print(The result is:
) ;
output( (3|7 + 5) * 8 / -9) ;
ID: print
LPAR
STRING: The result is:

RPAR
SEMI
ENTER
ID: output
LPAR
LPAR
NUM: 3|7
PLUS
NUM: 5
RPAR
MULTI
NUM: 8
DIV
NEG
NUM: 9
RPAR
SEMI

Here the scanner dos not need to distinguish negative sign with the minus operator. You can let the parser to judge the difference later.
How to submit
Submit before Nov 11, Monday, 9pm.
At most three students can form a group to do the homework together and submit the homework together with an email. If you can do the homework by yourself (a one-person group), it surely will be fine. .
Submit the homework by sending an email with attached program files. The details of how to submit your homework is in the file how_to_submit_homeworks.pdf .
References
1. Among the Automata https://www.theparisreview.org/blog/2012/05/22/among-the-automata/
NEG

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] data structure algorithm Hmk2 Scanner
$25