2024-03-26 19:02:54 +00:00
|
|
|
import sly
|
|
|
|
# for ease of reading, the compiler is broken down to multiple files
|
|
|
|
# parser.py for the parser
|
|
|
|
# lexer.py for the lexer
|
|
|
|
# and helper.py for helper functions(such as print_err)
|
|
|
|
from lexer import Lexer
|
|
|
|
from parser import Parser
|
|
|
|
from helper import print_err
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print_err('Aviv Romem')
|
|
|
|
lexer = Lexer()
|
|
|
|
parser = Parser()
|
|
|
|
text = '''
|
|
|
|
a: int;
|
|
|
|
{
|
|
|
|
while(a < 10) {
|
|
|
|
a = a + 1;
|
2024-03-27 15:44:35 +00:00
|
|
|
if(a >= 6 || a == 5)
|
2024-03-26 19:02:54 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
a = a + 0;
|
|
|
|
}
|
2024-03-27 15:44:35 +00:00
|
|
|
output(a);
|
|
|
|
switch(a * 5) {
|
|
|
|
case 1:
|
|
|
|
a = 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
output(a);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
output(a);
|
2024-03-26 19:02:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
parser.parse(lexer.tokenize(text))
|
|
|
|
for l, t in enumerate(parser.lines):
|
|
|
|
print(l,':',t)
|