This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.py
120 lines (111 loc) · 3.13 KB
/
tokens.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
DIGITS = r"\.*\d+\.*"
CHARACTERS = r'[\u200d\u200b\u0D80-\u0DFFa-zA-Z0-9_]+'
Tokens = {
"INT":'INT',
"FLOAT": 'FLOAT',
"PLUS": 'PLUS : "+"',
"MINUS": 'MINUS : "-"',
"MUL": 'MUL : "*"',
"DIV": 'DIV : "/"',
"LPAREN": 'LPAREN : "("',
"RPAREN": 'RPAREN : ")"',
"EOF": "EOF",
"ID": "IDENTIFIER",
"KEYWORD": "KEYWORD",
"POWER": "POWER : '^'",
"EQ": "EQ : '='",
"COMMA": "COMMA : ','",
"EQEQ": "EQEQ : '=='",
"NOTEQ": "NOTEQ : '!='",
"LESSTHAN": "LESSTHAN : '<'",
"GREATERTHAN": "GREATERTHAN : '>'",
"LTEQ": "LTEQ : '<='",
"GTEQ": "GTEQ : '>='",
"NEWLINE":"NEWLINE",
"ARROW": "ARROW : ->",
"STRING": "STRING",
"LSQUARE": "LSQUARE : '['",
"RSQUARE": "RSQUARE : ']'",
"PLUSEQ": "PLUSEQ: '+='",
"MINUSEQ": "MINUSEQ: '-='",
"ACCENT": "ACCENT: '`'",
"PYTHON_CODE": "PYTHON_CODE"
}
KEYWORDS = [
#English
'var',
'and',
'or',
'not',
'if',
'elseif',
'else',
'for',
'to',
'step',
'while',
'function',
'then',
'end',
'return',
'continue',
'break',
'do',
#Sinhala
'විචල්ය', # variable
'විචල්ය',
'සහ', # and
'හෝ', # or
'නොමැත', # not
'නොව', # not
'නැත', # not
'නොවේ', # not
'නොවන', # not
'ශ්රීතය', #function
'කාර්යය', # function
'නම්', #like-if
'නැත්නම්', #like-else
'නැතිනම්',#like-else
'මෙහි', # start of case
"එසේ_නැත්නම්", #like-elseif
"එසේ_නැතිනම්",#like-elseif
"එසේත්_නැත්නම්",#like-elseif
"එසේත්_නැතිනම්",#like-elseif
"අවසන්", #end
"දක්වා", # |
"පියවර",# දක්වා පියවර for i=0 to 10 step -2 then (it's like the step)
"තෙක්", # like-then but for (for-loop)
"සිට", #like to
"අතර",# while
"අතරතුර", # while
"නවත්වන්න", # break
"දෙන්න", #return
"දිගටම",
"කරන්න",
]
BuiltIns = {
"null":['ශුන්යයි'],
"false":['බොරු'],
"true":['සැබෑ'],
"math_pi":['ගණිතය_pi'],
"write":['ලියන්න'],
#"preturn": [''],
"input":['ආදානය'],
"int_input":['සංඛ්යා_ආදානය'],
"clear":['පැහැදිලිව'],
"is_num":['අංකයක්_ද'],
"is_str":['අක්ෂර_ද'],
"is_list":['ලැයිස්තුවක්_ද'],
"is_function":['ශ්රිතයක්_ද'],
"to_str": ["අක්ෂර_බවට_පරිවර්තනය_කරන්න"],
"to_num":["අංක_බවට_පරිවර්තනය_කරන්න"],
"type": ["වර්ගය"],
"append":['අගට_එකතු_කරන්න'],
"pop":['පොප්'],
"extend":['දිගු_කරන්න'],
"len":['දිග'],
"import":['ආනයනය_කරන්න'],
"select": ['ලැයිස්තුවෙන්_තෝරන්න']
}
#CHARACTERS = r'[\u0000-\uFFFFa-zA-Z0-9_]+'
#u200d & u200b are zero-width space