Example #1
0
 def visitReturnStmt(self, ctx: CParser.ReturnStmtContext):
     expression = None
     try:
         expression = self.visitExpression(ctx.expression())
     except:
         pass
     return Statement.Return(ctx.start.line, ctx.start.column, expression)
Example #2
0
 def visitSelectionStmt(self, ctx: CParser.SelectionStmtContext):
     expression = self.visitSimpleExpression(ctx.simpleExpression())
     body = self.visitStatement(ctx.statement(0))
     elseBody = None
     try:
         elseBody = self.visitStatement(ctx.statement(1))
     except:
         pass
     return Statement.If(ctx.start.line, ctx.start.column, expression, body,
                         elseBody)
Example #3
0
 def visitCompoundStmt(self, ctx: CParser.CompoundStmtContext):
     localDecls = []
     statements = []
     try:
         statements += self.visitStatementList(ctx.statementList())
     except:
         pass
     try:
         localDecls += self.visitLocalDeclarations(ctx.localDeclarations())
     except:
         pass
     return Statement.Compound(ctx.start.line, ctx.start.column, localDecls,
                               statements)
Example #4
0
 def __init__(self, expr):
     Statement.__init__(self, "WriteStatement")
     self._kids = [expr]
Example #5
0
 def __init__(self, expr, thenPart, elsePart):
     Statement.__init__(self, "IfStatement")
     # _kids[0] = expr
     # _kids[1] = thenPart
     # _kids[2] = elsePart
     self._kids = [expr, thenPart, elsePart]
Example #6
0
 def __init__(self, v):
     Statement.__init__(self, "ReadStatement")
     self._kids.append(v)
Example #7
0
 def visitBreakStmt(self, ctx: CParser.BreakStmtContext):
     return Statement.Break(ctx.start.line, ctx.start.column)
Example #8
0
 def visitIterationStmt(self, ctx: CParser.IterationStmtContext):
     expression = self.visitSimpleExpression(ctx.simpleExpression())
     body = self.visitStatement(ctx.statement())
     return Statement.While(ctx.start.line, ctx.start.column, expression,
                            body)
Example #9
0
 def visitExpressionStmt(self, ctx: CParser.ExpressionStmtContext):
     expression = self.visitExpression(ctx.expression())
     return Statement.ExpressionStmt(ctx.start.line, ctx.start.column,
                                     expression)
 def __init__(self, v, expr):
     Statement.__init__(self, "AssignmentStatement")
     self._kids = [v, expr]
Example #11
0
def statement_fn(s, l, t):
    return Statement(t[0])