Skip to content

Compilers, Interpreters, with Spirit parser and LLVM code generator, for educational purposes

Notifications You must be signed in to change notification settings

Arcterus/Computer-Languages

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# 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

About

Compilers, Interpreters, with Spirit parser and LLVM code generator, for educational purposes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages