Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simomux/kaleidoscopecompiler
Project for my front-end compilers exam A.Y. 2023-2024
https://github.com/simomux/kaleidoscopecompiler
ast bison-flex clang kaleidoscope llvm
Last synced: 4 days ago
JSON representation
Project for my front-end compilers exam A.Y. 2023-2024
- Host: GitHub
- URL: https://github.com/simomux/kaleidoscopecompiler
- Owner: simomux
- Created: 2024-03-18T14:22:36.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-06-09T12:39:33.000Z (8 months ago)
- Last Synced: 2025-02-05T11:49:51.564Z (4 days ago)
- Topics: ast, bison-flex, clang, kaleidoscope, llvm
- Language: C++
- Homepage:
- Size: 473 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Assignment for my front-end compilers class A.Y. 2023-2024
## Objective
Create a front-end compiler for Kaleidoscope extending the skeleton template from a modified version of the code from [My First Language Frontend with LLVM Tutorial](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index.html).
The assignment is divided in 4 parts, each one giving you a grammar and reuqiring the implementation of it and of the necessaries AST nodes.
### First level grammar
Fisrt part requires to implement assignment logic for variables.
Grammar
```bison
% start startsymb;startsymb:
programprogram:
% empty
| top ";" program % left ":";top:
% empty
| definition
| external
| globalvardefinition:
"def" proto blockexternal:
"extern" protoproto:
"id" "(" idseq ")"globalvar :
" global " "id"idseq :
% empty
| "id" idseq%left ":";
%left " <" "==";
%left "+" " -";
%left "*" "/";stmts :
stmt
| stmt ";" stmtsstmt :
assignment
| block
| expassignment
"id" "=" expblock:
"{" stmts "}"
| "{" vardefs ";" stmts "}"vardefs:
binding
| vardefs ";" bindingbinding:
"var" "id" initexpexp:
exp "+" exp
| exp " -" exp
| exp "*" exp
| exp "/" exp
| idexp
| "(" exp ")"
| "number"
| expifinitexp:
%empty
| "=" expexpif:
condexp "?" exp ":" expcondexp:
exp "<" exp
| exp "==" expidexp:
"id"
| "id" "(" optexp ")"optexp:
%empty
| explistexplist:
exp
| exp "," explist
```### Second level grammar
Implements rules and logic for `if` construct, `for` loops and initializations.
```bison
stmt:
assignment
| block
| ifstmt
| forstmt
| expifstmt:
"if" "(" condexp ")" stmt
| "if" "(" condexp ")" stmt " else " stmtforstmt:
"for" "(" init ";" condexp ";" assignment ")" stmtinit:
binding
| assignment
```### Third level grammar
Implements boolean operators `and`, `or` and `not` for consecutive conditional expressions.
```bison
condexp:
relexp
| relexp "and" condexp
| relexp "or" condexp
| "not" condexp
| "(" condexp ")"relexp:
exp "<" exp
| exp "==" exp
```### Fourth level grammar
TODO
```bison
binding:
"var" "id" initexp
| "var" "id" "[" "number" "]"
| "var" "id" "[" "number" "]" "=" "{" explist "}"idexp:
"id"
| "id" "(" optexp ")"
| "id" "[" exp "]"assignment:
"id" "=" exp
| "id" "[" exp "]" "=" exp
```