bugfix in lexer
This commit is contained in:
@@ -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')
|
||||
|
Reference in New Issue
Block a user