In today's recitation, we discussed a handout that was given out in this
morning's lecture. In order for JLex to run correctly, be sure to set up your
CLASSPATH
environment variable properly, as described in
Assignment #2.
The JLex input file, usually called [something].jlex
, is broken
up into three sections (delimited by %%
on a line by itself) as
follows:
ex.jlex
, we define a class,
Token
.Digit=[0-9]
. Also, you must tell JLex what
type to return as a token (%type Token
), and what to do upon
hitting End Of File. If you want extra fields in class yytext() then enter
them between '%{'
and '%}'
without the tick marks.
csx.jlex
is a starting point for Project 2. All those classes
extend the CSXToken class and need no further explanation. The Pos, or
Position class is used to keep track of where we are in the file. You can use
the feature built into JLex to accomplish this, but apparently it returns
weird values for the column number. Check it out in the documentation. There
is a link from the course webpage.
A Symbol()
is defined in java_cup.runtime.*
and
takes as its arguements a sym
and then the data. Its use is
pretty obvious from the handout, and all of the symbols in class
sym
appear at the end in that big thing that looks like it would
be an enum
in C++.