bugfix in lexer
This commit is contained in:
parent
aa0be5507e
commit
d66ea29d8f
@ -16,16 +16,17 @@ lib Main {
|
||||
output(test);
|
||||
output(false);
|
||||
|
||||
if (testBool != empty) {
|
||||
/*if (testBool != empty) {
|
||||
output(testEmpty);
|
||||
}
|
||||
}*/
|
||||
test1234(range(0, 10));
|
||||
}
|
||||
|
||||
public func test1234(param: list) {
|
||||
for i in range(0, length(param)) {
|
||||
/*for i in range(0, length(param)) {
|
||||
output(i);
|
||||
}
|
||||
}*/
|
||||
pass;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
from Interpreter.Repo import Repo
|
||||
from Interpreter.Utils import Utils
|
||||
from Models.Token import Token
|
||||
from Models.Interpreter.Token import Token
|
||||
|
||||
|
||||
class Lexer:
|
||||
@ -45,30 +45,29 @@ class Lexer:
|
||||
c = line[i]
|
||||
# ignore comments and spaces
|
||||
if not ol_comment and not self.__ml_comment:
|
||||
# comment filtering
|
||||
if c == '#' and not is_string1 and not is_string2:
|
||||
ol_comment = True
|
||||
|
||||
elif line[i-1] == '/' and c == '/':
|
||||
ol_comment = True
|
||||
|
||||
elif line[i-1] == '/' and c == '*':
|
||||
self.__ml_comment = True
|
||||
i += 2
|
||||
|
||||
# end of number
|
||||
if not c.isdigit() and is_number:
|
||||
elif not c.isdigit() and is_number:
|
||||
self.__add_tok(word, 'number')
|
||||
word = ''
|
||||
is_number = False
|
||||
|
||||
# end of expression char
|
||||
if c not in self.__repo.expr_chars and is_expr_char:
|
||||
elif c not in self.__repo.expr_chars and is_expr_char:
|
||||
self.__add_tok(word, 'expr_char')
|
||||
word = ''
|
||||
is_expr_char = False
|
||||
|
||||
# comment filtering
|
||||
if c == '#' and not is_string1 and not is_string2:
|
||||
ol_comment = True
|
||||
|
||||
elif c == '/' and line[+1] == '/':
|
||||
ol_comment = True
|
||||
|
||||
elif c == '/' and line[+1] == '*':
|
||||
self.__ml_comment = True
|
||||
i += 2
|
||||
|
||||
# begin of is_string1
|
||||
elif c == '\'' and not is_string1:
|
||||
is_string1 = True
|
||||
@ -132,8 +131,8 @@ class Lexer:
|
||||
if c == '\n' and ol_comment:
|
||||
ol_comment = False
|
||||
|
||||
if c == '*' and line[i + 1] == '/':
|
||||
if line[i - 1] == '*' and c == '/':
|
||||
self.__ml_comment = False
|
||||
|
||||
# self.__repo.output_tokens(self.__toks)
|
||||
self.__repo.output_tokens(self.__toks)
|
||||
return self.__toks
|
||||
|
@ -1,5 +1,6 @@
|
||||
from Interpreter.Repo import Repo
|
||||
from Interpreter.Utils import Utils
|
||||
from Models.Interpreter.Token import Token
|
||||
|
||||
|
||||
class Parser:
|
||||
@ -9,4 +10,5 @@ class Parser:
|
||||
self.__utils = utils
|
||||
|
||||
def parse(self, toks: list) -> None:
|
||||
self.__repo.output_tokens(toks)
|
||||
# self.__repo.output_tokens(toks)
|
||||
pass
|
||||
|
@ -27,6 +27,7 @@ class Repo:
|
||||
'public'
|
||||
]
|
||||
self.types = [
|
||||
'any',
|
||||
'number',
|
||||
'string',
|
||||
'bool',
|
||||
@ -35,7 +36,15 @@ class Repo:
|
||||
'emptyType',
|
||||
'void'
|
||||
]
|
||||
self.expr_chars = ['+', '-', '*', '/', '=']
|
||||
self.var_types = [
|
||||
'any',
|
||||
'number',
|
||||
'string',
|
||||
'bool',
|
||||
'list',
|
||||
'dict'
|
||||
]
|
||||
self.expr_chars = ['+', '-', '*', '/', '=', '^']
|
||||
self.bool_expr_chars = ['<', '>', '!', '!=', '==', '>=', '<=']
|
||||
self.bool_values = ['true', 'false']
|
||||
self.format_chars = ['{', '}', '(', ')', ';', ':', ',']
|
||||
@ -45,10 +54,10 @@ class Repo:
|
||||
|
||||
def output_tokens(self, toks: list) -> None:
|
||||
if self.debug and len(toks) > 0:
|
||||
# outp_toks = []
|
||||
outp_toks = []
|
||||
for tok in toks:
|
||||
# outp_toks.append({tok.value: tok.type})
|
||||
print({tok.value: tok.type})
|
||||
outp_toks.append({tok.value: tok.type})
|
||||
# print({tok.value: tok.type})
|
||||
|
||||
# print(outp_toks)
|
||||
print('\n')
|
||||
print(outp_toks)
|
||||
# print('\n')
|
||||
|
@ -1,7 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from Models.Error import Error
|
||||
from Models.Language.Error import Error
|
||||
from ServiceInitializer import ServiceInitializer
|
||||
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
class Class:
|
||||
|
||||
def __init__(self, name: str, ast: list, access: ''):
|
||||
self.name = name
|
||||
self.ast = ast
|
||||
self.access = access
|
@ -1,6 +0,0 @@
|
||||
class Func:
|
||||
|
||||
def __init__(self, name: str, ast: list, access='') -> None:
|
||||
self.name = name
|
||||
self.ast = ast
|
||||
self.access = access
|
0
src/Models/Interpreter/__init__.py
Normal file
0
src/Models/Interpreter/__init__.py
Normal file
0
src/Models/Language/__init__.py
Normal file
0
src/Models/Language/__init__.py
Normal file
@ -1,5 +0,0 @@
|
||||
class Lib:
|
||||
|
||||
def __init__(self, name: str, ast: list):
|
||||
self.name = name
|
||||
self.ast = ast
|
@ -1,6 +0,0 @@
|
||||
class Var:
|
||||
|
||||
def __init__(self, name: str, value: str, type: str) -> None:
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.type = type
|
3
src/test.py
Normal file
3
src/test.py
Normal file
@ -0,0 +1,3 @@
|
||||
test = 3 ** 2
|
||||
print(test)
|
||||
print(eval('3**2'))
|
Loading…
Reference in New Issue
Block a user