Skip to content

Instantly share code, notes, and snippets.

@jere-mie
Last active February 4, 2022 04:40
Show Gist options
  • Save jere-mie/b028cf1693f77878a1b8975918e94544 to your computer and use it in GitHub Desktop.
Save jere-mie/b028cf1693f77878a1b8975918e94544 to your computer and use it in GitHub Desktop.
Installing JLex

Instructions to Install JLex on the CS Servers

Want all the instructions in one code block without the explanations? Check out the appendix.

Before Starting

You may want to create a separate "2140" directory for this class:

mkdir 2140
cd 2140

Make sure you download the following two files:

  1. Main.java
  2. simple.lex

You can download files on the CS servers by running wget url, where url is replaced with the url of the file you want to download.
So, to download these two files, you can run:

wget http://jlu.myweb.cs.uwindsor.ca/214/Main.java
wget http://jlu.myweb.cs.uwindsor.ca/214/simple.lex

Instructions

  1. Create a "JLex" directory (case sensitive!):
mkdir JLex
  1. Move "Main.java" (attached) into the JLex directory
 mv Main.java JLex
  1. cd into the JLex directory
cd JLex
  1. Compile "Main.java"
javac Main.java
  1. Move back to the parent directory
cd ..
  1. JLex is now installed! You can now run the scanner generator.
    The general method to do this is to run: java JLex.Main lexFileName, replacing lexFileName with the name of your lex file.
    We'll use the sample lex file simple.lex, courtesy of Dr. Jianguo Lu, which we downloaded earlier.
    To run this file, simply type:
java JLex.Main simple.lex
  1. You should now see a new file generated, called lexFileName.java, or in this case simple.lex.java. We must now compile it, by typing:
javac simple.lex.java
  1. A new file, MyLexer.class should have been created (note, if using a lex file other than simple.lex, this file may be named something different). We can now run the lexer by running:
java MyLexer

That's it!

Now try typing stuff on your keyboard and see how the lexer responds. Try typing "int" or typing some words, like "hello" and "world".

Appendix

All the commands in one block

mkdir 2140
cd 2140
wget http://jlu.myweb.cs.uwindsor.ca/214/Main.java
wget http://jlu.myweb.cs.uwindsor.ca/214/simple.lex
mkdir JLex
mv Main.java JLex
cd JLex
javac Main.java
cd ..
java JLex.Main simple.lex
javac simple.lex.java
java MyLexer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment