parser.py (8156:9a6a02a235f1) parser.py (8452:3f2c329e9046)
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 17 unchanged lines hidden (view full) ---

26#
27# Authors: Nathan Binkert
28
29import os.path
30import re
31import sys
32
33from m5.util import code_formatter
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 17 unchanged lines hidden (view full) ---

26#
27# Authors: Nathan Binkert
28
29import os.path
30import re
31import sys
32
33from m5.util import code_formatter
34from m5.util.grammar import Grammar, TokenError, ParseError
34from m5.util.grammar import Grammar, ParseError
35
36import slicc.ast as ast
37import slicc.util as util
38from slicc.symbols import SymbolTable
39
40def read_slicc(sources):
41 if not isinstance(sources, (list,tuple)):
42 sources = [ sources ]

--- 4 unchanged lines hidden (view full) ---

47 if not sm_file:
48 continue
49 if sm_file.startswith("#"):
50 continue
51 yield sm_file
52
53class SLICC(Grammar):
54 def __init__(self, protocol, **kwargs):
35
36import slicc.ast as ast
37import slicc.util as util
38from slicc.symbols import SymbolTable
39
40def read_slicc(sources):
41 if not isinstance(sources, (list,tuple)):
42 sources = [ sources ]

--- 4 unchanged lines hidden (view full) ---

47 if not sm_file:
48 continue
49 if sm_file.startswith("#"):
50 continue
51 yield sm_file
52
53class SLICC(Grammar):
54 def __init__(self, protocol, **kwargs):
55 super(SLICC, self).__init__(**kwargs)
56 self.decl_list_vec = []
55 self.decl_list_vec = []
57 self.current_file = None
58 self.protocol = protocol
59 self.symtab = SymbolTable(self)
60
61 def codeFormatter(self, *args, **kwargs):
62 code = code_formatter(*args, **kwargs)
63 code['protocol'] = self.protocol
64 return code
65
66 def parse(self, filename):
56 self.protocol = protocol
57 self.symtab = SymbolTable(self)
58
59 def codeFormatter(self, *args, **kwargs):
60 code = code_formatter(*args, **kwargs)
61 code['protocol'] = self.protocol
62 return code
63
64 def parse(self, filename):
67 self.current_file = filename
68 f = file(filename, 'r')
69 text = f.read()
70 try:
65 try:
71 decl_list = super(SLICC, self).parse(text)
72 except (TokenError, ParseError), e:
73 sys.exit("%s: %s:%d" % (e, filename, e.token.lineno))
66 decl_list = self.parse_file(filename)
67 except ParseError, e:
68 sys.exit(str(e))
74 self.decl_list_vec.append(decl_list)
69 self.decl_list_vec.append(decl_list)
75 self.current_file = None
76
77 def _load(self, *filenames):
78 filenames = list(filenames)
79 while filenames:
80 f = filenames.pop(0)
81 if isinstance(f, (list, tuple)):
82 filenames[0:0] = list(f)
83 continue

--- 149 unchanged lines hidden (view full) ---

233 t.type = self.reserved.get(t.value, 'IDENT')
234 return t
235
236 def t_FLOATNUMBER(self, t):
237 '[0-9]+[.][0-9]+'
238 try:
239 t.value = float(t.value)
240 except ValueError:
70
71 def _load(self, *filenames):
72 filenames = list(filenames)
73 while filenames:
74 f = filenames.pop(0)
75 if isinstance(f, (list, tuple)):
76 filenames[0:0] = list(f)
77 continue

--- 149 unchanged lines hidden (view full) ---

227 t.type = self.reserved.get(t.value, 'IDENT')
228 return t
229
230 def t_FLOATNUMBER(self, t):
231 '[0-9]+[.][0-9]+'
232 try:
233 t.value = float(t.value)
234 except ValueError:
241 raise TokenError("Illegal float", t)
235 raise ParseError("Illegal float", t)
242 return t
243
244 def t_NUMBER(self, t):
245 r'[0-9]+'
246 try:
247 t.value = int(t.value)
248 except ValueError:
236 return t
237
238 def t_NUMBER(self, t):
239 r'[0-9]+'
240 try:
241 t.value = int(t.value)
242 except ValueError:
249 raise TokenError("Illegal number", t)
243 raise ParseError("Illegal number", t)
250 return t
251
252 def t_STRING1(self, t):
253 r'\"[^"\n]*\"'
254 t.type = 'STRING'
255 t.value = t.value[1:-1]
256 return t
257

--- 483 unchanged lines hidden ---
244 return t
245
246 def t_STRING1(self, t):
247 r'\"[^"\n]*\"'
248 t.type = 'STRING'
249 t.value = t.value[1:-1]
250 return t
251

--- 483 unchanged lines hidden ---