Example #1
0
File: expr04.py Project: narupo/cap
    def factor(self):
        n = None

        if self.tkr.cur() == '(':
            self.tkr.get()
            n = self.expr()
            self.tkr.get()
        else:
            n = Node()
            n.val = int(self.tkr.get())
            n.type = 'number'

        return n
Example #2
0
File: expr04.py Project: narupo/cap
    def expr(self):
        r = None
        n = self.term()

        if self.tkr.cur() in ['+', '-']:
            r = Node()
            r.val = self.tkr.get()
            if r.val == '+':
                r.type = 'add'
            else:
                r.type = 'sub'
            r.rhs = n
            r.lhs = self.expr()
        else:
            r = n
        return r
Example #3
0
File: expr04.py Project: narupo/cap
    def term(self):
        r = None
        n = self.factor()

        if self.tkr.cur() in ['*', '/']:
            r = Node()
            r.val = self.tkr.get()
            if r.val == '*':
                r.type = 'mul'
            else:
                r.type = 'div'
            r.rhs = n
            r.lhs = self.term()
        else:
            r = n
        return r
Example #4
0
def p_logical_expr2(p):
    '''logical_expr : NOT expr
    '''
    p[0]=Node('NOT')
    p[0].val = p[2]