โ
File extension: .patrik
File: hello.patrik:
func main:
print 1+2
python compiler.py hello.patrik
output: hello.asm
nasm -f macho hello.asm
output: hello.o
ld hello.o
output: 3
Goal | = | MainMehtod |
MainMethod | = | func main : INDENT (Statement)* DEDENT |
Statement | = | print Expression |
Expression | = | Integer + Integer |
Integer |
func main:
print 1
print 1+2
Tokens:
[FUNC, MAIN, COLON, INDENT, PRINT, INT(1), PRINT, INT(1), PLUS, INT(2), DEDENT]
Parse tree:
Goal(
MainMethod([
PrintStatement(
IntExpression(1)
),
PrintStatement(
AddExpression(1, 2)
),
])
)
Assembly:
Output:
1
3
func main:
print 39
Tokens:
[FUNC, MAIN, COLON, INDENT, PRINT, INT(39), DEDENT]
Parse tree:
Goal(
MainMethod([
PrintStatement(
IntExpression(39)
),
])
)
Output:
39