Docsity

CIS 400 Spring 2008: Implementing a Lexical Analyzer for Decaf in Java - Prof. Nancy Mccra, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
CIS 400 Spring 2008
Programming Project, Part 1: Lexical Analyzer
The first part of the programming project is to implement the lexical analyzer for the
source language Decaf. For the lexical specification, we will start with the Decaf
language description by Anoop Sarkur and given on the class web page. We may make
modifications to this specification as the semester progresses. Note that the lexical
specification includes integers and hexadecimal constants, but not any floating point,
doubles, etc. For now, the value of an identifier is just the string; we will implement the
symbol table in a later part of the project.
The implementation language will be Java (using JDK 1.5 or later). Template programs
will be developed, based on the project at the University of Linz at http://www.ssw.uni-
linz.ac.at/Misc/CC/.
Design of the lexical analyzer:
Tokens and token types:
For this project, we have chosen to have a detailed set of token types, one for each
operator, reserved word, etc. We have omitted โ€˜>>โ€™ and โ€˜<<โ€™ and โ€˜rotโ€™ from the Decaf
list, and we have chosen to have โ€œhiddenโ€ tokens for whitespace and comments.
Follow the Decaf specification for token boundaries and whitespace.
Omit character constants (in single quotes).
Keep String constants (in double quotes), but omit any handling of special character
notations and escape sequences in the strings. However, as specified, strings should not
carry over to more than one line.
Furthermore, we change the specification so that comments cannot carry over to more
than one line.
The list of token types is given in the accompanying document, DecafLexicalDesign.doc.
Program Design:
Following the Linz framework, a Token class is designed, and two classes โ€“ Scanner.java
and TestScanner.java โ€“ have been partially defined. The Scanner class contains the token
definitions as given above. The TestScanner class contains a main that reads the source
input file and prints out the results. These programs and an initial test source file are
given on the web pages. More test files will follow.
The recommended programming process is to make a scanner that operates by processing
one character at a time. An example scanner of this type was given in a class handout. It
is recommended to try one simple token type first, say the identifiers, and test it with a
source file that is just a stream of identifiers. Continue adding groups of token types until
you have handled all the cases.
pf2

Partial preview of the text

Download CIS 400 Spring 2008: Implementing a Lexical Analyzer for Decaf in Java - Prof. Nancy Mccra and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CIS 400 Spring 2008

Programming Project, Part 1: Lexical Analyzer

The first part of the programming project is to implement the lexical analyzer for the source language Decaf. For the lexical specification, we will start with the Decaf language description by Anoop Sarkur and given on the class web page. We may make modifications to this specification as the semester progresses. Note that the lexical specification includes integers and hexadecimal constants, but not any floating point, doubles, etc. For now, the value of an identifier is just the string; we will implement the symbol table in a later part of the project. The implementation language will be Java (using JDK 1.5 or later). Template programs will be developed, based on the project at the University of Linz at http://www.ssw.uni- linz.ac.at/Misc/CC/. Design of the lexical analyzer: Tokens and token types: For this project, we have chosen to have a detailed set of token types, one for each operator, reserved word, etc. We have omitted โ€˜>>โ€™ and โ€˜<<โ€™ and โ€˜rotโ€™ from the Decaf list, and we have chosen to have โ€œhiddenโ€ tokens for whitespace and comments. Follow the Decaf specification for token boundaries and whitespace. Omit character constants (in single quotes). Keep String constants (in double quotes), but omit any handling of special character notations and escape sequences in the strings. However, as specified, strings should not carry over to more than one line. Furthermore, we change the specification so that comments cannot carry over to more than one line. The list of token types is given in the accompanying document, DecafLexicalDesign.doc. Program Design: Following the Linz framework, a Token class is designed, and two classes โ€“ Scanner.java and TestScanner.java โ€“ have been partially defined. The Scanner class contains the token definitions as given above. The TestScanner class contains a main that reads the source input file and prints out the results. These programs and an initial test source file are given on the web pages. More test files will follow. The recommended programming process is to make a scanner that operates by processing one character at a time. An example scanner of this type was given in a class handout. It is recommended to try one simple token type first, say the identifiers, and test it with a source file that is just a stream of identifiers. Continue adding groups of token types until you have handled all the cases.

Due Date: By Tuesday, Feb 12, midnight, submit files to blackboard (yes, please submit as multiple files, not zipped, at least for these first parts) What to hand in: A short overview document describing your programming progress and test results. Program files, including code documentation.