Ejemplo n.º 1
0
 def p_binary_expression(self, p):
     ''' binary_expression : inner_expression AND inner_expression
                           | inner_expression OR inner_expression
                           | inner_expression EQ inner_expression
                           | inner_expression NE inner_expression
                           | inner_expression GE inner_expression
                           | inner_expression LE inner_expression
                           | inner_expression GT inner_expression
                           | inner_expression LT inner_expression
                           | inner_expression PLUS inner_expression
                           | inner_expression MINUS inner_expression
                           | inner_expression TIMES inner_expression
                           | inner_expression DIV inner_expression
                           | inner_expression MOD inner_expression '''
     typeBinaryOp = None
     if p[2] == '&&': typeBinaryOp = "AND"
     elif p[2] == '||': typeBinaryOp = "OR"
     elif p[2] == '==': typeBinaryOp = "EQ"
     elif p[2] == '!=': typeBinaryOp = "NE"
     elif p[2] == '>=': typeBinaryOp = "GE"
     elif p[2] == '<=': typeBinaryOp = "LE"
     elif p[2] == '>': typeBinaryOp = "GT"
     elif p[2] == '<': typeBinaryOp = "LT"
     elif p[2] == '+': typeBinaryOp = "ADD"
     elif p[2] == '-': typeBinaryOp = "SUB"
     elif p[2] == '*': typeBinaryOp = "MUL"
     elif p[2] == '/': typeBinaryOp = "DIV"
     elif p[2] == '%': typeBinaryOp = "MOD"
     subExpr = ApplyAtomicExpression(
         children=[AtomicExpression("ExprVar", typeBinaryOp), p[1]])
     p[0] = ApplyAtomicExpression(children=[subExpr, p[3]])
Ejemplo n.º 2
0
 def p_unary_expression(self, p):
     ''' unary_expression : NOT inner_expression
                          | MINUS inner_expression %prec UMINUS '''
     typeUnaryOp = None
     if p[1] == '!': typeUnaryOp = "NOT"
     elif p[1] == '-': typeUnaryOp = "UMINUS"
     p[0] = ApplyAtomicExpression(
         children=[AtomicExpression("ExprVar", typeUnaryOp), p[2]])
Ejemplo n.º 3
0
 def p_string_expression(self, p):
     ''' string_expression : STRING
     '''
     if p[1]:
         index_char = 1
         next_char = p[1][0]
         if next_char == "\\":
             index_char = 2
             next_char = p[1][0:index_char]
         sub = ApplyAtomicExpression(children=[
             AtomicExpression("ExprConstructor", "Cons"),
             AtomicExpression("ExprChar", self.get_char_ord(next_char))
         ])
         p[1] = p[1][index_char:]
         p[0] = ApplyAtomicExpression(
             children=[sub, self.p_string_expression(p)])
     else:
         p[0] = AtomicExpression("ExprConstructor", "Nil")
     return p[0]
Ejemplo n.º 4
0
 def p_upper_id_expression(self, p):
     ''' upper_id_expression : UPPERID
     '''
     p[0] = AtomicExpression("ExprConstructor", p[1])
Ejemplo n.º 5
0
 def p_lower_id_expression(self, p):
     ''' lower_id_expression : LOWERID
     '''
     p[0] = AtomicExpression("ExprVar", p[1])
Ejemplo n.º 6
0
 def p_number_expression(self, p):
     ''' number_expression : NUMBER
     '''
     p[0] = AtomicExpression("ExprNumber", str(p[1]))
Ejemplo n.º 7
0
    def p_char_expression(self, p):
        ''' char_expression : CHAR
        '''
        p[1] = self.get_char_ord(p[1])

        p[0] = AtomicExpression("ExprChar", p[1])