Skip to content

A smaller C based complier built from scratch using yacc and lex for grammar and lexical analyzer tools. Use

Notifications You must be signed in to change notification settings

Mbiwersi/C-based-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler

Custom built compiler using Yacc and Lex.

What is included

Interger Variables and Expressions

  • Interger Literals, Variables
  • Assignment Statements
  • Arithemtic Operators (+, -, *, /, ^, -(unary minus))
  • P

Boolean Variables and Expressions

  • Boolean Literals, Variables
  • Assignment Statements
  • Relational Operators (<, <=, ==, >=, >, !=)
  • Boolean Operators (!, &&, ||)
  • NOTE: Parentheses do not work - we when through it in office hours can could not figure out why

Input / output

  • read(comma delimted list of variables)
    • read(x, y, z)
    • 1 (true), and 0 (false) can be input for boolean variables
  • print(comma delimted list of Expressions);
    • print(2x, x^3(zw), abc/xyz, c)
  • printlines(expression)
    • print expression number of newlines
  • printString("Literal String")

Control Structures

  • if statements including optional else
  • while loops

Arrays

  • 1 Dimensional Arrays
  • 2 Dimensional Arrays

Functions

  • void parameterless functions

Run Locally (GNU / MAC)

Clone the project

git clone https://github.com/Mbiwersi/C-based-Compiler

Go to the project directory

cd my-project

Generate supporting yacc files

yacc -d ExprEval.y

Generate supporting lex files

lex lex1.l

Compile Files

cc -o comp lex.yy.c y.tab.c SymTab.c Semantics.c CodeGen.c IOMngr.c main.c

Execute the Program

./comp source.txt listing.lst asmCode.asm

Run Locally (Windows / GCC)

Clone the project

git clone https://github.com/Mbiwersi/C-based-Compiler

Go to the project directory

cd my-project

Generate supporting yacc files

bison -dy ExprEval.y

Generate supporting lex files

lex lex1.l

Compile Files

gcc -o comp lex.yy.c y.tab.c SymTab.c Semantics.c CodeGen.c IOMngr.c main.c

Execute the Program

./comp source.txt listing.lst asmCode.asm

About

A smaller C based complier built from scratch using yacc and lex for grammar and lexical analyzer tools. Use

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published