# Path: pydsl/exceptions.py
# class ParseError(Exception):
# 
#     def __init__(self, msg, offset):
#         self.msg = msg
#         self.offset = offset
# 
#     def __repr__(self):
#         return "ParseError(%r, %r)" % (self.msg, self.offset)
# 
#     def __str__(self):
#         return "%s at position %s" % (self.msg, self.offset + 1)


from pydsl.exceptions import ParseError
    '''expression : expression PLUS expression
                  | expression MINUS expression
                  | expression TIMES expression
                  | expression DIVIDE expression'''
    if t[2] == '+'  : t[0] = t[1] + t[3]
    elif t[2] == '-': t[0] = t[1] - t[3]
    elif t[2] == '*': t[0] = t[1] * t[3]
    elif t[2] == '/': t[0] = t[1] / t[3]

def p_expression_uminus(t):
    'expression : MINUS expression %prec UMINUS'
    t[0] = -t[2]

def p_expression_group(t):
    'expression : LPAREN expression RPAREN'
    t[0] = t[2]

def p_expression_number(t):
    'expression : NUMBER'
    t[0] = t[1]

def p_expression_name(t):
    'expression : NAME'
    try:
        t[0] = names[t[1]]
    except LookupError:
        raise ParseError("Undefined name",0)
        t[0] = 0

def p_error(t):

# Path: pydsl/exceptions.py
# class ParseError(Exception):
# 
#     def __init__(self, msg, offset):
#         self.msg = msg
#         self.offset = offset
# 
#     def __repr__(self):
#         return "ParseError(%r, %r)" % (self.msg, self.offset)
# 
#     def __str__(self):
#         return "%s at position %s" % (self.msg, self.offset + 1)


# Path: pydsl/contrib/grammar/calc_ply.py
from pydsl.exceptions import ParseError

    '''expression : expression PLUS expression
                  | expression MINUS expression
                  | expression TIMES expression
                  | expression DIVIDE expression'''
    if t[2] == '+'  : t[0] = t[1] + t[3]
    elif t[2] == '-': t[0] = t[1] - t[3]
    elif t[2] == '*': t[0] = t[1] * t[3]
    elif t[2] == '/': t[0] = t[1] / t[3]

def p_expression_uminus(t):
    'expression : MINUS expression %prec UMINUS'
    t[0] = -t[2]

def p_expression_group(t):
    'expression : LPAREN expression RPAREN'
    t[0] = t[2]

def p_expression_number(t):
    'expression : NUMBER'
    t[0] = t[1]

def p_expression_name(t):
    'expression : NAME'
    try:
        t[0] = names[t[1]]
    except LookupError:
        raise ParseError("Undefined name",0)
        t[0] = 0

def p_error(t):

    raise ParseError("Syntax error at", t.value)