예제 #1
0
 def p_pairs(self, p):
     '''
 pairs : pair
       | pairs COMMA pair
  pair : LBRA seqfof RBRA
 '''
     if len(p) == 2:
         # pair
         p[0] = p[1]
     elif len(p) == 4 and p[2] == ',':
         # pairs . pair
         p[0] = p[3]
     elif len(p) == 4 and p[1] == '[':
         # pair.
         q = p[2]
         if len(q) != 2 and len(q) != 3:
             raise SyntaxError("invalid length of list", self.lexer, p,
                               p.lineno(1), p.lexpos(1))
         if len(q) == 2:
             if not self.pisq(q[0]):
                 raise SyntaxError("quantified formula is expected",
                                   self.lexer, p, p.lineno(1), p.lexpos(1))
             if self.pisq(q[1]):
                 raise SyntaxError("quantifier-free formula is expected",
                                   self.lexer, p, p.lineno(1), p.lexpos(1))
             if self.pisex(q[1]):
                 raise SyntaxError("non-extended fof is expected",
                                   self.lexer, p, p.lineno(1), p.lexpos(1))
             p[0] = self.pdiff(q[1], q[0])
             if len(p[0][0]) > 0:
                 raise SyntaxError("invalid output formula (unknown var)",
                                   self.lexer, p, p.lineno(1), p.lexpos(1))
예제 #2
0
    def p_poly(self, p):
        '''
    poly : number
         | id
         | poly PLUS poly
         | poly MINUS poly
         | poly TIMES poly
         | poly DIVIDE poly
         | poly POWER rational
         | LPAREN poly RPAREN
         | MINUS poly %prec UMINUS
         | PLUS poly %prec UPLUS
         | ABS LPAREN poly RPAREN
    '''
        #    | AREA LPAREN listpoly COMMA freefml COMMA listvar RPAREN
        #    | AREA LPAREN freefml COMMA freefml COMMA listvar RPAREN
        #    | VOLUME LPAREN listpoly COMMA freefml COMMA listvar RPAREN
        #    | VOLUME LPAREN freefml COMMA freefml COMMA listvar RPAREN
        if p[1] == '(' or len(p) == 3:
            p[0] = p[2]
            if self.pisex(p[2]):
                self.psetex(p[0])
        elif len(p) == 4:
            # poly op poly
            p[0] = self.punion(p[1], p[3])
            if p[2] == '/':
                self.psetex(p[0])
            elif self.pisex(p[1]) or self.pisex(p[3]):
                self.psetex(p[0])

        elif len(p) == 5:
            # abs / ln
            p[0] = p[3]
            self.psetex(p[0])
        elif p[1] == 'area' or p[1] == 'volume':
            # area/volume
            self.psetex(p[0])
            if len(p[3].difference(p[7])) > 0:
                raise SyntaxError("not enough variable", self.lexer, p[1],
                                  p.lineno(1), p.lexpos(1))
            if len(p[7].difference(p[3])) > 0:
                raise SyntaxError("unknown variable", self.lexer, p[1],
                                  p.lineno(1), p.lexpos(1))
            if len(p[5].difference(p[3])) > 0:
                raise SyntaxError("unknown variable", self.lexer, p[1],
                                  p.lineno(1), p.lexpos(1))
            p[0] = p[7]
        else:
            p[0] = p[1]
예제 #3
0
    def p_fof(self, p):
        '''
    fof : NOT LPAREN fof RPAREN
        | AND LPAREN fofs RPAREN
        | OR LPAREN fofs RPAREN
        | REPL LPAREN fof COMMA fof RPAREN
        | IMPL LPAREN fof COMMA fof RPAREN
        | EQUIV LPAREN fof COMMA fof RPAREN
        | atom
        | ALL LPAREN listvar COMMA fof RPAREN
        | EX  LPAREN listvar COMMA fof RPAREN
        | LPAREN fof RPAREN
    '''
        if len(p) == 2:
            # atom
            p[0] = p[1]
        elif len(p) == 4:
            # ( fof )
            p[0] = p[2]
        elif len(p) == 5:
            # Not, And, Or
            p[0] = p[3]
        elif len(p) == 7:
            if p[1] == 'All' or p[1] == 'Ex':
                if len(p[3].difference(p[5])) > 0:
                    raise SyntaxError("unknown variable", self.lexer, p[3],
                                      p.lineno(1), p.lexpos(1))

                p[0] = p[5].difference(p[3])
            else:
                p[0] = p[3].union(p[5])
        else:
            print "hey", p[1]
예제 #4
0
 def p_pairs(self, p):
     '''
 pairs : pair
       | pairs COMMA pair
 pair : LBRA fof COMMA freefml RBRA
 '''
     if len(p) == 2:
         # pir
         p[0] = p[1]
     elif len(p) == 4:
         # pairs . pair
         p[0] = p[3]
     else:
         # pair
         if len(p[4].difference(p[2])) > 0:
             raise SyntaxError("invalid output formula", self.lexer, p[2],
                               p.lineno(1), p.lexpos(1))
예제 #5
0
 def p_atom(self, p):
     '''
 atom : TRUE
      | FALSE
      | poly EQ poly
      | poly NE poly
      | poly GT poly
      | poly GE poly
      | poly LT poly
      | poly LE poly
 '''
     if len(p) == 2:
         p[0] = self.pdef()
     elif len(p) == 4:
         # poly op poly
         p[0] = self.punion(p[1], p[3])
         if self.pisex(p[1]) or self.pisex(p[3]):
             raise SyntaxError("non-extended fof is expected", self.lexer,
                               p, p.lineno(1), p.lexpos(1))
     else:
         assert False
예제 #6
0
 def p_error(self, t):
     raise SyntaxError("unexpected token", self.lexer, t.value, t.lineno,
                       t.lexpos)