A compiler translates and/or compiles a program written in a suitable source language into an equivalent target language without changing the meaning of the program through a number of stages.
An implementation of a front-end compiler that is divided into three phases:
- Lexical analyzer generator
- Parser generator
- Java bytecode generation
The lexical analyzer generator is required to automatically construct a lexical analyzer from a regular expression description of a set of tokens. The tool is required to construct a nondeterministic finite automata (NFA) for the given regular expressions, combine these NFAs together with a new starting state, convert the resulting NFA to a DFA, minimize it and emit the transition table for the reduced DFA together with a lexical analyzer program that simulates the resulting DFA machine.
The generated lexical analyzer has to read its input one character at a time, until it finds the longest prefix of the input, which matches one of the given regular expressions. It should create a symbol table and insert each identifier in the table. If more than one regular expression matches some longest prefix of the input, the lexical analyzer should break the tie in favor of the regular expression listed first in the regular specifications.
The parser generator expects an LL (1) grammar as input, it should compute the first and follow and uses them to construct the predictive parsing table.
The table is used to derive a predictive top-down parser. If the input grammar is not LL (1), an appropriate error message should be produced.
If an error is encountered, a panic-mode error recovery routine is to be called to print an error message and to resume parsing.
The java bytecode generator must follows bytecode instructions defined in the Java virtual machine specifications
Grammar covers the following:
- Primitive types (int, float) with operations on them (+, -, *, /)
- Boolean Expressions
- Arithmetic Expressions
- Assignment statements
- If-else statements
- for loops
- while loops
- Java
- GNU Bison
- GNU Flex
- Code imporing/exporting + editable area in the GUI.
- Left Factoring Enabled.
- Left Recursion Elimination (both direct & indirect).
- Ability to view:
- NFA , DFA (for debugging).
- Tranisition table.
- Lexemes table.
- First & Follow Sets.
- Parsing table.
- Parse tree ( for debugging).
- Third phase is implemented by using GNU Bison.
- Simple editor to lay rules/code in and a simple code analyzer UI to check:
- Tokens (Lexemes)
- Transition table
- First and follow sets