90 likes | 212 Views
Programming Exercise #1: Using Scanner Generator Lex. J. H. Wang Oct. 18, 2011. Lexical Analysis with Lex. Goal: Using Lex to generate a scanner for your target language Input: a Lex program Output: a scanner for your target language. Input: Lex Program.
E N D
Programming Exercise #1:Using Scanner Generator Lex J. H. Wang Oct. 18, 2011
Lexical Analysis with Lex • Goal: Using Lex to generate a scanner for your target language • Input: a Lex program • Output: a scanner for your target language
Input: Lex Program • First, you have to decide a target language to be analyzed • Ex: Simple programming languages such as: Decaf, Espresso, Cool, … • http://www.stanford.edu/class/cs143/ • You can design your own language for any purpose • Music scores, games, computer graphics, matrix operations, calculators, homepages, XML subset, JSON, … • Then, write the Lex program for the target language • Define the tokens!
Output: Scanner • Run Lex to generate the scanner • You are allowed to use Lex or other scanner generators • Test your scanner with some example test files written in your target language • At least one test file should be submitted
Some Scanner Generators • Lex: on UNIX/Linux(http://dinosaur.compilertools.net/) • Flex: GNU (http://flex.sourceforge.net/) • JLex: for Java (http://www.cs.princeton.edu/~appel/modern/java/JLex/) • JFlex: for Java (http://jflex.de/) • Quex: for C++ (http://quex.sourceforge.net/) • …
Submission • Your submission *must* include • The source code (and optionally your executable file) • Your Lex program • At least one example test files in the target language • A README file that includes • A description of your target language (at least the lexical structure) • Special requirements for compilation or execution environments (ex: Lex version, compilation instructions, …) • The names and the responsible parts for each individual member should be clearly identified
How to Submit • Team-based (at most 2 persons per team) • You have to submit the programs by e-mails • Due: three weeks (Nov. 1, 2011)
Evaluation • Minimum requirement: your Lex program will be used as input to Lex, and the generated scanner will be checked using your example test cases for correctness • Optional bonus depends on the complexity and originality of your target language • You might be required to demo if the program submitted was unable to run