source: proto/charsetcompiler/pablo_stmt.py @ 3968

Last change on this file since 3968 was 3947, checked in by cameron, 5 years ago

Rename bitwise-expr to pablo-expr;add advance expression, pablo-stmt

File size: 1.0 KB
Line 
1#
2#  Pablo Statements.
3#
4import ast
5
6class PabloStmt:
7   pass
8
9class Assign(PabloStmt):
10    def __init__(self, varname, expr):
11        self.varname = varname
12        self.expr = expr
13    def __str__(self): return 'Assign("' + self.varname + ', ' + self.expr.__str__() + '")'
14    def toAST(self): return ast.Assign([ast.Name(id=self.varname, ctx=ast.Store())], self.expr.toAST())
15
16class IfStmt(PabloStmt):
17    def __init__(self, predicate, stmts):
18        self.predicate = predicate
19        self.stmts = stmts
20    def __str__(self): return 'If(%s, %s)' % (self.predicate.__str__(), self.stmts.__str__())
21    def toAST(self): return ast.If(self.predicate.toAST(), [s.toAST() for s in self.stmts], [])
22
23class WhileLoop(PabloStmt):
24    def __init__(self, predicate, stmts):
25        self.predicate = predicate
26        self.stmts = stmts
27    def __str__(self): return 'While(%s, %s)' % (self.predicate.__str__(), self.stmts.__str__())
28    def toAST(self): return ast.While(self.predicate.toAST(), [s.toAST() for s in self.stmts], [])
29
30
Note: See TracBrowser for help on using the repository browser.