This project is aimed at implementing a compiler for a subset of a programming language. It consists of two main phases: lexical analysis (Phase 1) and parsing (Phase 2).
In Phase 1, the lexical analyzer is generated using a tool that constructs a lexical analyzer from a regular expression description of a set of tokens. Here's an overview of the process:
- Scanner: The
Scanner
class is responsible for scanning the input file and generating the NFA (Nondeterministic Finite Automaton) for the given regular expressions. - NFA Conversion: The NFA is then converted to a DFA (Deterministic Finite Automaton) using the
DFA
class. - Minimization: The DFA is minimized to optimize the lexical analyzer using the
Minimize
class. - Matching: The generated DFA is used for matching tokens in the input file with the
Matcher
class. - Token Extraction: The
Matcher
class extracts tokens and outputs them to a file.
In Phase 2, the generated lexical analyzer is integrated with the parser. Here's how it works:
- CFG (Context-Free Grammar) Reader: The
CFGReader
class reads the production rules from a file. - Left Factoring and Left Recursion Elimination: The LL(1) grammar is generated by eliminating left factoring and left recursion using the
LL1_Generator
. - Parsing Table Generation: The LL(1) parsing table is generated using the
ParsingTable
class. - Parsing: The LL(1) parsing is performed using the
Combiner
class, which integrates the lexical analyzer with the parsing table.
- Compile the project.
- Run the executable, providing the input file path (
input.txt
) and the test file path (test.txt
).