-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex.py
47 lines (39 loc) · 1.25 KB
/
lex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
from Grammar import G, num, idx, string
keywords = r"\bclass\b|\blet\b|\bin\b|\bnew\b|\bif\b|\bthen\b|\belse\b|\bfi\b|\bcase\b|\bof\b|\besac\b|\bwhile\b|\bloop\b|\bpool\b|\binherits\b|isVoid\b|not\b|true\b|false\b|"
nums = r"\d+\.\d+|\d+|"
string=r"\".*?\"|"
#string = r"\".*?(?=(?:\\\\)+?\"|[^\\]\").*?\"(?<![^\\]\\\")"
#|\".*?[^\\]*?(?:\\\\)+\""
idex = r"[a-zA-Z]\w*|"
comments = r"\(\*.*?\*\)|--.*?\n" #
#comments = r"\(\*(.+?)\*\)"
symbols = r",|;|:|\{|\}|\(|\)|<-|=>|\.|=|\+|-|\*|/|<|>|@"
#print(text)
#print(" FT\n".join(child for child in text))
#print("cantidad de tokens", len(text))
#s = ""
#for i in tokens:
# i = str(i)
# if i.isspace() or i == "\n":
# assert False, "Bad Tokenization"
# s += i + " "
#print(s)
#def comparer(s, text):
# j = 0
# stesti = ""
# stestj = ""
# for i in range(len(text)):
# if text[i].isspace() or text[i] == "\n":
# continue
# while s[j].isspace() or s[j] == "\n":
# j += 1
# stesti += text[i]
# stestj += s[j]
# if s[j] != text[i]:
# print("i:",stesti, "### text en i:", text[i])
# print("j:",stestj, "### s en j:", s[j])
# return False
# j += 1
# return True
#print(comparer(s, program))