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 |
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): |
54 def __init__(self, protocol, **kwargs): |
55 super(SLICC, self).__init__(**kwargs) 56 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): 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 --- |