Compiler - Lexical Analyzer

This project is a lexical analyzer (scanner) written in Java. It reads a source code file, tokenizes it based on a finite state machine, and detects reserved words, identifiers, numbers, symbols, and errors.

Role
Developer (academic project)
Year
2024
Java
Compiler - Lexical Analyzer website screenshot

What I did

  • Designed and implemented a finite state machine (FSM) to tokenize source code into meaningful lexical units

  • Built recognition logic for reserved words, identifiers, numeric literals, symbols, and lexical errors

  • Developed a file reader pipeline that processes raw source code and outputs a structured token stream

Challenge

The first stage of a compiler: read raw source code and turn it into a structured stream of tokens, while detecting reserved words, identifiers, numbers, symbols and lexical errors.

Solution

I wrote a scanner in Java built around a finite state machine, with recognition logic for each token type and a file reader pipeline that processes the source and outputs the token stream.

Results

  • A working lexical analyzer based on a finite state machine

  • Recognizes reserved words, identifiers, numeric literals and symbols

  • Reports lexical errors in the source code

Have a similar project in mind?

Tell me what you're building and let's see how I can help.

Get in touch