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