Homework 2
Lexical Analysis  

powered by FreeFind

Modified: 

Overview

The text examines two programs that generate Java lexical analyzers: JavaCC and SableCC. Examples from the text for each generator will be given with instructions on their use.

Assignment

Complete the lexical-analysis part of the JavaCC and SableCC specifications for MiniJava grammar; that is define the tokens for MiniJava. The tokens are bold-faced in the grammar of section A.2 along with the Lexical Issues described in section A.1 of the appendix. One simiplication we'll make is that /* */ comments cannot be nested.

For JavaCC do only those parts necessary for the Sample.java test program.

For SableCC do the complete MiniJava grammar.

Files

Download the following files:

  1. Program2.9.jj - JavaCC definitions from text p. 31. Note that this is not MiniJava but can serve as an example and starting point.
  2. Program2.10.js - SableCC definitions from text p. 32. Note that this is not MiniJava but can serve as an example and starting point.
  3. Main.java - Calls the SableCC lexical analyzer.
  4. Lexical 1, 2, 3 - lexical test programs. Lexical1 and Lexical2 are correct for the definitions, Lexical3 has errors.
  5. Sample.java - Sample MiniJava program.

Getting Started

Turn In

  1. Cover sheet with your name, C431, date, and Homework 2.
  2. Print out of JavaCC and SableCC specification file for MiniJava.
  3. Screen shot listing of Command prompt window showing generation and analysis of Sample.java program for JavaCC and SableCC.

 

Resources

SableCC

JavaCC