Homework 1: scanner
2023 FAll
1. Introduction
We will construct a lexical analyzer, also called a scanner for the specified source language Pyr.
2 Helpful files
Some helpful files can be found at the Moodle site of this course at our university, under the section "Slides and Handouts".
- Files of Pyr: The specification documents and sample-program (.arr) files of Pyr, which are explained in classroom, are on Moodle. Please read and understand these files.
- Files of C-minus: Some sample programs (.cm) files of the C-minus language can be found at the Moodle site. Also uploaded are the output record (.txt) files of a scanner for the C-minus language. These files can show the expected behavior of a scanner for Pyr. An output file is recorded using a command like:
scanner_file_name program_name.cm > output_file_name.txt
- Note: we want to build a scanner for the Pyr language, not for C-minus.
- Note: you can decide the details of your scanner. As long as your scanner can obtain a list of tokens and print them out properly (like the behavior of a scanner for C-minus), it is okay.
- Scanner algorithm: A folder of "A simple DFA-based scanner algorithm" is on the Moodle site, which describes a DFA-based algorithm to build a scanner, which can be helpful to implement a scanner with high quality.
- Helpful C code: Implementing the compiler using C is recommended. Some helpful .c files are on Moodle, which can guide the implementation of a scanner for Pyr (customization and extensions are needed).
Implementing the scanner
Expected behavior of the scanner
Test your scanner with each of the provided sample language Pyr files (.arr), making sure that the correct list of tokens can be built and printed.
How to submit
- Files to be submitted on Moodle:
- All source code files (.c and .h if using C to write the scanner).
- A "hmk1-report" text file. The format can be .txt, .docx, .pdf, or .html. This file should describe the following:
- The full names of each group member.
- What features of the scanner are successfully implemented?
- If there are some remaining problems, what are they?
- If the number of group members is more than one, describe each group member's workload and contribution in detail.
- Note: We do not want one member to do all the work or one member to do nothing.
- Submit before Nov 11, Saturday, 9 p.m.
- At most, three students can form a group to do the homework together and submit the homework together with an email. You are encouraged to do the homework alone (a one-person group).
References
- "Among the Automata" https://www.theparisreview.org/blog/2012/05/22/among-the-automata/