def __init__(self, expression, statement, alternative_statement,
              symbol_table):
     Statement.__init__(self)
     self.expression = expression
     self.statement = statement
     self.alternativeStatement = alternative_statement
     self.symbol_table = symbol_table
示例#2
0
    def __init__(self, expression):
        Statement.__init__(self)
        self.expression = expression

        if(type(self.expression) != type(VoidType())):
            self.basetype = self.expression.basetype
        else:
            self.basetype = self.expression
示例#3
0
 def __init__(self, initExpression, checkExpression, updateExpression,
              statement, sym):
     Statement.__init__(self)
     self.initExpression = initExpression
     self.checkExpression = checkExpression
     self.updateExpression = updateExpression
     self.statement = statement
     self.sym = sym
示例#4
0
 def __init__(self, statements):
     Statement.__init__(self)
     self.statements = statements
示例#5
0
    def buildStatement(self, tree):
        """Build Statement"""
        if (tree.getChildCount() == 0):
            raise RuntimeError("Invalid statement: '" + tree.getText() + "'")
        elif (tree.getChildCount() == 1):
            # SEMICOLON
            token = tree.getChild(0).getPayload()
            if (isinstance(token, Token) and token.type == CLexer.SEMICOLON):
                return Statement()

            if (isinstance(token, Token) and token.type == CLexer.RETURN):
                return ReturnStatement(VoidType())

            # Otherwise something went wrong
            raise RuntimeError("Invalid statement: '" + tree.getText() + "'")
        else:
            # BREAK SEMICOLON
            # CONTINUE SEMICOLON
            # INCLUDE (CPATH|STRING)
            # expression SEMICOLON
            # LBRACE statement* RBRACE
            # WHILE LPAREN expression RPAREN statement
            # IF LPAREN expression RPAREN statement (ELSE statement)?
            # FOR LPAREN expression? SEMICOLON expression? SEMICOLON expression? RPAREN statement
            # TYPEDEF type IDENTIFIER (LSQUAREBRACKET NUM RSQUAREBRACKET)* SEMICOLON
            # type IDENTIFIER LPAREN (VOID|type IDENTIFIER? (COMMA type IDENTIFIER?)*)? RPAREN (SEMICOLON|LBRACE statement* RBRACE)
            token = tree.getChild(0).getPayload()
            if (isinstance(token, Token)):
                if (token.type == CLexer.BREAK):
                    if (isinstance(tree.getChild(1).getPayload(), Token)
                            and tree.getChild(1).getPayload().type
                            == CLexer.SEMICOLON):
                        return BreakStatement()
                    else:
                        raise RuntimeError("Invalid statement: '" +
                                           tree.getText() + "'")
                elif (token.type == CLexer.CONTINUE):
                    if (isinstance(tree.getChild(1).getPayload(), Token)
                            and tree.getChild(1).getPayload().type
                            == CLexer.SEMICOLON):
                        return ContinueStatement()
                    else:
                        raise RuntimeError("Invalid statement: '" +
                                           tree.getText() + "'")
                elif (token.type == CLexer.INCLUDE):
                    return self.buildIncludeStatement(tree)
                elif (token.type == CLexer.RETURN):
                    return self.buildReturnStatement(tree)
                elif (token.type == CLexer.LBRACE):
                    return self.buildCompoundStatement(tree)
                elif (token.type == CLexer.WHILE):
                    return self.buildWhileStatement(tree)
                elif (token.type == CLexer.IF):
                    return self.buildIfelseStatement(tree)
                elif (token.type == CLexer.FOR):
                    return self.buildForStatement(tree)
                elif (token.type == CLexer.TYPEDEF):
                    return self.buildTypeDefStatement(tree)
                else:
                    raise RuntimeError("Invalid statement: '" +
                                       tree.getText() + "'")
            else:
                token = tree.getChild(1).getPayload()
                if (not isinstance(token, Token)):
                    raise RuntimeError("Invalid statement: '" +
                                       tree.getText() + "'")

                if (token.type == CLexer.SEMICOLON):
                    return self.buildExpression(tree.getChild(0))
                elif (token.type == CLexer.IDENTIFIER):
                    return self.buildFunctionStatement(tree)
                else:
                    raise RuntimeError("Invalid statement: '" +
                                       tree.getText() + "'")
示例#6
0
 def __init__(self, expression, statement, symbol_table):
     Statement.__init__(self)
     self.expression = expression
     self.statement = statement
     self.symbol_table = symbol_table
 def __init__(self, expression):
     Statement.__init__(self)
     self.identifier = expression
     self.basetype = expression.basetype
示例#8
0
 def __init__(self, symbol_table):
     Statement.__init__(self)
     self.symbol_table = symbol_table
示例#9
0
 def __init__(self):
     Statement.__init__(self)
示例#10
0
 def __init__(self, expression, statement, sym):
     Statement.__init__(self)
     self.expression = expression
     self.statement = statement
     self.sym = sym
 def __init__(self, expression, statement, sym):
     Statement.__init__(self)
     self.expression = expression
     self.statement = statement
     self.alternativeStatement = None
     self.sym = sym
示例#12
0
 def __init__(self, expression, write_type):
     Statement.__init__(self)
     self.expression = expression
     self.basetype = expression.basetype
     self.write_type = write_type
示例#13
0
 def __init__(self, basetype):
     Statement.__init__(self)
     self.basetype = basetype
示例#14
0
 def __init__(self, basetype, identifier):
     Statement.__init__(self)
     self.basetype = basetype
     self.identifier = identifier
示例#15
0
 def __init__(self, function, statements, implemented):
     """Create a function with a function(Function), statements([Statement]) and implemented(bool)"""
     Statement.__init__(self)
     self.function = function
     self.statements = statements
     self.implemented = implemented