- Notifications
You must be signed in to change notification settings - Fork1
camargodev/compilers
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Compiler for a programming language called The Language.Proposed and developed in UFRGS' Compilers course.You can clone or download this repository freely.
TLC is a flex-bison based compiler. So, you will need to install them.You can use
apt-get install flexand
apt-get install bisonIt also uses programming language C, so you will need GCC.
To get started, open the main folder on a Unix based system and typemake.This command should generateflex andbison necessary files.Also, withmake, you automatically generates the AST (Abstract Syntax Tree) for the language.
To test, you can usemake test.Also, each part has a different set of tests.You can just get into the part specific folder and run the same command.
The root folder has everything that is necessary for running this compiler.Each specific part folder just marks the evolution of the project.Just runmake to generate the necessary files. Visiting theMakefile of each folder will show you how to test.
A lexer scanner was developed to accept the tokens of the language.This scanner uses onlyflex and is available atpart-1/scanner.l.
In this part,bison was introduced to perform the syntactic analysis.If you accesspart-2/parser.y, you'll see that now some syntactic rules were done to give some sense to the inputs.Still, no semantic analysis is performed, so something likeint x = "hello"; is accepted.
In this part, the AST (Abstract Syntax Tree) is build within the syntactic analysis.For this, structs like the onestree.h andlexeme.h were developed.Also, values were added to tokens onscanner.l and tree construction functions were used onparser.y.
In this part, the semantic analysis was added.During the syntactic analysis, the tokens were semanticly verified.This part will prevent the use of undeclared identifiers or double declaration of a identifier, for example.A lot of structs were developed, but the most important are ontable.h, liketable_stack that represents a stack of symbol tables.Also, nodes fortree.h now have types (like a expression node) and conversions are marked on nodes.
In this part, we started the code generation from "The Language" toILOC.Also, the language was trully simplfied and we only deal with integers now.The commands for which code is "generated" are:
- Variable declaration, ie
x int;(global vars),int x;andint x <= 1;(local var with/without inicialization). - If conditionals, ie
if (bool) then {...};andif (bool) then {...} else {...};. - While/Do-While, ie
do {...} while (bool);andwhile (bool) do {...};
- Flex - The Fast Lexical Analyzer
- Bison - A LALR(1) general-purpose parser generator
- GCC - The GNU Compiler Collection
If you want to contribute to this compiler project, just e-mail me atcamargodev@gmail.com.Although this was developed for a college course, it has a huge potential for learning.
- João Vitor de Camargo -Developer
- Marcellus Farias -Developer
- This project was developed under the counseling of UFRGS' professor Lucas Schnorr.
About
In development compiler for UFRGS Compilers course.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.