compilation_course_compiler/items.py

41 lines
1.4 KiB
Python

# Item return type:
# { lines, result, is_float }
# - result: end result variable name(or the value itself in case of number literal, also if applicable)
# - is_float: true if the results are of type float(assuming there are results)
# idlist return type shall be a list of all ids and lines( { id, line } )
class Expression():
def __init__(self, result: str, is_float: bool):
self.result = result
self.is_float = is_float
# Statement type:
# - breaks: a list of all lines on which a brake occured, to be handled by relevant rules
class Statement():
def __init__(self, breaks: list):
self.breaks = breaks
class Id():
def __init__(self, id: str, line: int):
self.id = id
self.line = line
# Case type:
# - num: NUM token lexeme as string
# - line: line at which the comparison check is to be made
# - end: next line after the end of the case block
# - breaks: the list of breaks from the case stmtlist
class Case():
def __init__(self, num: str, line: int, end: int, breaks: list):
self.num = num
self.line = line
self.end = end
self.breaks = breaks
# Symbol table type:
# { is_float, line }
# - is_float: true if the type is float(we have only 2 types, it makes it easier to check)
# - line: line defined at, for error handling
class Symbol():
def __init__(self, is_float, line):
self.is_float = is_float
self.line = line