C- Lexical Analyzer and Parser
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
data
lib
output
.gitignore
README.md
main.py
makefile
p4
test.py

README.md

Nicholas Pickering Contruction of Language Translators COP4620 Project 4 - Code Generation Professor Eggen Date Due: 4/19/2016 Date Submitted: 4/19/2016

Introduction

This project is an effort to generate quadruples for execution on a processor. The code generation takes the results of the parser and semantic analyzer, and breaks them into bits of code called quadruples.

Quadruples have the following form: [index, opcode, operand1, operand2, result]

Invoking the application

Invoke the application by calling: ./p4 filename

where filename is the path to the C- program to parse.

Main

The entry point to the application is main.py.

Coden Generation Program Flow

The output created by the Lexical Analyzer/Parser is further processed to generate a table of quadruples - executable bits of code.

The output result is the table listing of the generated quadruples, in the proper order to be executed by a processor.

Lexical Analyzer Program Flow

The input file is processed line by line, character by character. At the beginning of a new token, the analyzer determines the type (or set of types) the new token may belong to.

The analyzer then accepts characters until a character is found which does not comply with the determined token type, handling errors as necessary.

The output result is a listing of tokens as they are recognized. A token collection is ready to be passed to a language parser.

Nested comments and Floating point numbers are supported.

Parser Program Flow

The tokens generated by the lexical analysis are passed to the parser. The recursive descent parser begins analyzing the token stack for correctness in regards to the grammar.

Semantic Analyzer Program Flow

As the parser analyzes the token stack, a symbol table is generated. The symbol table is used to validate the token stack against semantic rules of the C- language.

Output Files

This program produces output to the console.

In the code generation state, the program outputs a table of quadruples.

An example of code generation output is saved to the output directory.