Assignment #2

Lexer

Theo's solution

In this assignment, you will use javacc to generate a lexical analyzer for Tea. Be sure to check the posted grammar solution.

Unlike lex and yacc, the JavaCC tool does not have a separate lexical analyzer generator. We will embed the tokens and the output statements for them within a null parser file.

Here is the outline of the .jj file you will write:

You need to add your tokens within the switch statement to print them out and within the TOKEN declaration.

To run JavaCC:

You can use a Makefile similar to Theo's (at '/cs/users/tvd/Makefile'.) or just run JavaCC from his directory. If you have downloaded it into a /bin directory the command is:

You then run the generated tea.java to create a .class file which is your lexical analyzer. To run your generated lexer, type:

Run your generated lexer on:

(a)
void input_a() {
     a = b3;
     xyz = a + b + c - p / q;
     a = xyz * ( p + q );
     p = a - xyz - p;
}

(b)
void input_b() {
     if ( i > j )
       i = i + j;
     elsif ( i < j )
       i = 1;
}

(c)
void input_c() {
     while ( i < j && j < k ) {
	   k = k + 1;
	   while ( i == j )
		 i = i + 2;
     }
}



(d) A program of your choice. It should test the tokens not tested
in the others. 

Pass in: the JavaCC source file, input and output from the four programs.

In this, and all assignments, you will be graded on the appearance and documentation of your project. Include your token list as part of the documentation. You should use a laser printer to print.

Send questions and comments to: Karen Lemone