-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalTypes.py
More file actions
50 lines (38 loc) · 1.07 KB
/
globalTypes.py
File metadata and controls
50 lines (38 loc) · 1.07 KB
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
"""
Tokens:
Palabras RESERVADAS:
else, if, int, return, void, while, if-else
posiblemente: input(), output()
SIMBOLOS:
+ - * / < <= > >= == != = ; , ( ) [ ] { } /* */
ID:
letra letra*
letra = a|..|z|A|..|Z
NUM:
digito digito*
digito = 0|..|9
espacios en blanco = ' ', '\n', '\t'
COMENTARIO (en cualquier lugar donde pueda estar un espacio en blanco):
/* ... */ (puede ocupar más de una linea)
Tokens examples:
(ID, “contador”)
(EQUAL, “=”)
(PLUS, “+”)
(ERROR, “”)
"""
from enum import Enum, auto
import string
class TokenType(Enum):
UNDECLARED = [" ", "\n", "\t"]
COMMENT = "/*"
ID = [string.ascii_letters, "_"]
RESERVED = ["else", "if", "int", "return", "void", "while", "if-else"]
NUM = "0123456789"
OPS = ["+", "-", "*", "/"]
COMP = ["<", "<=", ">", ">=", "==", "!="]
PUN_SEP = [";", ",", "(", ")", "{", "}", "[", "]"]
ASG = ["="]
ENDFILE = "$"
ERROR = ""
def __str__(self):
return self.name