0% found this document useful (0 votes)
81 views2 pages

Practical: Generating Lexical Analyzer With Jlex

This document provides instructions for generating a lexical analyzer with JLex. It describes downloading files, creating Java projects in NetBeans, using JLex to process a .lex file to generate a .java file, compiling and running the generated code. The objective is to understand how to generate a Java lexical analyzer from a grammar specification using JLex. Exercises are included to modify the sample .lex file and create a new lexical analyzer for a different grammar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views2 pages

Practical: Generating Lexical Analyzer With Jlex

This document provides instructions for generating a lexical analyzer with JLex. It describes downloading files, creating Java projects in NetBeans, using JLex to process a .lex file to generate a .java file, compiling and running the generated code. The objective is to understand how to generate a Java lexical analyzer from a grammar specification using JLex. Exercises are included to modify the sample .lex file and create a new lexical analyzer for a different grammar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TCP2451 Programming Language Translation

Multimedia University

TCP2451
Programming Language Translation

Lab 8

Practical

Practical: Generating lexical analyzer with JLex

Objective: To describe how to generate a Java lexical analyzer with JLex.

1. Download “Main.java” for JLex.


2. Run NetBeans. Close all projects using the IDE menu.
3. Start new project named “Lab08P01_jlex”
- Project Type: Java Application
- Enter project name “Lab08P01_jlex” and create a new folder to store all the
projects
- Uncheck the “Create Main Class” check box if any
4. Create a Java package and name it “JLex”.
5. Create a Java file in this package and name it “Main.java”.
6. Open the downloaded file “Main.java”. Copy the contents of the downloaded file
to “Main.java” in this project.
7. Compile the program.
8. Download “e.lex” into the “Lab08P01_jlex” project folder.
9. Right-click project -> Properties -> Run and enter the following:
- Main class: JLex.Main
- Arguments: e.lex
- Working directory: (your appropriate project directory path e.g.
“C:\yourname\Lab08P01_jlex”)
10. Run the program and view the output file “e.lex.java”.
11. Close the project.
12. Start new project named “Lab08P01_SimpleExample”
- Type: Java Application
- Enter project name “Lab08P01_SimpleExample”
13. Create a Java package and name it “SimpleExample”. Create a Java file in this
package and name it “Main.java”.

1
TCP2451 Programming Language Translation

14. Copy the contents of the “e.lex.java” to replace the entire content in the
“Main.java” of this project.
15. Compile the program.
16. Right-click project -> Properties -> Run and enter the following:
- Main class: SimpleExample.SimpleExample
17. Run the program and view output generated.

Exercise
1. Examine the contents of e.lex and search the Internet for the JLex manual to
understand the contents.
2. Modify e.lex to include tokens for arithmetic and relational operators.
3. Create a Lex file for a different grammar for JLex to generate the lexical analyzer.
Test the lexical analyzer with at least three sample source programs.

You might also like