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