-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
44 lines (36 loc) · 1.14 KB
/
README
File metadata and controls
44 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Boost::Spirit + LLVM = WIN !
## This project contains examples on how to build interpreters and compilers with the Spirit parser library and the LLVM backend.
This is a work in progress, with for now, only the first examples as self-contained c++ programs (hence the dupplication). After launching the programs, you have to feed the "code" on standard input
(Ctrl-d to end input when interactive).
* lang-1 only contains artihmetic expressions.
So if you type :
"
1+2*(3+1)-1/2
"
<and Ctrl-d>
it will output:
"
parsing succeded !
; ModuleID = 'lang_1'
define i32 @main() {
entry:
%addtmp = add i32 3, 1
%multmp = mul i32 2, %addtmp
%addtmp1 = add i32 1, %multmp
%divtmp = sdiv i32 1, 2
%subtmp = sub i32 %addtmp1, %divtmp
ret i32 %subtmp
}
"
and then exec the code to print the result:
"
result: 9
"
lang-2 adds variables (var a; var b=...;) and statements must end with a ';'
the program must end with a return statement (return ... ;)
lang-3 adds if{} [else{}] and while(){} control structures and ternary operators.
To be continued ...
# TODO:
* and then make an llvm-backed calc7
* handle scopes with symbols_stack
* handle function definitions