parser.py (6907:b05de761960e) | parser.py (6999:f226c098c393) |
---|---|
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 --- 16 unchanged lines hidden (view full) --- 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Nathan Binkert 28 29import os.path 30import re 31import sys 32 | 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 --- 16 unchanged lines hidden (view full) --- 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Nathan Binkert 28 29import os.path 30import re 31import sys 32 |
33from m5.util import code_formatter |
|
33from m5.util.grammar import Grammar, TokenError, ParseError 34 35import slicc.ast as ast 36import slicc.util as util 37from slicc.symbols import SymbolTable 38 39def read_slicc(sources): 40 if not isinstance(sources, (list,tuple)): --- 4 unchanged lines hidden (view full) --- 45 sm_file = sm_file.strip() 46 if not sm_file: 47 continue 48 if sm_file.startswith("#"): 49 continue 50 yield sm_file 51 52class SLICC(Grammar): | 34from m5.util.grammar import Grammar, TokenError, 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)): --- 4 unchanged lines hidden (view full) --- 46 sm_file = sm_file.strip() 47 if not sm_file: 48 continue 49 if sm_file.startswith("#"): 50 continue 51 yield sm_file 52 53class SLICC(Grammar): |
53 def __init__(self, **kwargs): | 54 def __init__(self, protocol, **kwargs): |
54 super(SLICC, self).__init__(**kwargs) 55 self.decl_list_vec = [] 56 self.current_file = None | 55 super(SLICC, self).__init__(**kwargs) 56 self.decl_list_vec = [] 57 self.current_file = None |
57 self.symtab = SymbolTable() | 58 self.protocol = protocol 59 self.symtab = SymbolTable(self) |
58 | 60 |
61 def codeFormatter(self, *args, **kwargs): 62 code = code_formatter(*args, **kwargs) 63 code['protocol'] = self.protocol 64 return code 65 |
|
59 def parse(self, filename): 60 self.current_file = filename 61 f = file(filename, 'r') 62 text = f.read() 63 try: 64 decl_list = super(SLICC, self).parse(text) 65 except (TokenError, ParseError), e: 66 sys.exit("%s: %s:%d" % (e, filename, e.token.lineno)) --- 624 unchanged lines hidden --- | 66 def parse(self, filename): 67 self.current_file = filename 68 f = file(filename, 'r') 69 text = f.read() 70 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)) --- 624 unchanged lines hidden --- |