Beispiel #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)
Beispiel #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)
Beispiel #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)
 def __init__(self, expr):
     Statement.__init__(self, "WriteStatement")
     self._kids = [expr]
Beispiel #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]
 def __init__(self, v):
     Statement.__init__(self, "ReadStatement")
     self._kids.append(v)
Beispiel #7
0
 def visitBreakStmt(self, ctx: CParser.BreakStmtContext):
     return Statement.Break(ctx.start.line, ctx.start.column)
Beispiel #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)
Beispiel #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]
Beispiel #11
0
def statement_fn(s, l, t):
    return Statement(t[0])