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)
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)
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]
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)
def visitBreakStmt(self, ctx: CParser.BreakStmtContext): return Statement.Break(ctx.start.line, ctx.start.column)
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)
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]
def statement_fn(s, l, t): return Statement(t[0])