-
Notifications
You must be signed in to change notification settings - Fork 0
/
uCType.py
71 lines (64 loc) · 1.9 KB
/
uCType.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
'''
Second Project: Semantic Analysis of AST for the uC language.
Subject:
MC921 - Construction of Compilers
Authors:
Victor Ferreira Ferrari - RA 187890
Vinicius Couto Espindola - RA 188115
University of Campinas - UNICAMP - 2020
Last Modified: 05/05/2020.
'''
class uCType(object):
'''
Class that represents a type in the uC language. Types
are declared as singleton instances of this type.
'''
def __init__(self, name, bin_ops=set(), un_ops=set(), rel_ops=set(), assign_ops=set(), cast_types=set()):
self.name = name
self.bin_ops = bin_ops
self.un_ops = un_ops
self.rel_ops = rel_ops
self.assign_ops = assign_ops
self.cast_types = cast_types
def __str__(self):
return f'type({self.name})'
def __repr__(self):
return self.__str__()
int_type = uCType("int",
bin_ops = {'+', '-', '*', '/', '%'},
un_ops = {'+', '-', '--', '++', 'p--', 'p++', '*', '&'},
rel_ops = {'<=', '<', '==', '!=', '>', '>='},
assign_ops = {'+=', '-=', '*=', '/=', '%='},
cast_types = {'int', 'float'}
)
float_type = uCType("float",
bin_ops = {'+', '-', '*', '/', '%'},
un_ops = {'+', '-', '&', '*'},
rel_ops = {'<=', '<', '==', '!=', '>', '>='},
assign_ops = {'+=', '-=', '*=', '/=', '%='},
cast_types = {'int', 'float'}
)
char_type = uCType("char",
un_ops = {'*', '&'},
rel_ops = {'==', '!='},
cast_types = {'char'}
)
string_type = uCType("string",
bin_ops = {'+'},
rel_ops = {'==', '!='}
)
boolean_type = uCType("bool",
un_ops = {'!', '*', '&'},
rel_ops = {'&&', '||', '==', '!='}
)
void_type = uCType("void",
un_ops = {'*', '&'}
)
ptr_type = uCType('ptr',
un_ops = {'*', '&', '++', 'p++', '--', 'p--'},
rel_ops = {'==', '!='}
)
arr_type = uCType('array',
un_ops = {'*', '&', '++', 'p++', '--', 'p--'},
rel_ops = {'==', '!='}
)