summaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/slicc/parser/parser.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/mem/slicc/parser/parser.py b/src/mem/slicc/parser/parser.py
index 95e8d25e5..7fecfd273 100644
--- a/src/mem/slicc/parser/parser.py
+++ b/src/mem/slicc/parser/parser.py
@@ -100,8 +100,15 @@ t_SEMICOLON = r';'
t_ASSIGN = r':='
t_DOT = r'\.'
-class TokenError(Exception): pass
-class ParseError(Exception): pass
+class TokenError(Exception):
+ def __init__(self, msg, t):
+ super(TokenError, self).__init__(msg)
+ self.token = t
+
+class ParseError(Exception):
+ def __init__(self, msg, t):
+ super(ParseError, self).__init__(msg)
+ self.token = t
def t_error(t):
raise TokenError("Illegal character", t)
@@ -157,7 +164,7 @@ def p_file(p):
p[0] = [ x for x in p[1] if x is not None ]
def p_error(t):
- raise ParseError(t)
+ raise ParseError("Syntax error", t)
def p_empty(p):
"empty :"
@@ -533,16 +540,8 @@ def scan(filenames):
try:
print "parsing ",filename
results = yacc.parse(file(filename, 'r').read())
- except (ParseError,TokenError), e:
- print "File ",filename," ",e
- raise e
- #except ParseError, e:
- # print "File ",filename," "e
- # raise e, tuple([filename] + [ i for i in e ])
-
- #except ParseError, e:
- # print e
-
+ except (TokenError, ParseError), e:
+ sys.exit("%s: %s:%d" % (e, filename, e.token.lineno))
for result in results:
result.add(hh, cc)