This project implements the lexical analysis phase of a compiler as part of a Compiler Design course.
The lexer is built using JFlex and is responsible for recognizing and categorizing input tokens such as:
- Identifiers
- Keywords
- Operators
- Separators
- Numeric literals (multiple types)
The program reads an input file and prints tokens in the specified formatted output.
- Java
- JFlex (Lexical Analyzer Generator)
compiler-lexer-jflex/
├──docs/
│ └── report.pdf
├── src/
│ ├── Parser.flex # JFlex specification file
│ ├── Parser.java # Generated lexer (from JFlex)
│ └── test.txt # Sample input file
└── README.md
The Parser.flex file defines regular expressions for:
- Keywords
- Operators
- Separators
- Identifiers
- Numeric constants
Each matched token is printed in a formatted structure defined in the project requirements.
Run JFlex on the specification file: jflex Parser.flex
This generates: Parser.java
javac Parser.java
This creates: Parser.class
Place test.txt in the same directory and run: java Parser test.txt
The output tokens will be printed to the console.
- Pattern-based token recognition
- Structured token output
- Modular lexical rule definitions
- Clean separation between specification and generated code
This project demonstrates:
- Practical implementation of lexical analysis
- Usage of lexical analyzer generators
- Regular expression–based tokenization
- Foundations of compiler front-end design
Parser.javais generated automatically fromParser.flex- The
.classfile is not included in the repository - IDE configuration files are excluded via
.gitignore
This project is provided for educational purposes. You may reuse or modify the code with proper attribution.