It's the first compiler I write. I am building a new own programming language.
Variables | If/ElseIf/Else | Loop | Function | Recursion | |
---|---|---|---|---|---|
Runtime | ✔ | ✔ | ✔ | ✔ | ✔ |
Code Generation | ✔ | ✔ | ✔ | ✔ | ✔ |
Python version >= 3 (install python)
Open your bash, got to project's root directory and then type python main.py --src tests\fibonacci.an
. Type python main.py --help
to see more options.
You can write your own algorithm creating a new file new_file.an
and then running it as explained above.
loop 7:
print "Hello World"
endloop
namespace an
{
class Program
{
static void Main()
{
for (int i = 0; i < 7; i += 1)
{
System.Console.WriteLine("Hello World");
}
}
}
}
You can view AST while compiling
-> Statements
|-> Loop
|-> VarDeclare
|______|______|-> x
|______|-> =
|______|______|-> Num
|______|______|______|-> 0
|______|-> x
|-> <
|______|-> Num
|______|______|-> 10
|______|-> x
|-> =
|______|______|-> x
|______|-> +
|______|______|-> Num
|______|______|______|-> 1
|-> Statements
|______|-> Print
|______|______|-> x
declare n = 10
declare t = 0
declare tt = 1
declare nextTerm = 0
loop declare i = 1; i <= n; i = i + 1:
if i == 1:
print t
elseif i == 2:
print tt
endif
nextTerm = t + tt
t = tt
tt = nextTerm
print nextTerm
endloop
print "Hello World"
You still cannot change a value from a collection (contribute for this feature!)
declare collection = [1, 2, 3, 4, 5]
append(collection, 6)
loop declare i = 0; i < count(collection); i = i+1:
print collection[i]
endloop
declare x = 0
while x < 10:
x = x + 1
print x
elsewhile x < 20:
x = x + 10
print x
endwhile
loop declare x = 0; x < 10; x = x + 1:
print x
endloop
loop declare i = 0; 10:
print "Hello World " + i
endloop
loop 7:
print "Hello World"
endloop
E-mail: [email protected]
Linkedin: Alan Nunes
Thank you, I hope you like it!