コード例 #1
0
ファイル: SemanticAnalysis.py プロジェクト: vanzan/compilador
class SemanticAnalysis():

    def __init__(self):
        self.sa = ScopeAnalysis()
        self.labelNo = 0

    def IS_TYPE_KIND(self, k):
        return k == Kind.ARRAY_TYPE_.value or \
               k == Kind.STRUCT_TYPE_.value or \
               k == Kind.ALIAS_TYPE_.value or \
               k == Kind.SCALAR_TYPE_.value

    def newLabel(self):
        self.labelNo += 1
        return self.labelNo

    def semantics(self, rule, currentToken):
        _, name, _ = currentToken

        if rule == 10:  # B -> NB { LDV LS }
            self.sa.endBlock()

        elif rule == 28:  # IDD -> id
            IDD_.nont = Tnont.IDD.value
            IDD_.ID.name = name
            p = self.sa.search(name)
            if p is not None:
                print(ERR_REDECL)
            else:
                p = self.sa.define(name)
                p.eKind = Kind.NO_KIND_DEF_.value
                IDD_.obj = p

        elif rule == 29:  # IDU -> id
            IDU_.name = name
            p = self.sa.find(name)
            if p is None:
                print(ERR_NOT_DECL)
                p = self.sa.define(name)
                IDU_.obj = p

        elif rule == 30:  # NB -> epsilon
            self.sa.newBlock()

        elif rule == 6:  # T -> integer
            T_.T.type = copy.copy(pInteger)
            T_.nSize = 1

        elif rule == 7:  # T -> char
            T_.T.type = copy.copy(pChar)
            T_.nSize = 1

        elif rule == 8:  # T -> boolean
            T_.T.type = copy.copy(pBool)
            T_.nSize = 1

        elif rule == 9:  # T -> string
            T_.T.type = copy.copy(pString)
            T_.nSize = 1
コード例 #2
0
ファイル: SemanticAnalysis.py プロジェクト: vanzan/compilador
 def __init__(self):
     self.sa = ScopeAnalysis()
     self.labelNo = 0