https://github.com/billgewrgoulas/custom-compiler
Compiler for a small programming language, built for the Compilers course at UOI.
https://github.com/billgewrgoulas/custom-compiler
assembler code-generation compiler interpreter lexical-analysis programming-language symbol-table syntax-analysis syntax-tree
Last synced: about 2 months ago
JSON representation
Compiler for a small programming language, built for the Compilers course at UOI.
- Host: GitHub
- URL: https://github.com/billgewrgoulas/custom-compiler
- Owner: billgewrgoulas
- Created: 2021-03-10T17:01:01.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T10:51:19.000Z (over 3 years ago)
- Last Synced: 2025-05-29T19:47:48.997Z (about 1 year ago)
- Topics: assembler, code-generation, compiler, interpreter, lexical-analysis, programming-language, symbol-table, syntax-analysis, syntax-tree
- Language: Python
- Homepage:
- Size: 781 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Programming language compiler.
Cimple is a small programming language that borrows elements from other languages like C and pascal. While it doesnt support some of the basic features and tools that most languages do ,it provides a wide variety of structures and elements that have very intresting implementation patterns. Cimple supports functions and procedures ,
parameter passing by value or by reference, complex conditional loops , recursive calls and even nesting in function declaration and many more.
Task: Given a source program written in Cimple , generate the final code written in assembly.
The phaces of the implementation are the following:
* Lexical Analysis
* Syntax Analysis
* Intermidiate Code Generation
* Symbol Table / Meaning Analysis
* Final Code Generation
## Grammar of Cimple (follows the LL(1) principle):
program : program ID block .
block : declarations subprograms statements
declarations : ( declare varlist ; )∗
varlist : ID ( , ID )∗ | ε
subprograms : ( subprogram )∗
subprogram : function ID ( formalparlist ) block | procedure ID ( formalparlist ) block
formalparlist : formalparitem ( , formalparitem )∗ | ε
formalparitem : in ID | inout ID
statements : statement ; | { statement ( ; statement )∗ }
statement : assignStat | ifStat | whileStat | switchcaseStat | forcaseStat | incaseStat | callStat | returnStat | inputStat | printStat | ε
assignStat : ID := expression
ifStat : if ( condition ) statements elsepart
elsepart : else statements | ε
whileStat : while ( condition ) statements
switchcaseStat: switchcase ( case ( condition ) statements )∗ default statements
forcaseStat : forcase ( case ( condition ) statements )∗ default statements
incaseStat : incase ( case ( condition ) statements )∗
returnStat : return( expression )
callStat : call ID( actualparlist )
printStat : print( expression )
inputStat : input( ID )
actualparlist : actualparitem ( , actualparitem )∗ | ε
actualparitem : in expression | inout ID
condition : boolterm ( or boolterm )∗
boolterm : boolfactor ( and boolfactor )∗
boolfactor : not [ condition ] | [ condition ] | expression REL_OP expression
expression : optionalSign term ( ADD_OP term )∗
term : factor ( MUL_OP factor )∗
factor : INTEGER | ( expression ) | ID idtail
idtail : ( actualparlist ) | ε
optionalSign : ADD_OP | ε
REL_OP : = | <= | >= | > | < | <> ; ADD_OP : + |
MUL_OP : * | /
INTEGER : [0-9]+
ID : [a-zA-Z][a-zA-Z0-9]*