Skip to content

4nickpick/cminus-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

C- Lexical Analyzer and Parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages