Skip to content

First three phases of the front-end compiler as explained in the dragon book.

Notifications You must be signed in to change notification settings

BlueLort/Compiler-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Generator

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.

📝 Table of Contents


About

An implementation of a front-end compiler that is divided into three phases:

  • Lexical analyzer generator
  • Parser generator
  • Java bytecode generation

Lexical analyzer generator

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.

Parser generator

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.

Java bytecode generation

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

Project_flow


Prerequisites

You need to have the following installed:

  • Java
  • GNU Bison
  • GNU Flex

Features

  • 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.

Sample Runs

  • Simple editor to lay rules/code in and a simple code analyzer UI to check:
    • Tokens (Lexemes)
    • Transition table
    • First and follow sets

About

First three phases of the front-end compiler as explained in the dragon book.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published