|
School of Computer Science University of Windsor
03-60-214: Computer Languages, Grammars
and Translators (Winter 2007)
|
|
|
Installing and running JLexIn this lab you can first try to run simple.lex, mylexer2.lex, and english.lex. After you get familiar with JLex specification and scanner generation process, you can start to work on assignment 2. Install JLex
Run JLexyou can run the scanner generator by typing the following commands: > java JLex.Main lexfileName for example, you can try to generate a scanner from simple.lex sepcification: > java JLex.Main simple.lex make sure that when you type the command you are in the directory one layer above JLex. Notice what file is generated by JLex. You should see that a new file (the scanner) called lexfileName.java (e.g., simple.lex.java) is produced. Now you can compile and run the scanner. Compile the scannertake a look at the file simple.lex.java. We will notice the class name is MyLexer; Change the file name of simple.lex.java to MyLexer.java bytyping: >mv simple.lex.java MyLexer.java Then you can compile the scanner (e.g. MyLexer.java) by typing: >javac MyLexer.java Or alternatively you can directly compile the generated code without changing its file name by: >javac simple.lex.java look at the files that are generated. In some cases several classes may be generated; Run the scannernow you can run the scanner by: >java MyLexer notice that in general the Main method can be in other classes; input something on the keyboard to see what happens. Now you have completed the process, you should look the lex spec, the scanner generated, and try to change the lex to produce different scanners. |
Instructor: Dr. Jianguo Lu Email: jlu at uwindsor Office: 5111 Lambton Tower Phone: 519.253.3000 ext 3786
|