diff --git a/bot.py b/bot.py index 063d3dd..1a5a359 100755 --- a/bot.py +++ b/bot.py @@ -41,7 +41,7 @@ try: except Exception, e: print 'ERROR: malformed config file', Exception, e sys.exit() - + bot.persist_dir = os.path.abspath('persist') if not os.path.exists(bot.persist_dir): os.mkdir(bot.persist_dir) diff --git a/core/main.py b/core/main.py index 52a741b..9de5139 100644 --- a/core/main.py +++ b/core/main.py @@ -17,7 +17,7 @@ class Input(dict): conn.msg(chan, msg) def reply(msg): - if chan == nick: # PMs don't need prefixes + if chan == nick: # PMs don't need prefixes conn.msg(chan, msg) else: conn.msg(chan, nick + ': ' + msg) @@ -68,7 +68,7 @@ def do_sieve(sieve, bot, input, func, type, args): traceback.print_exc() return None - + class Handler(object): '''Runs plugins in their own threads (ensures order)''' def __init__(self, func): @@ -106,12 +106,12 @@ def dispatch(input, kind, func, args): input = do_sieve(sieve, bot, input, func, kind, args) if input == None: return - + if func._thread: bot.threads[func].put(input) else: thread.start_new_thread(run, (func, input)) - + def main(conn, out): inp = Input(conn, *out) @@ -120,14 +120,13 @@ def main(conn, out): for func, args in bot.events[inp.command] + bot.events['*']: dispatch(Input(conn, *out), "event", func, args) - if inp.command == 'PRIVMSG': # COMMANDS - if inp.chan == inp.nick: # private message, no command prefix + if inp.chan == inp.nick: # private message, no command prefix prefix = r'^(?:[.!]?|' else: prefix = r'^(?:[.!]|' - + command_re = prefix + inp.conn.nick command_re += r'[:,]*\s+)(\w+)(?:$|\s+)(.*)' @@ -139,10 +138,10 @@ def main(conn, out): input = Input(conn, *out) input.inp_unstripped = m.group(2) input.inp = m.group(2).strip() - + func, args = bot.commands[command] dispatch(input, "command", func, args) - + # REGEXES for func, args in bot.plugs['regex']: m = args['re'].search(inp.lastparam) diff --git a/core/reload.py b/core/reload.py index cfc9831..f952fc4 100644 --- a/core/reload.py +++ b/core/reload.py @@ -28,11 +28,9 @@ def format_plug(plug, kind='', lpad=0, width=40): if kind == 'regex': out += ' ' * (50 - len(out)) + plug[1]['regex'] - return out - def reload(init=False): changed = False @@ -41,12 +39,12 @@ def reload(init=False): bot.threads = {} core_fileset = set(glob.glob(os.path.join("core", "*.py"))) - + for filename in core_fileset: mtime = os.stat(filename).st_mtime if mtime != mtimes.get(filename): mtimes[filename] = mtime - + changed = True try: @@ -82,7 +80,7 @@ def reload(init=False): mtime = os.stat(filename).st_mtime if mtime != mtimes.get(filename): mtimes[filename] = mtime - + changed = True try: @@ -95,7 +93,7 @@ def reload(init=False): # remove plugins already loaded from this filename for name, data in bot.plugs.iteritems(): - bot.plugs[name] = [x for x in data + bot.plugs[name] = [x for x in data if x[0]._filename != filename] for func, handler in list(bot.threads.iteritems()): @@ -107,7 +105,7 @@ def reload(init=False): if hasattr(obj, '_hook'): # check for magic if obj._thread: bot.threads[obj] = Handler(obj) - + for type, data in obj._hook: bot.plugs[type] += [data] @@ -141,7 +139,7 @@ def reload(init=False): if bot.commands: # hack to make commands with multiple aliases # print nicely - + print ' command:' commands = collections.defaultdict(list) @@ -149,11 +147,11 @@ def reload(init=False): commands[make_signature(func)].append(name) for sig, names in sorted(commands.iteritems()): - names.sort(key=lambda x: (-len(x), x)) # long names first + names.sort(key=lambda x: (-len(x), x)) # long names first out = ' ' * 6 + '%s:%s:%s' % sig out += ' ' * (50 - len(out)) + ', '.join(names) print out - + for kind, plugs in sorted(bot.plugs.iteritems()): if kind == 'command': continue diff --git a/plugins/drama.py b/plugins/drama.py index ff7711b..463e9d8 100755 --- a/plugins/drama.py +++ b/plugins/drama.py @@ -10,7 +10,7 @@ from util import hook api_url = "http://encyclopediadramatica.com/api.php?action=opensearch&search=" ed_url = "http://encyclopediadramatica.com/" -ua_header = ('User-Agent','Skybot/1.0 http://bitbucket.org/Scaevolus/skybot/') +ua_header = ('User-Agent', 'Skybot/1.0 http://bitbucket.org/Scaevolus/skybot/') @hook.command('ed') @@ -20,7 +20,7 @@ def drama(inp): '''article on ''' if not inp: return drama.__doc__ - + q = api_url + (urllib2.quote(inp, safe='')) request = urllib2.Request(q) request.add_header(*ua_header) @@ -28,12 +28,12 @@ def drama(inp): if not j[1]: return 'no results found' article_name = j[1][0].replace(' ', '_') - + url = ed_url + (urllib2.quote(article_name)) request = urllib2.Request(url) request.add_header(*ua_header) page = html.fromstring(urllib2.build_opener().open(request).read()) - + for p in page.xpath('//div[@id="bodyContent"]/p'): if p.text_content(): summary = ' '.join(p.text_content().splitlines()) diff --git a/plugins/goonsay.py b/plugins/goonsay.py index 8df5ac3..c25e574 100644 --- a/plugins/goonsay.py +++ b/plugins/goonsay.py @@ -11,11 +11,12 @@ from util import hook # say('(--[. ]-[ .] /') # say('(_______o__)') + @hook.command @hook.command('gs') def goonsay(inp): - ".gs/.goonsay -- Get's the goonsay.com result for or " - "add a new :goonsay: to the database. If no arg it will get a random result." + ".gs/.goonsay -- Get's the goonsay.com result for " + " or add a new :goonsay: to the database. With no args, random result." url = "http://goonsay.com/api/goonsays" @@ -44,7 +45,8 @@ def goonsay(inp): if len(inp): try: - req = urllib2.Request('%s/%d/' % (url, int(inp)), None, req_headers) + req = urllib2.Request('%s/%d/' % (url, int(inp)), None, + req_headers) j = json.loads(urllib2.urlopen(req).read()) except urllib2.HTTPError, e: if e.code == 410 or e.code == 404: diff --git a/plugins/mem.py b/plugins/mem.py index 7f0de87..e088139 100644 --- a/plugins/mem.py +++ b/plugins/mem.py @@ -14,7 +14,7 @@ def mem(inp): status = dict(line_pairs) keys = 'VmSize VmLib VmData VmExe VmRSS VmStk'.split() return ', '.join(key + ':' + status[key] for key in keys) - + elif os.name == 'nt': cmd = "tasklist /FI \"PID eq %s\" /FO CSV /NH" % os.getpid() out = os.popen(cmd).read() diff --git a/plugins/mtg.py b/plugins/mtg.py index 448fa9b..85d56c0 100644 --- a/plugins/mtg.py +++ b/plugins/mtg.py @@ -28,7 +28,6 @@ def mtg(inp): text = re.sub(r'\(.*?\)', '', text) # strip parenthetical explanations text = re.sub(r'\.(\S)', r'. \1', text) # fix spacing - printings = card.find('td/small').text_content() printings = re.search(r'Editions:(.*)Languages:', printings).group(1) printings = re.findall(r'\s*(.+?(?: \([^)]+\))*) \((.*?)\)', diff --git a/plugins/pycparser/cdecl.py b/plugins/pycparser/cdecl.py index c0dc5b3..77ef479 100644 --- a/plugins/pycparser/cdecl.py +++ b/plugins/pycparser/cdecl.py @@ -1,98 +1,98 @@ -#----------------------------------------------------------------- -# pycparser: cdecl.py -# -# Example of the CDECL tool using pycparser. CDECL "explains" -# C type declarations in plain English. -# -# The AST generated by pycparser from the given declaration is -# traversed recursively to build the explanation. -# Note that the declaration must be a valid external declaration -# in C. All the types used in it must be defined with typedef, -# or parsing will fail. The definition can be arbitrary, it isn't -# really used - by pycparser must know which tokens are types. -# -# For example: -# -# 'typedef int Node; const Node* (*ar)[10];' -# => -# ar is a pointer to array[10] of pointer to const Node -# -# Copyright (C) 2008, Eli Bendersky -# License: LGPL -#----------------------------------------------------------------- -import sys - -from pycparser import c_parser, c_ast - - -def explain_c_declaration(c_decl): - """ Parses the declaration in c_decl and returns a text - explanation as a string. - - The last external node of the string is used, to allow - earlier typedefs for used types. - """ - parser = c_parser.CParser() - - node = parser.parse(c_decl, filename='') - - if ( not isinstance(node, c_ast.FileAST) or - not isinstance(node.ext[-1], c_ast.Decl)): - return "Last external node is invalid type" - - return _explain_decl_node(node.ext[-1]) - - -def _explain_decl_node(decl_node): - """ Receives a c_ast.Decl note and returns its explanation in - English. - """ - #~ print decl_node.show() - storage = ' '.join(decl_node.storage) + ' ' if decl_node.storage else '' - - return (decl_node.name + - " is a " + - storage + - _explain_type(decl_node.type)) - - -def _explain_type(decl): - """ Recursively explains a type decl node - """ - typ = type(decl) - - if typ == c_ast.TypeDecl: - quals = ' '.join(decl.quals) + ' ' if decl.quals else '' - return quals + _explain_type(decl.type) - elif typ == c_ast.Typename or typ == c_ast.Decl: - return _explain_type(decl.type) - elif typ == c_ast.IdentifierType: - return ' '.join(decl.names) - elif typ == c_ast.PtrDecl: - quals = ' '.join(decl.quals) + ' ' if decl.quals else '' - return quals + 'pointer to ' + _explain_type(decl.type) - elif typ == c_ast.ArrayDecl: - arr = 'array' - if decl.dim: arr += '[%s]' % decl.dim.value - - return arr + " of " + _explain_type(decl.type) - - elif typ == c_ast.FuncDecl: - if decl.args: - params = [_explain_type(param) for param in decl.args.params] - args = ', '.join(params) - else: - args = '' - - return ('function(%s) returning ' % (args) + - _explain_type(decl.type)) - - -if __name__ == "__main__": - if len(sys.argv) > 1: - c_decl = sys.argv[1] - else: - c_decl = "char *(*(**foo[][8])())[];" - - print "Explaining the declaration:", c_decl - print "\n", explain_c_declaration(c_decl) +#----------------------------------------------------------------- +# pycparser: cdecl.py +# +# Example of the CDECL tool using pycparser. CDECL "explains" +# C type declarations in plain English. +# +# The AST generated by pycparser from the given declaration is +# traversed recursively to build the explanation. +# Note that the declaration must be a valid external declaration +# in C. All the types used in it must be defined with typedef, +# or parsing will fail. The definition can be arbitrary, it isn't +# really used - by pycparser must know which tokens are types. +# +# For example: +# +# 'typedef int Node; const Node* (*ar)[10];' +# => +# ar is a pointer to array[10] of pointer to const Node +# +# Copyright (C) 2008, Eli Bendersky +# License: LGPL +#----------------------------------------------------------------- +import sys + +from pycparser import c_parser, c_ast + + +def explain_c_declaration(c_decl): + """ Parses the declaration in c_decl and returns a text + explanation as a string. + + The last external node of the string is used, to allow + earlier typedefs for used types. + """ + parser = c_parser.CParser() + + node = parser.parse(c_decl, filename='') + + if ( not isinstance(node, c_ast.FileAST) or + not isinstance(node.ext[-1], c_ast.Decl)): + return "Last external node is invalid type" + + return _explain_decl_node(node.ext[-1]) + + +def _explain_decl_node(decl_node): + """ Receives a c_ast.Decl note and returns its explanation in + English. + """ + #~ print decl_node.show() + storage = ' '.join(decl_node.storage) + ' ' if decl_node.storage else '' + + return (decl_node.name + + " is a " + + storage + + _explain_type(decl_node.type)) + + +def _explain_type(decl): + """ Recursively explains a type decl node + """ + typ = type(decl) + + if typ == c_ast.TypeDecl: + quals = ' '.join(decl.quals) + ' ' if decl.quals else '' + return quals + _explain_type(decl.type) + elif typ == c_ast.Typename or typ == c_ast.Decl: + return _explain_type(decl.type) + elif typ == c_ast.IdentifierType: + return ' '.join(decl.names) + elif typ == c_ast.PtrDecl: + quals = ' '.join(decl.quals) + ' ' if decl.quals else '' + return quals + 'pointer to ' + _explain_type(decl.type) + elif typ == c_ast.ArrayDecl: + arr = 'array' + if decl.dim: arr += '[%s]' % decl.dim.value + + return arr + " of " + _explain_type(decl.type) + + elif typ == c_ast.FuncDecl: + if decl.args: + params = [_explain_type(param) for param in decl.args.params] + args = ', '.join(params) + else: + args = '' + + return ('function(%s) returning ' % (args) + + _explain_type(decl.type)) + + +if __name__ == "__main__": + if len(sys.argv) > 1: + c_decl = sys.argv[1] + else: + c_decl = "char *(*(**foo[][8])())[];" + + print "Explaining the declaration:", c_decl + print "\n", explain_c_declaration(c_decl) diff --git a/plugins/pycparser/pycparser/__init__.py b/plugins/pycparser/pycparser/__init__.py index 6219bb2..f04359d 100644 --- a/plugins/pycparser/pycparser/__init__.py +++ b/plugins/pycparser/pycparser/__init__.py @@ -1,75 +1,75 @@ -#----------------------------------------------------------------- -# pycparser: __init__.py -# -# This package file exports some convenience functions for -# interacting with pycparser -# -# Copyright (C) 2008-2009, Eli Bendersky -# License: LGPL -#----------------------------------------------------------------- - -__all__ = ['c_lexer', 'c_parser', 'c_ast'] -__version__ = '1.05' - -from subprocess import Popen, PIPE -from types import ListType - -from c_parser import CParser - - -def parse_file( filename, use_cpp=False, - cpp_path='cpp', cpp_args=''): - """ Parse a C file using pycparser. - - filename: - Name of the file you want to parse. - - use_cpp: - Set to True if you want to execute the C pre-processor - on the file prior to parsing it. - - cpp_path: - If use_cpp is True, this is the path to 'cpp' on your - system. If no path is provided, it attempts to just - execute 'cpp', so it must be in your PATH. - - cpp_args: - If use_cpp is True, set this to the command line - arguments strings to cpp. Be careful with quotes - - it's best to pass a raw string (r'') here. - For example: - r'-I../utils/fake_libc_include' - If several arguments are required, pass a list of - strings. - - When successful, an AST is returned. ParseError can be - thrown if the file doesn't parse successfully. - - Errors from cpp will be printed out. - """ - if use_cpp: - path_list = [cpp_path] - if isinstance(cpp_args, ListType): - path_list += cpp_args - elif cpp_args != '': - path_list += [cpp_args] - path_list += [filename] - - # Note the use of universal_newlines to treat all newlines - # as \n for Python's purpose - # - pipe = Popen( path_list, - stdout=PIPE, - universal_newlines=True) - text = pipe.communicate()[0] - else: - text = open(filename).read() - - parser = CParser() - return parser.parse(text, filename) - - -if __name__ == "__main__": - pass - - +#----------------------------------------------------------------- +# pycparser: __init__.py +# +# This package file exports some convenience functions for +# interacting with pycparser +# +# Copyright (C) 2008-2009, Eli Bendersky +# License: LGPL +#----------------------------------------------------------------- + +__all__ = ['c_lexer', 'c_parser', 'c_ast'] +__version__ = '1.05' + +from subprocess import Popen, PIPE +from types import ListType + +from c_parser import CParser + + +def parse_file( filename, use_cpp=False, + cpp_path='cpp', cpp_args=''): + """ Parse a C file using pycparser. + + filename: + Name of the file you want to parse. + + use_cpp: + Set to True if you want to execute the C pre-processor + on the file prior to parsing it. + + cpp_path: + If use_cpp is True, this is the path to 'cpp' on your + system. If no path is provided, it attempts to just + execute 'cpp', so it must be in your PATH. + + cpp_args: + If use_cpp is True, set this to the command line + arguments strings to cpp. Be careful with quotes - + it's best to pass a raw string (r'') here. + For example: + r'-I../utils/fake_libc_include' + If several arguments are required, pass a list of + strings. + + When successful, an AST is returned. ParseError can be + thrown if the file doesn't parse successfully. + + Errors from cpp will be printed out. + """ + if use_cpp: + path_list = [cpp_path] + if isinstance(cpp_args, ListType): + path_list += cpp_args + elif cpp_args != '': + path_list += [cpp_args] + path_list += [filename] + + # Note the use of universal_newlines to treat all newlines + # as \n for Python's purpose + # + pipe = Popen( path_list, + stdout=PIPE, + universal_newlines=True) + text = pipe.communicate()[0] + else: + text = open(filename).read() + + parser = CParser() + return parser.parse(text, filename) + + +if __name__ == "__main__": + pass + + diff --git a/plugins/pycparser/pycparser/c_ast.py b/plugins/pycparser/pycparser/c_ast.py index 90cfb79..e0ebab8 100644 --- a/plugins/pycparser/pycparser/c_ast.py +++ b/plugins/pycparser/pycparser/c_ast.py @@ -1,1163 +1,1163 @@ -#----------------------------------------------------------------- -# ** ATTENTION ** -# This code was automatically generated from the file: -# _c_ast.yaml -# -# Do not modify it directly. Modify the configuration file and -# run the generator again. -# ** ** *** ** ** -# -# pycparser: c_ast.py -# -# AST Node classes. -# -# Copyright (C) 2008, Eli Bendersky -# License: LGPL -#----------------------------------------------------------------- - - -import sys - - -class Node(object): - """ Abstract base class for AST nodes. - """ - def children(self): - """ A sequence of all children that are Nodes - """ - pass - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - """ Pretty print the Node and all its attributes and - children (recursively) to a buffer. - - file: - Open IO buffer into which the Node is printed. - - offset: - Initial offset (amount of leading spaces) - - attrnames: - True if you want to see the attribute names in - name=value pairs. False to only see the values. - - showcoord: - Do you want the coordinates of each Node to be - displayed. - """ - pass - - -class NodeVisitor(object): - """ A base NodeVisitor class for visiting c_ast nodes. - Subclass it and define your own visit_XXX methods, where - XXX is the class name you want to visit with these - methods. - - For example: - - class ConstantVisitor(NodeVisitor): - def __init__(self): - self.values = [] - - def visit_Constant(self, node): - self.values.append(node.value) - - Creates a list of values of all the constant nodes - encountered below the given node. To use it: - - cv = ConstantVisitor() - cv.visit(node) - - Notes: - - * generic_visit() will be called for AST nodes for which - no visit_XXX method was defined. - * The children of nodes for which a visit_XXX was - defined will not be visited - if you need this, call - generic_visit() on the node. - You can use: - NodeVisitor.generic_visit(self, node) - * Modeled after Python's own AST visiting facilities - (the ast module of Python 3.0) - """ - def visit(self, node): - """ Visit a node. - """ - method = 'visit_' + node.__class__.__name__ - visitor = getattr(self, method, self.generic_visit) - return visitor(node) - - def generic_visit(self, node): - """ Called if no explicit visitor function exists for a - node. Implements preorder visiting of the node. - """ - for c in node.children(): - self.visit(c) - - -class Typedef(Node): - def __init__(self, name, quals, storage, type, coord=None): - self.name = name - self.quals = quals - self.storage = storage - self.type = type - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Typedef: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name)), ("quals", repr(self.quals)), ("storage", repr(self.storage))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name, self.quals, self.storage]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Struct(Node): - def __init__(self, name, decls, coord=None): - self.name = name - self.decls = decls - self.coord = coord - - def children(self): - nodelist = [] - if self.decls is not None: nodelist.extend(self.decls) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Struct: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class FuncCall(Node): - def __init__(self, name, args, coord=None): - self.name = name - self.args = args - self.coord = coord - - def children(self): - nodelist = [] - if self.name is not None: nodelist.append(self.name) - if self.args is not None: nodelist.append(self.args) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'FuncCall: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class UnaryOp(Node): - def __init__(self, op, expr, coord=None): - self.op = op - self.expr = expr - self.coord = coord - - def children(self): - nodelist = [] - if self.expr is not None: nodelist.append(self.expr) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'UnaryOp: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) - else: - attrstr = ', '.join('%s' % v for v in [self.op]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Union(Node): - def __init__(self, name, decls, coord=None): - self.name = name - self.decls = decls - self.coord = coord - - def children(self): - nodelist = [] - if self.decls is not None: nodelist.extend(self.decls) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Union: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class TernaryOp(Node): - def __init__(self, cond, iftrue, iffalse, coord=None): - self.cond = cond - self.iftrue = iftrue - self.iffalse = iffalse - self.coord = coord - - def children(self): - nodelist = [] - if self.cond is not None: nodelist.append(self.cond) - if self.iftrue is not None: nodelist.append(self.iftrue) - if self.iffalse is not None: nodelist.append(self.iffalse) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'TernaryOp: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Label(Node): - def __init__(self, name, stmt, coord=None): - self.name = name - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Label: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class IdentifierType(Node): - def __init__(self, names, coord=None): - self.names = names - self.coord = coord - - def children(self): - nodelist = [] - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'IdentifierType: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("names", repr(self.names))]) - else: - attrstr = ', '.join('%s' % v for v in [self.names]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class FuncDef(Node): - def __init__(self, decl, param_decls, body, coord=None): - self.decl = decl - self.param_decls = param_decls - self.body = body - self.coord = coord - - def children(self): - nodelist = [] - if self.decl is not None: nodelist.append(self.decl) - if self.body is not None: nodelist.append(self.body) - if self.param_decls is not None: nodelist.extend(self.param_decls) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'FuncDef: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Enumerator(Node): - def __init__(self, name, value, coord=None): - self.name = name - self.value = value - self.coord = coord - - def children(self): - nodelist = [] - if self.value is not None: nodelist.append(self.value) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Enumerator: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class For(Node): - def __init__(self, init, cond, next, stmt, coord=None): - self.init = init - self.cond = cond - self.next = next - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.init is not None: nodelist.append(self.init) - if self.cond is not None: nodelist.append(self.cond) - if self.next is not None: nodelist.append(self.next) - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'For: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Assignment(Node): - def __init__(self, op, lvalue, rvalue, coord=None): - self.op = op - self.lvalue = lvalue - self.rvalue = rvalue - self.coord = coord - - def children(self): - nodelist = [] - if self.lvalue is not None: nodelist.append(self.lvalue) - if self.rvalue is not None: nodelist.append(self.rvalue) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Assignment: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) - else: - attrstr = ', '.join('%s' % v for v in [self.op]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class FuncDecl(Node): - def __init__(self, args, type, coord=None): - self.args = args - self.type = type - self.coord = coord - - def children(self): - nodelist = [] - if self.args is not None: nodelist.append(self.args) - if self.type is not None: nodelist.append(self.type) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'FuncDecl: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Enum(Node): - def __init__(self, name, values, coord=None): - self.name = name - self.values = values - self.coord = coord - - def children(self): - nodelist = [] - if self.values is not None: nodelist.append(self.values) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Enum: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class ExprList(Node): - def __init__(self, exprs, coord=None): - self.exprs = exprs - self.coord = coord - - def children(self): - nodelist = [] - if self.exprs is not None: nodelist.extend(self.exprs) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'ExprList: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Break(Node): - def __init__(self, coord=None): - self.coord = coord - - def children(self): - return () - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Break: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class DoWhile(Node): - def __init__(self, cond, stmt, coord=None): - self.cond = cond - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.cond is not None: nodelist.append(self.cond) - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'DoWhile: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class StructRef(Node): - def __init__(self, name, type, field, coord=None): - self.name = name - self.type = type - self.field = field - self.coord = coord - - def children(self): - nodelist = [] - if self.name is not None: nodelist.append(self.name) - if self.field is not None: nodelist.append(self.field) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'StructRef: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("type", repr(self.type))]) - else: - attrstr = ', '.join('%s' % v for v in [self.type]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class BinaryOp(Node): - def __init__(self, op, left, right, coord=None): - self.op = op - self.left = left - self.right = right - self.coord = coord - - def children(self): - nodelist = [] - if self.left is not None: nodelist.append(self.left) - if self.right is not None: nodelist.append(self.right) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'BinaryOp: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) - else: - attrstr = ', '.join('%s' % v for v in [self.op]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Compound(Node): - def __init__(self, decls, stmts, coord=None): - self.decls = decls - self.stmts = stmts - self.coord = coord - - def children(self): - nodelist = [] - if self.decls is not None: nodelist.extend(self.decls) - if self.stmts is not None: nodelist.extend(self.stmts) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Compound: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class ArrayDecl(Node): - def __init__(self, type, dim, coord=None): - self.type = type - self.dim = dim - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - if self.dim is not None: nodelist.append(self.dim) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'ArrayDecl: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Case(Node): - def __init__(self, expr, stmt, coord=None): - self.expr = expr - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.expr is not None: nodelist.append(self.expr) - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Case: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Cast(Node): - def __init__(self, to_type, expr, coord=None): - self.to_type = to_type - self.expr = expr - self.coord = coord - - def children(self): - nodelist = [] - if self.to_type is not None: nodelist.append(self.to_type) - if self.expr is not None: nodelist.append(self.expr) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Cast: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class TypeDecl(Node): - def __init__(self, declname, quals, type, coord=None): - self.declname = declname - self.quals = quals - self.type = type - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'TypeDecl: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("declname", repr(self.declname)), ("quals", repr(self.quals))]) - else: - attrstr = ', '.join('%s' % v for v in [self.declname, self.quals]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Default(Node): - def __init__(self, stmt, coord=None): - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Default: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class PtrDecl(Node): - def __init__(self, quals, type, coord=None): - self.quals = quals - self.type = type - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'PtrDecl: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("quals", repr(self.quals))]) - else: - attrstr = ', '.join('%s' % v for v in [self.quals]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Switch(Node): - def __init__(self, cond, stmt, coord=None): - self.cond = cond - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.cond is not None: nodelist.append(self.cond) - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Switch: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Continue(Node): - def __init__(self, coord=None): - self.coord = coord - - def children(self): - return () - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Continue: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class ParamList(Node): - def __init__(self, params, coord=None): - self.params = params - self.coord = coord - - def children(self): - nodelist = [] - if self.params is not None: nodelist.extend(self.params) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'ParamList: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Return(Node): - def __init__(self, expr, coord=None): - self.expr = expr - self.coord = coord - - def children(self): - nodelist = [] - if self.expr is not None: nodelist.append(self.expr) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Return: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Typename(Node): - def __init__(self, quals, type, coord=None): - self.quals = quals - self.type = type - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Typename: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("quals", repr(self.quals))]) - else: - attrstr = ', '.join('%s' % v for v in [self.quals]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class ID(Node): - def __init__(self, name, coord=None): - self.name = name - self.coord = coord - - def children(self): - nodelist = [] - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'ID: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Goto(Node): - def __init__(self, name, coord=None): - self.name = name - self.coord = coord - - def children(self): - nodelist = [] - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Goto: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Decl(Node): - def __init__(self, name, quals, storage, type, init, bitsize, coord=None): - self.name = name - self.quals = quals - self.storage = storage - self.type = type - self.init = init - self.bitsize = bitsize - self.coord = coord - - def children(self): - nodelist = [] - if self.type is not None: nodelist.append(self.type) - if self.init is not None: nodelist.append(self.init) - if self.bitsize is not None: nodelist.append(self.bitsize) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Decl: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name)), ("quals", repr(self.quals)), ("storage", repr(self.storage))]) - else: - attrstr = ', '.join('%s' % v for v in [self.name, self.quals, self.storage]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class Constant(Node): - def __init__(self, type, value, coord=None): - self.type = type - self.value = value - self.coord = coord - - def children(self): - nodelist = [] - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'Constant: ') - - if attrnames: - attrstr = ', '.join('%s=%s' % nv for nv in [("type", repr(self.type)), ("value", repr(self.value))]) - else: - attrstr = ', '.join('%s' % v for v in [self.type, self.value]) - buf.write(attrstr) - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class FileAST(Node): - def __init__(self, ext, coord=None): - self.ext = ext - self.coord = coord - - def children(self): - nodelist = [] - if self.ext is not None: nodelist.extend(self.ext) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'FileAST: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class ArrayRef(Node): - def __init__(self, name, subscript, coord=None): - self.name = name - self.subscript = subscript - self.coord = coord - - def children(self): - nodelist = [] - if self.name is not None: nodelist.append(self.name) - if self.subscript is not None: nodelist.append(self.subscript) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'ArrayRef: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class While(Node): - def __init__(self, cond, stmt, coord=None): - self.cond = cond - self.stmt = stmt - self.coord = coord - - def children(self): - nodelist = [] - if self.cond is not None: nodelist.append(self.cond) - if self.stmt is not None: nodelist.append(self.stmt) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'While: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class EnumeratorList(Node): - def __init__(self, enumerators, coord=None): - self.enumerators = enumerators - self.coord = coord - - def children(self): - nodelist = [] - if self.enumerators is not None: nodelist.extend(self.enumerators) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'EnumeratorList: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class EllipsisParam(Node): - def __init__(self, coord=None): - self.coord = coord - - def children(self): - return () - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'EllipsisParam: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - -class If(Node): - def __init__(self, cond, iftrue, iffalse, coord=None): - self.cond = cond - self.iftrue = iftrue - self.iffalse = iffalse - self.coord = coord - - def children(self): - nodelist = [] - if self.cond is not None: nodelist.append(self.cond) - if self.iftrue is not None: nodelist.append(self.iftrue) - if self.iffalse is not None: nodelist.append(self.iffalse) - return tuple(nodelist) - - def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): - lead = ' ' * offset - buf.write(lead + 'If: ') - - if showcoord: - buf.write(' (at %s)' % self.coord) - buf.write('\n') - - for c in self.children(): - c.show(buf, offset + 2, attrnames, showcoord) - - +#----------------------------------------------------------------- +# ** ATTENTION ** +# This code was automatically generated from the file: +# _c_ast.yaml +# +# Do not modify it directly. Modify the configuration file and +# run the generator again. +# ** ** *** ** ** +# +# pycparser: c_ast.py +# +# AST Node classes. +# +# Copyright (C) 2008, Eli Bendersky +# License: LGPL +#----------------------------------------------------------------- + + +import sys + + +class Node(object): + """ Abstract base class for AST nodes. + """ + def children(self): + """ A sequence of all children that are Nodes + """ + pass + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + """ Pretty print the Node and all its attributes and + children (recursively) to a buffer. + + file: + Open IO buffer into which the Node is printed. + + offset: + Initial offset (amount of leading spaces) + + attrnames: + True if you want to see the attribute names in + name=value pairs. False to only see the values. + + showcoord: + Do you want the coordinates of each Node to be + displayed. + """ + pass + + +class NodeVisitor(object): + """ A base NodeVisitor class for visiting c_ast nodes. + Subclass it and define your own visit_XXX methods, where + XXX is the class name you want to visit with these + methods. + + For example: + + class ConstantVisitor(NodeVisitor): + def __init__(self): + self.values = [] + + def visit_Constant(self, node): + self.values.append(node.value) + + Creates a list of values of all the constant nodes + encountered below the given node. To use it: + + cv = ConstantVisitor() + cv.visit(node) + + Notes: + + * generic_visit() will be called for AST nodes for which + no visit_XXX method was defined. + * The children of nodes for which a visit_XXX was + defined will not be visited - if you need this, call + generic_visit() on the node. + You can use: + NodeVisitor.generic_visit(self, node) + * Modeled after Python's own AST visiting facilities + (the ast module of Python 3.0) + """ + def visit(self, node): + """ Visit a node. + """ + method = 'visit_' + node.__class__.__name__ + visitor = getattr(self, method, self.generic_visit) + return visitor(node) + + def generic_visit(self, node): + """ Called if no explicit visitor function exists for a + node. Implements preorder visiting of the node. + """ + for c in node.children(): + self.visit(c) + + +class Typedef(Node): + def __init__(self, name, quals, storage, type, coord=None): + self.name = name + self.quals = quals + self.storage = storage + self.type = type + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Typedef: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name)), ("quals", repr(self.quals)), ("storage", repr(self.storage))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name, self.quals, self.storage]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Struct(Node): + def __init__(self, name, decls, coord=None): + self.name = name + self.decls = decls + self.coord = coord + + def children(self): + nodelist = [] + if self.decls is not None: nodelist.extend(self.decls) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Struct: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class FuncCall(Node): + def __init__(self, name, args, coord=None): + self.name = name + self.args = args + self.coord = coord + + def children(self): + nodelist = [] + if self.name is not None: nodelist.append(self.name) + if self.args is not None: nodelist.append(self.args) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'FuncCall: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class UnaryOp(Node): + def __init__(self, op, expr, coord=None): + self.op = op + self.expr = expr + self.coord = coord + + def children(self): + nodelist = [] + if self.expr is not None: nodelist.append(self.expr) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'UnaryOp: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) + else: + attrstr = ', '.join('%s' % v for v in [self.op]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Union(Node): + def __init__(self, name, decls, coord=None): + self.name = name + self.decls = decls + self.coord = coord + + def children(self): + nodelist = [] + if self.decls is not None: nodelist.extend(self.decls) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Union: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class TernaryOp(Node): + def __init__(self, cond, iftrue, iffalse, coord=None): + self.cond = cond + self.iftrue = iftrue + self.iffalse = iffalse + self.coord = coord + + def children(self): + nodelist = [] + if self.cond is not None: nodelist.append(self.cond) + if self.iftrue is not None: nodelist.append(self.iftrue) + if self.iffalse is not None: nodelist.append(self.iffalse) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'TernaryOp: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Label(Node): + def __init__(self, name, stmt, coord=None): + self.name = name + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Label: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class IdentifierType(Node): + def __init__(self, names, coord=None): + self.names = names + self.coord = coord + + def children(self): + nodelist = [] + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'IdentifierType: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("names", repr(self.names))]) + else: + attrstr = ', '.join('%s' % v for v in [self.names]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class FuncDef(Node): + def __init__(self, decl, param_decls, body, coord=None): + self.decl = decl + self.param_decls = param_decls + self.body = body + self.coord = coord + + def children(self): + nodelist = [] + if self.decl is not None: nodelist.append(self.decl) + if self.body is not None: nodelist.append(self.body) + if self.param_decls is not None: nodelist.extend(self.param_decls) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'FuncDef: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Enumerator(Node): + def __init__(self, name, value, coord=None): + self.name = name + self.value = value + self.coord = coord + + def children(self): + nodelist = [] + if self.value is not None: nodelist.append(self.value) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Enumerator: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class For(Node): + def __init__(self, init, cond, next, stmt, coord=None): + self.init = init + self.cond = cond + self.next = next + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.init is not None: nodelist.append(self.init) + if self.cond is not None: nodelist.append(self.cond) + if self.next is not None: nodelist.append(self.next) + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'For: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Assignment(Node): + def __init__(self, op, lvalue, rvalue, coord=None): + self.op = op + self.lvalue = lvalue + self.rvalue = rvalue + self.coord = coord + + def children(self): + nodelist = [] + if self.lvalue is not None: nodelist.append(self.lvalue) + if self.rvalue is not None: nodelist.append(self.rvalue) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Assignment: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) + else: + attrstr = ', '.join('%s' % v for v in [self.op]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class FuncDecl(Node): + def __init__(self, args, type, coord=None): + self.args = args + self.type = type + self.coord = coord + + def children(self): + nodelist = [] + if self.args is not None: nodelist.append(self.args) + if self.type is not None: nodelist.append(self.type) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'FuncDecl: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Enum(Node): + def __init__(self, name, values, coord=None): + self.name = name + self.values = values + self.coord = coord + + def children(self): + nodelist = [] + if self.values is not None: nodelist.append(self.values) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Enum: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class ExprList(Node): + def __init__(self, exprs, coord=None): + self.exprs = exprs + self.coord = coord + + def children(self): + nodelist = [] + if self.exprs is not None: nodelist.extend(self.exprs) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'ExprList: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Break(Node): + def __init__(self, coord=None): + self.coord = coord + + def children(self): + return () + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Break: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class DoWhile(Node): + def __init__(self, cond, stmt, coord=None): + self.cond = cond + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.cond is not None: nodelist.append(self.cond) + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'DoWhile: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class StructRef(Node): + def __init__(self, name, type, field, coord=None): + self.name = name + self.type = type + self.field = field + self.coord = coord + + def children(self): + nodelist = [] + if self.name is not None: nodelist.append(self.name) + if self.field is not None: nodelist.append(self.field) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'StructRef: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("type", repr(self.type))]) + else: + attrstr = ', '.join('%s' % v for v in [self.type]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class BinaryOp(Node): + def __init__(self, op, left, right, coord=None): + self.op = op + self.left = left + self.right = right + self.coord = coord + + def children(self): + nodelist = [] + if self.left is not None: nodelist.append(self.left) + if self.right is not None: nodelist.append(self.right) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'BinaryOp: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))]) + else: + attrstr = ', '.join('%s' % v for v in [self.op]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Compound(Node): + def __init__(self, decls, stmts, coord=None): + self.decls = decls + self.stmts = stmts + self.coord = coord + + def children(self): + nodelist = [] + if self.decls is not None: nodelist.extend(self.decls) + if self.stmts is not None: nodelist.extend(self.stmts) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Compound: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class ArrayDecl(Node): + def __init__(self, type, dim, coord=None): + self.type = type + self.dim = dim + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + if self.dim is not None: nodelist.append(self.dim) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'ArrayDecl: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Case(Node): + def __init__(self, expr, stmt, coord=None): + self.expr = expr + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.expr is not None: nodelist.append(self.expr) + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Case: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Cast(Node): + def __init__(self, to_type, expr, coord=None): + self.to_type = to_type + self.expr = expr + self.coord = coord + + def children(self): + nodelist = [] + if self.to_type is not None: nodelist.append(self.to_type) + if self.expr is not None: nodelist.append(self.expr) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Cast: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class TypeDecl(Node): + def __init__(self, declname, quals, type, coord=None): + self.declname = declname + self.quals = quals + self.type = type + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'TypeDecl: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("declname", repr(self.declname)), ("quals", repr(self.quals))]) + else: + attrstr = ', '.join('%s' % v for v in [self.declname, self.quals]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Default(Node): + def __init__(self, stmt, coord=None): + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Default: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class PtrDecl(Node): + def __init__(self, quals, type, coord=None): + self.quals = quals + self.type = type + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'PtrDecl: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("quals", repr(self.quals))]) + else: + attrstr = ', '.join('%s' % v for v in [self.quals]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Switch(Node): + def __init__(self, cond, stmt, coord=None): + self.cond = cond + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.cond is not None: nodelist.append(self.cond) + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Switch: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Continue(Node): + def __init__(self, coord=None): + self.coord = coord + + def children(self): + return () + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Continue: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class ParamList(Node): + def __init__(self, params, coord=None): + self.params = params + self.coord = coord + + def children(self): + nodelist = [] + if self.params is not None: nodelist.extend(self.params) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'ParamList: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Return(Node): + def __init__(self, expr, coord=None): + self.expr = expr + self.coord = coord + + def children(self): + nodelist = [] + if self.expr is not None: nodelist.append(self.expr) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Return: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Typename(Node): + def __init__(self, quals, type, coord=None): + self.quals = quals + self.type = type + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Typename: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("quals", repr(self.quals))]) + else: + attrstr = ', '.join('%s' % v for v in [self.quals]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class ID(Node): + def __init__(self, name, coord=None): + self.name = name + self.coord = coord + + def children(self): + nodelist = [] + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'ID: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Goto(Node): + def __init__(self, name, coord=None): + self.name = name + self.coord = coord + + def children(self): + nodelist = [] + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Goto: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Decl(Node): + def __init__(self, name, quals, storage, type, init, bitsize, coord=None): + self.name = name + self.quals = quals + self.storage = storage + self.type = type + self.init = init + self.bitsize = bitsize + self.coord = coord + + def children(self): + nodelist = [] + if self.type is not None: nodelist.append(self.type) + if self.init is not None: nodelist.append(self.init) + if self.bitsize is not None: nodelist.append(self.bitsize) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Decl: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name)), ("quals", repr(self.quals)), ("storage", repr(self.storage))]) + else: + attrstr = ', '.join('%s' % v for v in [self.name, self.quals, self.storage]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class Constant(Node): + def __init__(self, type, value, coord=None): + self.type = type + self.value = value + self.coord = coord + + def children(self): + nodelist = [] + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'Constant: ') + + if attrnames: + attrstr = ', '.join('%s=%s' % nv for nv in [("type", repr(self.type)), ("value", repr(self.value))]) + else: + attrstr = ', '.join('%s' % v for v in [self.type, self.value]) + buf.write(attrstr) + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class FileAST(Node): + def __init__(self, ext, coord=None): + self.ext = ext + self.coord = coord + + def children(self): + nodelist = [] + if self.ext is not None: nodelist.extend(self.ext) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'FileAST: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class ArrayRef(Node): + def __init__(self, name, subscript, coord=None): + self.name = name + self.subscript = subscript + self.coord = coord + + def children(self): + nodelist = [] + if self.name is not None: nodelist.append(self.name) + if self.subscript is not None: nodelist.append(self.subscript) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'ArrayRef: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class While(Node): + def __init__(self, cond, stmt, coord=None): + self.cond = cond + self.stmt = stmt + self.coord = coord + + def children(self): + nodelist = [] + if self.cond is not None: nodelist.append(self.cond) + if self.stmt is not None: nodelist.append(self.stmt) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'While: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class EnumeratorList(Node): + def __init__(self, enumerators, coord=None): + self.enumerators = enumerators + self.coord = coord + + def children(self): + nodelist = [] + if self.enumerators is not None: nodelist.extend(self.enumerators) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'EnumeratorList: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class EllipsisParam(Node): + def __init__(self, coord=None): + self.coord = coord + + def children(self): + return () + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'EllipsisParam: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + +class If(Node): + def __init__(self, cond, iftrue, iffalse, coord=None): + self.cond = cond + self.iftrue = iftrue + self.iffalse = iffalse + self.coord = coord + + def children(self): + nodelist = [] + if self.cond is not None: nodelist.append(self.cond) + if self.iftrue is not None: nodelist.append(self.iftrue) + if self.iffalse is not None: nodelist.append(self.iffalse) + return tuple(nodelist) + + def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False): + lead = ' ' * offset + buf.write(lead + 'If: ') + + if showcoord: + buf.write(' (at %s)' % self.coord) + buf.write('\n') + + for c in self.children(): + c.show(buf, offset + 2, attrnames, showcoord) + + diff --git a/plugins/pycparser/pycparser/c_lexer.py b/plugins/pycparser/pycparser/c_lexer.py index 28638df..97f9d3b 100644 --- a/plugins/pycparser/pycparser/c_lexer.py +++ b/plugins/pycparser/pycparser/c_lexer.py @@ -16,21 +16,21 @@ from ply.lex import TOKEN class CLexer(object): """ A lexer for the C language. After building it, set the - input text with input(), and call token() to get new + input text with input(), and call token() to get new tokens. - + The public attribute filename can be set to an initial - filaneme, but the lexer will update it upon #line + filaneme, but the lexer will update it upon #line directives. """ def __init__(self, error_func, type_lookup_func): """ Create a new Lexer. - + error_func: An error function. Will be called with an error - message, line and column as arguments, in case of + message, line and column as arguments, in case of an error during lexing. - + type_lookup_func: A type lookup function. Given a string, it must return True IFF this string is a name of a type @@ -39,7 +39,7 @@ class CLexer(object): self.error_func = error_func self.type_lookup_func = type_lookup_func self.filename = '' - + # Allow either "# line" or "# " to support GCC's # cpp output # @@ -47,8 +47,8 @@ class CLexer(object): def build(self, **kwargs): """ Builds the lexer from the specification. Must be - called after the lexer object is created. - + called after the lexer object is created. + This method exists separately, because the PLY manual warns against calling lex.lex inside __init__ @@ -62,13 +62,13 @@ class CLexer(object): def input(self, text): self.lexer.input(text) - + def token(self): g = self.lexer.token() return g ######################-- PRIVATE --###################### - + ## ## Internal auxiliary methods ## @@ -76,26 +76,26 @@ class CLexer(object): location = self._make_tok_location(token) self.error_func(msg, location[0], location[1]) self.lexer.skip(1) - + def _find_tok_column(self, token): i = token.lexpos while i > 0: if self.lexer.lexdata[i] == '\n': break i -= 1 return (token.lexpos - i) + 1 - + def _make_tok_location(self, token): return (token.lineno, self._find_tok_column(token)) - + ## ## Reserved keywords ## keywords = ( - 'AUTO', 'BREAK', 'CASE', 'CHAR', 'CONST', 'CONTINUE', - 'DEFAULT', 'DO', 'DOUBLE', 'ELSE', 'ENUM', 'EXTERN', + 'AUTO', 'BREAK', 'CASE', 'CHAR', 'CONST', 'CONTINUE', + 'DEFAULT', 'DO', 'DOUBLE', 'ELSE', 'ENUM', 'EXTERN', 'FLOAT', 'FOR', 'GOTO', 'IF', 'INT', 'LONG', 'REGISTER', - 'RETURN', 'SHORT', 'SIGNED', 'SIZEOF', 'STATIC', 'STRUCT', - 'SWITCH', 'TYPEDEF', 'UNION', 'UNSIGNED', 'VOID', + 'RETURN', 'SHORT', 'SIGNED', 'SIZEOF', 'STATIC', 'STRUCT', + 'SWITCH', 'TYPEDEF', 'UNION', 'UNSIGNED', 'VOID', 'VOLATILE', 'WHILE', ) @@ -108,35 +108,35 @@ class CLexer(object): ## tokens = keywords + ( # Identifiers - 'ID', - - # Type identifiers (identifiers previously defined as + 'ID', + + # Type identifiers (identifiers previously defined as # types with typedef) 'TYPEID', - - # constants + + # constants 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', - 'FLOAT_CONST', + 'FLOAT_CONST', 'CHAR_CONST', 'WCHAR_CONST', - + # String literals 'STRING_LITERAL', 'WSTRING_LITERAL', - # Operators + # Operators 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT', 'LOR', 'LAND', 'LNOT', 'LT', 'LE', 'GT', 'GE', 'EQ', 'NE', - + # Assignment - 'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', + 'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', 'PLUSEQUAL', 'MINUSEQUAL', - 'LSHIFTEQUAL','RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', + 'LSHIFTEQUAL','RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', 'OREQUAL', - # Increment/decrement + # Increment/decrement 'PLUSPLUS', 'MINUSMINUS', # Structure dereference (->) @@ -144,18 +144,18 @@ class CLexer(object): # Conditional operator (?) 'CONDOP', - - # Delimeters + + # Delimeters 'LPAREN', 'RPAREN', # ( ) 'LBRACKET', 'RBRACKET', # [ ] - 'LBRACE', 'RBRACE', # { } + 'LBRACE', 'RBRACE', # { } 'COMMA', 'PERIOD', # . , 'SEMI', 'COLON', # ; : # Ellipsis (...) 'ELLIPSIS', - - # pre-processor + + # pre-processor 'PPHASH', # '#' ) @@ -172,7 +172,7 @@ class CLexer(object): decimal_constant = '(0'+integer_suffix_opt+')|([1-9][0-9]*'+integer_suffix_opt+')' octal_constant = '0[0-7]*'+integer_suffix_opt hex_constant = '0[xX][0-9a-fA-F]+'+integer_suffix_opt - + bad_octal_constant = '0[0-7]*[89]' # character constants (K&R2: A.2.5.2) @@ -185,14 +185,14 @@ class CLexer(object): bad_escape = r"""([\\][^a-zA-Z\\?'"x0-7])""" escape_sequence = r"""(\\("""+simple_escape+'|'+octal_escape+'|'+hex_escape+'))' - cconst_char = r"""([^'\\\n]|"""+escape_sequence+')' + cconst_char = r"""([^'\\\n]|"""+escape_sequence+')' char_const = "'"+cconst_char+"'" wchar_const = 'L'+char_const unmatched_quote = "('"+cconst_char+"*\\n)|('"+cconst_char+"*$)" bad_char_const = r"""('"""+cconst_char+"""[^'\n]+')|('')|('"""+bad_escape+r"""[^'\n]*')""" # string literals (K&R2: A.2.6) - string_char = r"""([^"\\\n]|"""+escape_sequence+')' + string_char = r"""([^"\\\n]|"""+escape_sequence+')' string_literal = '"'+string_char+'*"' wstring_literal = 'L'+string_literal bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' @@ -207,15 +207,15 @@ class CLexer(object): ## states = ( # ppline: preprocessor line directives - # + # ('ppline', 'exclusive'), ) - + def t_PPHASH(self, t): r'[ \t]*\#' m = self.line_pattern.match( t.lexer.lexdata, pos=t.lexer.lexpos) - + if m: t.lexer.begin('ppline') self.pp_line = self.pp_filename = None @@ -223,7 +223,7 @@ class CLexer(object): else: t.type = 'PPHASH' return t - + ## ## Rules for the ppline state ## @@ -246,21 +246,21 @@ class CLexer(object): def t_ppline_NEWLINE(self, t): r'\n' - + if self.pp_line is None: self._error('line number missing in #line', t) else: self.lexer.lineno = int(self.pp_line) - + if self.pp_filename is not None: self.filename = self.pp_filename - + t.lexer.begin('INITIAL') def t_ppline_PPLINE(self, t): r'line' pass - + t_ppline_ignore = ' \t' def t_ppline_error(self, t): @@ -336,8 +336,8 @@ class CLexer(object): t_ELLIPSIS = r'\.\.\.' t_STRING_LITERAL = string_literal - - # The following floating and integer constants are defined as + + # The following floating and integer constants are defined as # functions to impose a strict order (otherwise, decimal # is placed before the others because its regex is longer, # and this is bad) @@ -363,17 +363,17 @@ class CLexer(object): def t_INT_CONST_DEC(self, t): return t - # Must come before bad_char_const, to prevent it from + # Must come before bad_char_const, to prevent it from # catching valid char constants as invalid - # + # @TOKEN(char_const) def t_CHAR_CONST(self, t): return t - + @TOKEN(wchar_const) def t_WCHAR_CONST(self, t): return t - + @TOKEN(unmatched_quote) def t_UNMATCHED_QUOTE(self, t): msg = "Unmatched '" @@ -387,23 +387,23 @@ class CLexer(object): @TOKEN(wstring_literal) def t_WSTRING_LITERAL(self, t): return t - + # unmatched string literals are caught by the preprocessor - + @TOKEN(bad_string_literal) def t_BAD_STRING_LITERAL(self, t): - msg = "String contains invalid escape code" + msg = "String contains invalid escape code" self._error(msg, t) @TOKEN(identifier) def t_ID(self, t): t.type = self.keyword_map.get(t.value, "ID") - + if t.type == 'ID' and self.type_lookup_func(t.value): t.type = "TYPEID" - + return t - + def t_error(self, t): msg = 'Illegal character %s' % repr(t.value[0]) self._error(msg, t) @@ -412,32 +412,32 @@ class CLexer(object): if __name__ == "__main__": filename = '../zp.c' text = open(filename).read() - + #~ text = '"'+r"""ka \p ka"""+'"' text = r""" 546 - #line 66 "kwas\df.h" + #line 66 "kwas\df.h" id 4 - # 5 + # 5 dsf """ - + def errfoo(msg, a, b): print msg sys.exit() - + def typelookup(namd): return False - + clex = CLexer(errfoo, typelookup) clex.build() clex.input(text) - + while 1: tok = clex.token() if not tok: break - + #~ print type(tok) print "-", tok.value, tok.type, tok.lineno, clex.filename, tok.lexpos - + diff --git a/plugins/pycparser/pycparser/c_parser.py b/plugins/pycparser/pycparser/c_parser.py index 6c03660..ba5cb90 100644 --- a/plugins/pycparser/pycparser/c_parser.py +++ b/plugins/pycparser/pycparser/c_parser.py @@ -1,1259 +1,1259 @@ -#----------------------------------------------------------------- -# pycparser: cparse.py -# -# CParser class: Parser and AST builder for the C language -# -# Copyright (C) 2008, Eli Bendersky -# License: LGPL -#----------------------------------------------------------------- - -import re -import sys -from types import StringType - -import ply.yacc - -import c_ast -from c_lexer import CLexer -from plyparser import PLYParser, Coord, ParseError - - -class CParser(PLYParser): - def __init__( - self, - lex_optimize=True, - lextab='pycparser.lextab', - yacc_optimize=True, - yacctab='pycparser.yacctab', - yacc_debug=False): - """ Create a new CParser. - - Some arguments for controlling the debug/optimization - level of the parser are provided. The defaults are - tuned for release/performance mode. - The simple rules for using them are: - *) When tweaking CParser/CLexer, set these to False - *) When releasing a stable parser, set to True - - lex_optimize: - Set to False when you're modifying the lexer. - Otherwise, changes in the lexer won't be used, if - some lextab.py file exists. - When releasing with a stable lexer, set to True - to save the re-generation of the lexer table on - each run. - - lextab: - Points to the lex table that's used for optimized - mode. Only if you're modifying the lexer and want - some tests to avoid re-generating the table, make - this point to a local lex table file (that's been - earlier generated with lex_optimize=True) - - yacc_optimize: - Set to False when you're modifying the parser. - Otherwise, changes in the parser won't be used, if - some parsetab.py file exists. - When releasing with a stable parser, set to True - to save the re-generation of the parser table on - each run. - - yacctab: - Points to the yacc table that's used for optimized - mode. Only if you're modifying the parser, make - this point to a local yacc table file - - yacc_debug: - Generate a parser.out file that explains how yacc +#----------------------------------------------------------------- +# pycparser: cparse.py +# +# CParser class: Parser and AST builder for the C language +# +# Copyright (C) 2008, Eli Bendersky +# License: LGPL +#----------------------------------------------------------------- + +import re +import sys +from types import StringType + +import ply.yacc + +import c_ast +from c_lexer import CLexer +from plyparser import PLYParser, Coord, ParseError + + +class CParser(PLYParser): + def __init__( + self, + lex_optimize=True, + lextab='pycparser.lextab', + yacc_optimize=True, + yacctab='pycparser.yacctab', + yacc_debug=False): + """ Create a new CParser. + + Some arguments for controlling the debug/optimization + level of the parser are provided. The defaults are + tuned for release/performance mode. + The simple rules for using them are: + *) When tweaking CParser/CLexer, set these to False + *) When releasing a stable parser, set to True + + lex_optimize: + Set to False when you're modifying the lexer. + Otherwise, changes in the lexer won't be used, if + some lextab.py file exists. + When releasing with a stable lexer, set to True + to save the re-generation of the lexer table on + each run. + + lextab: + Points to the lex table that's used for optimized + mode. Only if you're modifying the lexer and want + some tests to avoid re-generating the table, make + this point to a local lex table file (that's been + earlier generated with lex_optimize=True) + + yacc_optimize: + Set to False when you're modifying the parser. + Otherwise, changes in the parser won't be used, if + some parsetab.py file exists. + When releasing with a stable parser, set to True + to save the re-generation of the parser table on + each run. + + yacctab: + Points to the yacc table that's used for optimized + mode. Only if you're modifying the parser, make + this point to a local yacc table file + + yacc_debug: + Generate a parser.out file that explains how yacc built the parsing table from the grammar. - """ - self.clex = CLexer( - error_func=self._lex_error_func, - type_lookup_func=self._lex_type_lookup_func) - - self.clex.build( - optimize=lex_optimize, - lextab=lextab) - self.tokens = self.clex.tokens - - rules_with_opt = [ - 'abstract_declarator', - 'constant_expression', - 'declaration_list', - 'declaration_specifiers', - 'expression', - 'identifier_list', - 'init_declarator_list', - 'parameter_type_list', - 'specifier_qualifier_list', - 'statement_list', - 'type_qualifier_list', - ] - - for rule in rules_with_opt: - self._create_opt_rule(rule) - - self.cparser = ply.yacc.yacc( - module=self, - start='translation_unit', - debug=yacc_debug, - optimize=yacc_optimize, - tabmodule=yacctab) - - # A table of identifiers defined as typedef types during - # parsing. - # - self.typedef_table = set([]) - - def parse(self, text, filename='', debuglevel=0): - """ Parses C code and returns an AST. - - text: - A string containing the C source code - - filename: - Name of the file being parsed (for meaningful - error messages) - - debuglevel: - Debug level to yacc - """ - self.clex.filename = filename - self.clex.reset_lineno() - self.typedef_table = set([]) - return self.cparser.parse(text, lexer=self.clex, debug=debuglevel) - - ######################-- PRIVATE --###################### - - def _lex_error_func(self, msg, line, column): - self._parse_error(msg, self._coord(line, column)) - - def _lex_type_lookup_func(self, name): - """ Looks up types that were previously defined with - typedef. - Passed to the lexer for recognizing identifiers that - are types. - """ - return name in self.typedef_table - - def _add_typedef_type(self, name): - """ Adds names that were defined as new types with - typedef. - """ - self.typedef_table.add(name) - - # To understand what's going on here, read sections A.8.5 and - # A.8.6 of K&R2 very carefully. - # - # A C type consists of a basic type declaration, with a list - # of modifiers. For example: - # - # int *c[5]; - # - # The basic declaration here is 'int x', and the pointer and - # the array are the modifiers. - # - # Basic declarations are represented by TypeDecl (from module - # c_ast) and the modifiers are FuncDecl, PtrDecl and - # ArrayDecl. - # - # The standard states that whenever a new modifier is parsed, - # it should be added to the end of the list of modifiers. For - # example: - # - # K&R2 A.8.6.2: Array Declarators - # - # In a declaration T D where D has the form - # D1 [constant-expression-opt] - # and the type of the identifier in the declaration T D1 is - # "type-modifier T", the type of the - # identifier of D is "type-modifier array of T" - # - # This is what this method does. The declarator it receives - # can be a list of declarators ending with TypeDecl. It - # tacks the modifier to the end of this list, just before - # the TypeDecl. - # - # Additionally, the modifier may be a list itself. This is - # useful for pointers, that can come as a chain from the rule - # p_pointer. In this case, the whole modifier list is spliced - # into the new location. - # - def _type_modify_decl(self, decl, modifier): - """ Tacks a type modifier on a declarator, and returns - the modified declarator. - - Note: the declarator and modifier may be modified - """ - #~ print '****' - #~ decl.show(offset=3) - #~ modifier.show(offset=3) - #~ print '****' - - modifier_head = modifier - modifier_tail = modifier - - # The modifier may be a nested list. Reach its tail. - # - while modifier_tail.type: - modifier_tail = modifier_tail.type - - # If the decl is a basic type, just tack the modifier onto - # it + """ + self.clex = CLexer( + error_func=self._lex_error_func, + type_lookup_func=self._lex_type_lookup_func) + + self.clex.build( + optimize=lex_optimize, + lextab=lextab) + self.tokens = self.clex.tokens + + rules_with_opt = [ + 'abstract_declarator', + 'constant_expression', + 'declaration_list', + 'declaration_specifiers', + 'expression', + 'identifier_list', + 'init_declarator_list', + 'parameter_type_list', + 'specifier_qualifier_list', + 'statement_list', + 'type_qualifier_list', + ] + + for rule in rules_with_opt: + self._create_opt_rule(rule) + + self.cparser = ply.yacc.yacc( + module=self, + start='translation_unit', + debug=yacc_debug, + optimize=yacc_optimize, + tabmodule=yacctab) + + # A table of identifiers defined as typedef types during + # parsing. # - if isinstance(decl, c_ast.TypeDecl): - modifier_tail.type = decl - return modifier - else: - # Otherwise, the decl is a list of modifiers. Reach - # its tail and splice the modifier onto the tail, - # pointing to the underlying basic type. - # - decl_tail = decl - - while not isinstance(decl_tail.type, c_ast.TypeDecl): - decl_tail = decl_tail.type - - modifier_tail.type = decl_tail.type - decl_tail.type = modifier_head - return decl - - # Due to the order in which declarators are constructed, - # they have to be fixed in order to look like a normal AST. - # - # When a declaration arrives from syntax construction, it has - # these problems: - # * The innermost TypeDecl has no type (because the basic - # type is only known at the uppermost declaration level) - # * The declaration has no variable name, since that is saved - # in the innermost TypeDecl - # * The typename of the declaration is a list of type - # specifiers, and not a node. Here, basic identifier types - # should be separated from more complex types like enums - # and structs. - # - # This method fixes these problem. - # - def _fix_decl_name_type(self, decl, typename): + self.typedef_table = set([]) + + def parse(self, text, filename='', debuglevel=0): + """ Parses C code and returns an AST. + + text: + A string containing the C source code + + filename: + Name of the file being parsed (for meaningful + error messages) + + debuglevel: + Debug level to yacc + """ + self.clex.filename = filename + self.clex.reset_lineno() + self.typedef_table = set([]) + return self.cparser.parse(text, lexer=self.clex, debug=debuglevel) + + ######################-- PRIVATE --###################### + + def _lex_error_func(self, msg, line, column): + self._parse_error(msg, self._coord(line, column)) + + def _lex_type_lookup_func(self, name): + """ Looks up types that were previously defined with + typedef. + Passed to the lexer for recognizing identifiers that + are types. + """ + return name in self.typedef_table + + def _add_typedef_type(self, name): + """ Adds names that were defined as new types with + typedef. + """ + self.typedef_table.add(name) + + # To understand what's going on here, read sections A.8.5 and + # A.8.6 of K&R2 very carefully. + # + # A C type consists of a basic type declaration, with a list + # of modifiers. For example: + # + # int *c[5]; + # + # The basic declaration here is 'int x', and the pointer and + # the array are the modifiers. + # + # Basic declarations are represented by TypeDecl (from module + # c_ast) and the modifiers are FuncDecl, PtrDecl and + # ArrayDecl. + # + # The standard states that whenever a new modifier is parsed, + # it should be added to the end of the list of modifiers. For + # example: + # + # K&R2 A.8.6.2: Array Declarators + # + # In a declaration T D where D has the form + # D1 [constant-expression-opt] + # and the type of the identifier in the declaration T D1 is + # "type-modifier T", the type of the + # identifier of D is "type-modifier array of T" + # + # This is what this method does. The declarator it receives + # can be a list of declarators ending with TypeDecl. It + # tacks the modifier to the end of this list, just before + # the TypeDecl. + # + # Additionally, the modifier may be a list itself. This is + # useful for pointers, that can come as a chain from the rule + # p_pointer. In this case, the whole modifier list is spliced + # into the new location. + # + def _type_modify_decl(self, decl, modifier): + """ Tacks a type modifier on a declarator, and returns + the modified declarator. + + Note: the declarator and modifier may be modified + """ + #~ print '****' + #~ decl.show(offset=3) + #~ modifier.show(offset=3) + #~ print '****' + + modifier_head = modifier + modifier_tail = modifier + + # The modifier may be a nested list. Reach its tail. + # + while modifier_tail.type: + modifier_tail = modifier_tail.type + + # If the decl is a basic type, just tack the modifier onto + # it + # + if isinstance(decl, c_ast.TypeDecl): + modifier_tail.type = decl + return modifier + else: + # Otherwise, the decl is a list of modifiers. Reach + # its tail and splice the modifier onto the tail, + # pointing to the underlying basic type. + # + decl_tail = decl + + while not isinstance(decl_tail.type, c_ast.TypeDecl): + decl_tail = decl_tail.type + + modifier_tail.type = decl_tail.type + decl_tail.type = modifier_head + return decl + + # Due to the order in which declarators are constructed, + # they have to be fixed in order to look like a normal AST. + # + # When a declaration arrives from syntax construction, it has + # these problems: + # * The innermost TypeDecl has no type (because the basic + # type is only known at the uppermost declaration level) + # * The declaration has no variable name, since that is saved + # in the innermost TypeDecl + # * The typename of the declaration is a list of type + # specifiers, and not a node. Here, basic identifier types + # should be separated from more complex types like enums + # and structs. + # + # This method fixes these problem. + # + def _fix_decl_name_type(self, decl, typename): """ Fixes a declaration. Modifies decl. - """ - # Reach the underlying basic type - # - type = decl - while not isinstance(type, c_ast.TypeDecl): - type = type.type - - decl.name = type.declname - type.quals = decl.quals - - # The typename is a list of types. If any type in this - # list isn't a simple string type, it must be the only - # type in the list (it's illegal to declare "int enum .." - # If all the types are basic, they're collected in the - # IdentifierType holder. - # - for tn in typename: - if not isinstance(tn, StringType): - if len(typename) > 1: - self._parse_error( - "Invalid multiple types specified", tn.coord) - else: - type.type = tn - return decl - - type.type = c_ast.IdentifierType(typename) + """ + # Reach the underlying basic type + # + type = decl + while not isinstance(type, c_ast.TypeDecl): + type = type.type + + decl.name = type.declname + type.quals = decl.quals + + # The typename is a list of types. If any type in this + # list isn't a simple string type, it must be the only + # type in the list (it's illegal to declare "int enum .." + # If all the types are basic, they're collected in the + # IdentifierType holder. + # + for tn in typename: + if not isinstance(tn, StringType): + if len(typename) > 1: + self._parse_error( + "Invalid multiple types specified", tn.coord) + else: + type.type = tn + return decl + + type.type = c_ast.IdentifierType(typename) return decl - - def _add_declaration_specifier(self, declspec, newspec, kind): - """ Declaration specifiers are represented by a dictionary - with 3 entries: - * qual: a list of type qualifiers - * storage: a list of storage type qualifiers - * type: a list of type specifiers - - This method is given a declaration specifier, and a - new specifier of a given kind. - Returns the declaration specifier, with the new - specifier incorporated. - """ - spec = declspec or dict(qual=[], storage=[], type=[]) - spec[kind].append(newspec) - return spec - - def _build_function_definition(self, decl, spec, param_decls, body): - """ Builds a function definition. - """ - declaration = c_ast.Decl( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=decl, - init=None, - bitsize=None, - coord=decl.coord) - - typename = spec['type'] - declaration = self._fix_decl_name_type(declaration, typename) - return c_ast.FuncDef( - decl=declaration, - param_decls=param_decls, - body=body, - coord=decl.coord) - + + def _add_declaration_specifier(self, declspec, newspec, kind): + """ Declaration specifiers are represented by a dictionary + with 3 entries: + * qual: a list of type qualifiers + * storage: a list of storage type qualifiers + * type: a list of type specifiers + + This method is given a declaration specifier, and a + new specifier of a given kind. + Returns the declaration specifier, with the new + specifier incorporated. + """ + spec = declspec or dict(qual=[], storage=[], type=[]) + spec[kind].append(newspec) + return spec + + def _build_function_definition(self, decl, spec, param_decls, body): + """ Builds a function definition. + """ + declaration = c_ast.Decl( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=decl, + init=None, + bitsize=None, + coord=decl.coord) + + typename = spec['type'] + declaration = self._fix_decl_name_type(declaration, typename) + return c_ast.FuncDef( + decl=declaration, + param_decls=param_decls, + body=body, + coord=decl.coord) + def _select_struct_union_class(self, token): - """ Given a token (either STRUCT or UNION), selects the + """ Given a token (either STRUCT or UNION), selects the appropriate AST class. - """ - if token == 'struct': - return c_ast.Struct - else: - return c_ast.Union - - ## - ## Precedence and associativity of operators - ## - precedence = ( - ('left', 'LOR'), - ('left', 'LAND'), - ('left', 'OR'), - ('left', 'XOR'), - ('left', 'AND'), - ('left', 'EQ', 'NE'), - ('left', 'GT', 'GE', 'LT', 'LE'), - ('left', 'RSHIFT', 'LSHIFT'), - ('left', 'PLUS', 'MINUS'), - ('left', 'TIMES', 'DIVIDE', 'MOD') - ) - - ## - ## Grammar productions - ## Implementation of the BNF defined in K&R2 A.13 - ## + """ + if token == 'struct': + return c_ast.Struct + else: + return c_ast.Union + + ## + ## Precedence and associativity of operators + ## + precedence = ( + ('left', 'LOR'), + ('left', 'LAND'), + ('left', 'OR'), + ('left', 'XOR'), + ('left', 'AND'), + ('left', 'EQ', 'NE'), + ('left', 'GT', 'GE', 'LT', 'LE'), + ('left', 'RSHIFT', 'LSHIFT'), + ('left', 'PLUS', 'MINUS'), + ('left', 'TIMES', 'DIVIDE', 'MOD') + ) + + ## + ## Grammar productions + ## Implementation of the BNF defined in K&R2 A.13 + ## def p_translation_unit_1(self, p): - """ translation_unit : external_declaration - """ - # Note: external_declaration is already a list - # - p[0] = c_ast.FileAST(p[1]) - + """ translation_unit : external_declaration + """ + # Note: external_declaration is already a list + # + p[0] = c_ast.FileAST(p[1]) + def p_translation_unit_2(self, p): """ translation_unit : translation_unit external_declaration - """ - p[1].ext.extend(p[2]) - p[0] = p[1] - - # Declarations always come as lists (because they can be - # several in one line), so we wrap the function definition - # into a list as well, to make the return value of - # external_declaration homogenous. - # + """ + p[1].ext.extend(p[2]) + p[0] = p[1] + + # Declarations always come as lists (because they can be + # several in one line), so we wrap the function definition + # into a list as well, to make the return value of + # external_declaration homogenous. + # def p_external_declaration_1(self, p): - """ external_declaration : function_definition - """ - p[0] = [p[1]] - - def p_external_declaration_2(self, p): + """ external_declaration : function_definition + """ + p[0] = [p[1]] + + def p_external_declaration_2(self, p): """ external_declaration : declaration - """ - p[0] = p[1] - + """ + p[0] = p[1] + def p_external_declaration_3(self, p): """ external_declaration : pp_directive - """ - p[0] = p[1] - + """ + p[0] = p[1] + def p_pp_directive(self, p): - """ pp_directive : PPHASH - """ - self._parse_error('Directives not supported yet', - self._coord(p.lineno(1))) - - # In function definitions, the declarator can be followed by - # a declaration list, for old "K&R style" function definitios. - # + """ pp_directive : PPHASH + """ + self._parse_error('Directives not supported yet', + self._coord(p.lineno(1))) + + # In function definitions, the declarator can be followed by + # a declaration list, for old "K&R style" function definitios. + # def p_function_definition_1(self, p): """ function_definition : declarator declaration_list_opt compound_statement - """ - # no declaration specifiers - spec = dict(qual=[], storage=[], type=[]) - - p[0] = self._build_function_definition( - decl=p[1], - spec=spec, - param_decls=p[2], - body=p[3]) - - def p_function_definition_2(self, p): - """ function_definition : declaration_specifiers declarator declaration_list_opt compound_statement - """ - spec = p[1] - - p[0] = self._build_function_definition( - decl=p[2], - spec=spec, - param_decls=p[3], - body=p[4]) - + """ + # no declaration specifiers + spec = dict(qual=[], storage=[], type=[]) + + p[0] = self._build_function_definition( + decl=p[1], + spec=spec, + param_decls=p[2], + body=p[3]) + + def p_function_definition_2(self, p): + """ function_definition : declaration_specifiers declarator declaration_list_opt compound_statement + """ + spec = p[1] + + p[0] = self._build_function_definition( + decl=p[2], + spec=spec, + param_decls=p[3], + body=p[4]) + def p_statement(self, p): - """ statement : labeled_statement - | expression_statement - | compound_statement - | selection_statement - | iteration_statement - | jump_statement - """ - p[0] = p[1] - - # In C, declarations can come several in a line: - # int x, *px, romulo = 5; - # - # However, for the AST, we will split them to separate Decl - # nodes. - # - # This rule splits its declarations and always returns a list - # of Decl nodes, even if it's one element long. - # + """ statement : labeled_statement + | expression_statement + | compound_statement + | selection_statement + | iteration_statement + | jump_statement + """ + p[0] = p[1] + + # In C, declarations can come several in a line: + # int x, *px, romulo = 5; + # + # However, for the AST, we will split them to separate Decl + # nodes. + # + # This rule splits its declarations and always returns a list + # of Decl nodes, even if it's one element long. + # def p_decl_body(self, p): """ decl_body : declaration_specifiers init_declarator_list_opt - """ - spec = p[1] - is_typedef = 'typedef' in spec['storage'] - decls = [] - - # p[2] (init_declarator_list_opt) is either a list or None - # - if p[2] is None: - # Then it's a declaration of a struct / enum tag, - # without an actual declarator. - # - type = spec['type'] - if len(type) > 1: - coord = '?' - for t in type: - if hasattr(t, 'coord'): - coord = t.coord - break - - self._parse_error('Multiple type specifiers with a type tag', coord) - - decl = c_ast.Decl( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=type[0], - init=None, - bitsize=None, - coord=type[0].coord) - decls = [decl] - else: - for decl, init in p[2] or []: - if is_typedef: - decl = c_ast.Typedef( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=decl, - coord=decl.coord) - else: - decl = c_ast.Decl( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=decl, - init=init, - bitsize=None, - coord=decl.coord) - - typename = spec['type'] - fixed_decl = self._fix_decl_name_type(decl, typename) - - # Add the type name defined by typedef to a - # symbol table (for usage in the lexer) - # - if is_typedef: - self._add_typedef_type(fixed_decl.name) - - decls.append(fixed_decl) - - p[0] = decls - - # The declaration has been split to a decl_body sub-rule and - # SEMI, because having them in a single rule created a problem - # for defining typedefs. - # - # If a typedef line was directly followed by a line using the - # type defined with the typedef, the type would not be - # recognized. This is because to reduce the declaration rule, - # the parser's lookahead asked for the token after SEMI, which - # was the type from the next line, and the lexer had no chance - # to see the updated type symbol table. - # - # Splitting solves this problem, because after seeing SEMI, - # the parser reduces decl_body, which actually adds the new - # type into the table to be seen by the lexer before the next - # line is reached. - # + """ + spec = p[1] + is_typedef = 'typedef' in spec['storage'] + decls = [] + + # p[2] (init_declarator_list_opt) is either a list or None + # + if p[2] is None: + # Then it's a declaration of a struct / enum tag, + # without an actual declarator. + # + type = spec['type'] + if len(type) > 1: + coord = '?' + for t in type: + if hasattr(t, 'coord'): + coord = t.coord + break + + self._parse_error('Multiple type specifiers with a type tag', coord) + + decl = c_ast.Decl( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=type[0], + init=None, + bitsize=None, + coord=type[0].coord) + decls = [decl] + else: + for decl, init in p[2] or []: + if is_typedef: + decl = c_ast.Typedef( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=decl, + coord=decl.coord) + else: + decl = c_ast.Decl( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=decl, + init=init, + bitsize=None, + coord=decl.coord) + + typename = spec['type'] + fixed_decl = self._fix_decl_name_type(decl, typename) + + # Add the type name defined by typedef to a + # symbol table (for usage in the lexer) + # + if is_typedef: + self._add_typedef_type(fixed_decl.name) + + decls.append(fixed_decl) + + p[0] = decls + + # The declaration has been split to a decl_body sub-rule and + # SEMI, because having them in a single rule created a problem + # for defining typedefs. + # + # If a typedef line was directly followed by a line using the + # type defined with the typedef, the type would not be + # recognized. This is because to reduce the declaration rule, + # the parser's lookahead asked for the token after SEMI, which + # was the type from the next line, and the lexer had no chance + # to see the updated type symbol table. + # + # Splitting solves this problem, because after seeing SEMI, + # the parser reduces decl_body, which actually adds the new + # type into the table to be seen by the lexer before the next + # line is reached. + # def p_declaration(self, p): - """ declaration : decl_body SEMI - """ - p[0] = p[1] - - # Since each declaration is a list of declarations, this - # rule will combine all the declarations and return a single - # list - # + """ declaration : decl_body SEMI + """ + p[0] = p[1] + + # Since each declaration is a list of declarations, this + # rule will combine all the declarations and return a single + # list + # def p_declaration_list(self, p): - """ declaration_list : declaration + """ declaration_list : declaration | declaration_list declaration - """ - p[0] = p[1] if len(p) == 2 else p[1] + p[2] - - def p_declaration_specifiers_1(self, p): - """ declaration_specifiers : type_qualifier declaration_specifiers_opt - """ - p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') - + """ + p[0] = p[1] if len(p) == 2 else p[1] + p[2] + + def p_declaration_specifiers_1(self, p): + """ declaration_specifiers : type_qualifier declaration_specifiers_opt + """ + p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') + def p_declaration_specifiers_2(self, p): - """ declaration_specifiers : type_specifier declaration_specifiers_opt - """ - p[0] = self._add_declaration_specifier(p[2], p[1], 'type') - - def p_declaration_specifiers_3(self, p): - """ declaration_specifiers : storage_class_specifier declaration_specifiers_opt - """ - p[0] = self._add_declaration_specifier(p[2], p[1], 'storage') - + """ declaration_specifiers : type_specifier declaration_specifiers_opt + """ + p[0] = self._add_declaration_specifier(p[2], p[1], 'type') + + def p_declaration_specifiers_3(self, p): + """ declaration_specifiers : storage_class_specifier declaration_specifiers_opt + """ + p[0] = self._add_declaration_specifier(p[2], p[1], 'storage') + def p_storage_class_specifier(self, p): - """ storage_class_specifier : AUTO - | REGISTER - | STATIC - | EXTERN + """ storage_class_specifier : AUTO + | REGISTER + | STATIC + | EXTERN | TYPEDEF - """ - p[0] = p[1] - + """ + p[0] = p[1] + def p_type_specifier_1(self, p): - """ type_specifier : VOID - | CHAR - | SHORT - | INT - | LONG - | FLOAT - | DOUBLE - | SIGNED - | UNSIGNED - | typedef_name - | enum_specifier - | struct_or_union_specifier - """ - p[0] = p[1] - + """ type_specifier : VOID + | CHAR + | SHORT + | INT + | LONG + | FLOAT + | DOUBLE + | SIGNED + | UNSIGNED + | typedef_name + | enum_specifier + | struct_or_union_specifier + """ + p[0] = p[1] + def p_type_qualifier(self, p): - """ type_qualifier : CONST + """ type_qualifier : CONST | VOLATILE - """ - p[0] = p[1] - + """ + p[0] = p[1] + def p_init_declarator_list(self, p): - """ init_declarator_list : init_declarator + """ init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator - """ - p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] - - # Returns a (declarator, intializer) pair - # If there's no initializer, returns (declarator, None) - # + """ + p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] + + # Returns a (declarator, intializer) pair + # If there's no initializer, returns (declarator, None) + # def p_init_declarator(self, p): - """ init_declarator : declarator + """ init_declarator : declarator | declarator EQUALS initializer - """ - p[0] = (p[1], p[3] if len(p) > 2 else None) - - def p_specifier_qualifier_list_1(self, p): - """ specifier_qualifier_list : type_qualifier specifier_qualifier_list_opt - """ - p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') - + """ + p[0] = (p[1], p[3] if len(p) > 2 else None) + + def p_specifier_qualifier_list_1(self, p): + """ specifier_qualifier_list : type_qualifier specifier_qualifier_list_opt + """ + p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') + def p_specifier_qualifier_list_2(self, p): - """ specifier_qualifier_list : type_specifier specifier_qualifier_list_opt - """ - p[0] = self._add_declaration_specifier(p[2], p[1], 'type') - - # TYPEID is allowed here (and in other struct/enum related tag names), because - # struct/enum tags reside in their own namespace and can be named the same as types - # + """ specifier_qualifier_list : type_specifier specifier_qualifier_list_opt + """ + p[0] = self._add_declaration_specifier(p[2], p[1], 'type') + + # TYPEID is allowed here (and in other struct/enum related tag names), because + # struct/enum tags reside in their own namespace and can be named the same as types + # def p_struct_or_union_specifier_1(self, p): - """ struct_or_union_specifier : struct_or_union ID + """ struct_or_union_specifier : struct_or_union ID | struct_or_union TYPEID - """ - klass = self._select_struct_union_class(p[1]) - p[0] = klass( - name=p[2], - decls=None, - coord=self._coord(p.lineno(2))) - + """ + klass = self._select_struct_union_class(p[1]) + p[0] = klass( + name=p[2], + decls=None, + coord=self._coord(p.lineno(2))) + def p_struct_or_union_specifier_2(self, p): """ struct_or_union_specifier : struct_or_union LBRACE struct_declaration_list RBRACE - """ - klass = self._select_struct_union_class(p[1]) - p[0] = klass( - name=None, - decls=p[3], - coord=self._coord(p.lineno(2))) - - def p_struct_or_union_specifier_3(self, p): - """ struct_or_union_specifier : struct_or_union ID LBRACE struct_declaration_list RBRACE - | struct_or_union TYPEID LBRACE struct_declaration_list RBRACE - """ - klass = self._select_struct_union_class(p[1]) - p[0] = klass( - name=p[2], - decls=p[4], - coord=self._coord(p.lineno(2))) - + """ + klass = self._select_struct_union_class(p[1]) + p[0] = klass( + name=None, + decls=p[3], + coord=self._coord(p.lineno(2))) + + def p_struct_or_union_specifier_3(self, p): + """ struct_or_union_specifier : struct_or_union ID LBRACE struct_declaration_list RBRACE + | struct_or_union TYPEID LBRACE struct_declaration_list RBRACE + """ + klass = self._select_struct_union_class(p[1]) + p[0] = klass( + name=p[2], + decls=p[4], + coord=self._coord(p.lineno(2))) + def p_struct_or_union(self, p): - """ struct_or_union : STRUCT + """ struct_or_union : STRUCT | UNION - """ - p[0] = p[1] - - # Combine all declarations into a single list - # + """ + p[0] = p[1] + + # Combine all declarations into a single list + # def p_struct_declaration_list(self, p): - """ struct_declaration_list : struct_declaration + """ struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration - """ - p[0] = p[1] if len(p) == 2 else p[1] + p[2] - + """ + p[0] = p[1] if len(p) == 2 else p[1] + p[2] + def p_struct_declaration_1(self, p): """ struct_declaration : specifier_qualifier_list struct_declarator_list SEMI - """ - spec = p[1] - decls = [] - - for struct_decl in p[2]: - decl = c_ast.Decl( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=struct_decl['decl'], - init=None, - bitsize=struct_decl['bitsize'], - coord=struct_decl['decl'].coord) - - typename = spec['type'] - decls.append(self._fix_decl_name_type(decl, typename)) - - p[0] = decls - + """ + spec = p[1] + decls = [] + + for struct_decl in p[2]: + decl = c_ast.Decl( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=struct_decl['decl'], + init=None, + bitsize=struct_decl['bitsize'], + coord=struct_decl['decl'].coord) + + typename = spec['type'] + decls.append(self._fix_decl_name_type(decl, typename)) + + p[0] = decls + def p_struct_declarator_list(self, p): - """ struct_declarator_list : struct_declarator + """ struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator - """ - p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] - - # struct_declarator passes up a dict with the keys: decl (for - # the underlying declarator) and bitsize (for the bitsize) - # + """ + p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] + + # struct_declarator passes up a dict with the keys: decl (for + # the underlying declarator) and bitsize (for the bitsize) + # def p_struct_declarator_1(self, p): """ struct_declarator : declarator - """ - p[0] = {'decl': p[1], 'bitsize': None} - + """ + p[0] = {'decl': p[1], 'bitsize': None} + def p_struct_declarator_2(self, p): - """ struct_declarator : declarator COLON constant_expression + """ struct_declarator : declarator COLON constant_expression | COLON constant_expression - """ - if len(p) > 3: - p[0] = {'decl': p[1], 'bitsize': p[3]} - else: - p[0] = {'decl': None, 'bitsize': p[2]} - + """ + if len(p) > 3: + p[0] = {'decl': p[1], 'bitsize': p[3]} + else: + p[0] = {'decl': None, 'bitsize': p[2]} + def p_enum_specifier_1(self, p): - """ enum_specifier : ENUM ID - | ENUM TYPEID - """ - p[0] = c_ast.Enum(p[2], None, self._coord(p.lineno(1))) - - def p_enum_specifier_2(self, p): - """ enum_specifier : ENUM LBRACE enumerator_list RBRACE - """ - p[0] = c_ast.Enum(None, p[3], self._coord(p.lineno(1))) - - def p_enum_specifier_3(self, p): - """ enum_specifier : ENUM ID LBRACE enumerator_list RBRACE - | ENUM TYPEID LBRACE enumerator_list RBRACE - """ - p[0] = c_ast.Enum(p[2], p[4], self._coord(p.lineno(1))) - + """ enum_specifier : ENUM ID + | ENUM TYPEID + """ + p[0] = c_ast.Enum(p[2], None, self._coord(p.lineno(1))) + + def p_enum_specifier_2(self, p): + """ enum_specifier : ENUM LBRACE enumerator_list RBRACE + """ + p[0] = c_ast.Enum(None, p[3], self._coord(p.lineno(1))) + + def p_enum_specifier_3(self, p): + """ enum_specifier : ENUM ID LBRACE enumerator_list RBRACE + | ENUM TYPEID LBRACE enumerator_list RBRACE + """ + p[0] = c_ast.Enum(p[2], p[4], self._coord(p.lineno(1))) + def p_enumerator_list(self, p): - """ enumerator_list : enumerator - | enumerator_list COMMA + """ enumerator_list : enumerator + | enumerator_list COMMA | enumerator_list COMMA enumerator - """ - if len(p) == 2: - p[0] = c_ast.EnumeratorList([p[1]], p[1].coord) - elif len(p) == 3: - p[0] = p[1] - else: - p[1].enumerators.append(p[3]) - p[0] = p[1] - + """ + if len(p) == 2: + p[0] = c_ast.EnumeratorList([p[1]], p[1].coord) + elif len(p) == 3: + p[0] = p[1] + else: + p[1].enumerators.append(p[3]) + p[0] = p[1] + def p_enumerator(self, p): - """ enumerator : ID + """ enumerator : ID | ID EQUALS constant_expression - """ - if len(p) == 2: - p[0] = c_ast.Enumerator( - p[1], None, - self._coord(p.lineno(1))) - else: - p[0] = c_ast.Enumerator( - p[1], p[3], - self._coord(p.lineno(1))) - + """ + if len(p) == 2: + p[0] = c_ast.Enumerator( + p[1], None, + self._coord(p.lineno(1))) + else: + p[0] = c_ast.Enumerator( + p[1], p[3], + self._coord(p.lineno(1))) + def p_declarator_1(self, p): - """ declarator : direct_declarator - """ - p[0] = p[1] - + """ declarator : direct_declarator + """ + p[0] = p[1] + def p_declarator_2(self, p): - """ declarator : pointer direct_declarator - """ - p[0] = self._type_modify_decl(p[2], p[1]) - + """ declarator : pointer direct_declarator + """ + p[0] = self._type_modify_decl(p[2], p[1]) + def p_direct_declarator_1(self, p): - """ direct_declarator : ID - """ - p[0] = c_ast.TypeDecl( - declname=p[1], - type=None, - quals=None, - coord=self._coord(p.lineno(1))) - - def p_direct_declarator_2(self, p): - """ direct_declarator : LPAREN declarator RPAREN - """ - p[0] = p[2] - - def p_direct_declarator_3(self, p): - """ direct_declarator : direct_declarator LBRACKET constant_expression_opt RBRACKET - """ - arr = c_ast.ArrayDecl( - type=None, - dim=p[3], - coord=p[1].coord) - - p[0] = self._type_modify_decl(decl=p[1], modifier=arr) - - def p_direct_declarator_4(self, p): - """ direct_declarator : direct_declarator LPAREN parameter_type_list RPAREN - | direct_declarator LPAREN identifier_list_opt RPAREN - """ - func = c_ast.FuncDecl( - args=p[3], - type=None, - coord=p[1].coord) - - p[0] = self._type_modify_decl(decl=p[1], modifier=func) - + """ direct_declarator : ID + """ + p[0] = c_ast.TypeDecl( + declname=p[1], + type=None, + quals=None, + coord=self._coord(p.lineno(1))) + + def p_direct_declarator_2(self, p): + """ direct_declarator : LPAREN declarator RPAREN + """ + p[0] = p[2] + + def p_direct_declarator_3(self, p): + """ direct_declarator : direct_declarator LBRACKET constant_expression_opt RBRACKET + """ + arr = c_ast.ArrayDecl( + type=None, + dim=p[3], + coord=p[1].coord) + + p[0] = self._type_modify_decl(decl=p[1], modifier=arr) + + def p_direct_declarator_4(self, p): + """ direct_declarator : direct_declarator LPAREN parameter_type_list RPAREN + | direct_declarator LPAREN identifier_list_opt RPAREN + """ + func = c_ast.FuncDecl( + args=p[3], + type=None, + coord=p[1].coord) + + p[0] = self._type_modify_decl(decl=p[1], modifier=func) + def p_pointer(self, p): - """ pointer : TIMES type_qualifier_list_opt + """ pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer - """ - coord = self._coord(p.lineno(1)) - - p[0] = c_ast.PtrDecl( - quals=p[2] or [], - type=p[3] if len(p) > 3 else None, - coord=coord) - + """ + coord = self._coord(p.lineno(1)) + + p[0] = c_ast.PtrDecl( + quals=p[2] or [], + type=p[3] if len(p) > 3 else None, + coord=coord) + def p_type_qualifier_list(self, p): - """ type_qualifier_list : type_qualifier + """ type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier - """ - p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]] - - def p_parameter_type_list(self, p): - """ parameter_type_list : parameter_list - | parameter_list COMMA ELLIPSIS - """ - if len(p) > 2: - p[1].params.append(c_ast.EllipsisParam()) - - p[0] = p[1] - + """ + p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]] + + def p_parameter_type_list(self, p): + """ parameter_type_list : parameter_list + | parameter_list COMMA ELLIPSIS + """ + if len(p) > 2: + p[1].params.append(c_ast.EllipsisParam()) + + p[0] = p[1] + def p_parameter_list(self, p): - """ parameter_list : parameter_declaration + """ parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration - """ - if len(p) == 2: # single parameter - p[0] = c_ast.ParamList([p[1]], p[1].coord) - else: - p[1].params.append(p[3]) - p[0] = p[1] - + """ + if len(p) == 2: # single parameter + p[0] = c_ast.ParamList([p[1]], p[1].coord) + else: + p[1].params.append(p[3]) + p[0] = p[1] + def p_parameter_declaration_1(self, p): - """ parameter_declaration : declaration_specifiers declarator - """ - spec = p[1] - decl = p[2] - - decl = c_ast.Decl( - name=None, - quals=spec['qual'], - storage=spec['storage'], - type=decl, - init=None, - bitsize=None, - coord=decl.coord) - - typename = spec['type'] or ['int'] - p[0] = self._fix_decl_name_type(decl, typename) - + """ parameter_declaration : declaration_specifiers declarator + """ + spec = p[1] + decl = p[2] + + decl = c_ast.Decl( + name=None, + quals=spec['qual'], + storage=spec['storage'], + type=decl, + init=None, + bitsize=None, + coord=decl.coord) + + typename = spec['type'] or ['int'] + p[0] = self._fix_decl_name_type(decl, typename) + def p_parameter_declaration_2(self, p): """ parameter_declaration : declaration_specifiers abstract_declarator_opt - """ - spec = p[1] - decl = c_ast.Typename( - quals=spec['qual'], - type=p[2] or c_ast.TypeDecl(None, None, None)) - - typename = spec['type'] or ['int'] - - p[0] = self._fix_decl_name_type(decl, typename) - + """ + spec = p[1] + decl = c_ast.Typename( + quals=spec['qual'], + type=p[2] or c_ast.TypeDecl(None, None, None)) + + typename = spec['type'] or ['int'] + + p[0] = self._fix_decl_name_type(decl, typename) + def p_identifier_list(self, p): - """ identifier_list : identifier + """ identifier_list : identifier | identifier_list COMMA identifier - """ - if len(p) == 2: # single parameter - p[0] = c_ast.ParamList([p[1]], p[1].coord) - else: - p[1].params.append(p[3]) - p[0] = p[1] - + """ + if len(p) == 2: # single parameter + p[0] = c_ast.ParamList([p[1]], p[1].coord) + else: + p[1].params.append(p[3]) + p[0] = p[1] + def p_initializer_1(self, p): """ initializer : assignment_expression - """ - p[0] = p[1] - + """ + p[0] = p[1] + def p_initializer_2(self, p): - """ initializer : LBRACE initializer_list RBRACE + """ initializer : LBRACE initializer_list RBRACE | LBRACE initializer_list COMMA RBRACE - """ - p[0] = p[2] - + """ + p[0] = p[2] + def p_initializer_list(self, p): - """ initializer_list : initializer - | initializer_list COMMA initializer - """ - if len(p) == 2: # single initializer - p[0] = c_ast.ExprList([p[1]], p[1].coord) - else: - p[1].exprs.append(p[3]) - p[0] = p[1] - + """ initializer_list : initializer + | initializer_list COMMA initializer + """ + if len(p) == 2: # single initializer + p[0] = c_ast.ExprList([p[1]], p[1].coord) + else: + p[1].exprs.append(p[3]) + p[0] = p[1] + def p_type_name(self, p): - """ type_name : specifier_qualifier_list abstract_declarator_opt - """ - #~ print '==========' - #~ print p[1] - #~ print p[2] - #~ print p[2].children() - #~ print '==========' - - typename = c_ast.Typename( - quals=p[1]['qual'], - type=p[2] or c_ast.TypeDecl(None, None, None)) - - p[0] = self._fix_decl_name_type(typename, p[1]['type']) - + """ type_name : specifier_qualifier_list abstract_declarator_opt + """ + #~ print '==========' + #~ print p[1] + #~ print p[2] + #~ print p[2].children() + #~ print '==========' + + typename = c_ast.Typename( + quals=p[1]['qual'], + type=p[2] or c_ast.TypeDecl(None, None, None)) + + p[0] = self._fix_decl_name_type(typename, p[1]['type']) + def p_abstract_declarator_1(self, p): - """ abstract_declarator : pointer - """ - dummytype = c_ast.TypeDecl(None, None, None) - p[0] = self._type_modify_decl( - decl=dummytype, - modifier=p[1]) - + """ abstract_declarator : pointer + """ + dummytype = c_ast.TypeDecl(None, None, None) + p[0] = self._type_modify_decl( + decl=dummytype, + modifier=p[1]) + def p_abstract_declarator_2(self, p): - """ abstract_declarator : pointer direct_abstract_declarator - """ - p[0] = self._type_modify_decl(p[2], p[1]) - + """ abstract_declarator : pointer direct_abstract_declarator + """ + p[0] = self._type_modify_decl(p[2], p[1]) + def p_abstract_declarator_3(self, p): """ abstract_declarator : direct_abstract_declarator - """ - p[0] = p[1] - - # Creating and using direct_abstract_declarator_opt here - # instead of listing both direct_abstract_declarator and the - # lack of it in the beginning of _1 and _2 caused two - # shift/reduce errors. - # + """ + p[0] = p[1] + + # Creating and using direct_abstract_declarator_opt here + # instead of listing both direct_abstract_declarator and the + # lack of it in the beginning of _1 and _2 caused two + # shift/reduce errors. + # def p_direct_abstract_declarator_1(self, p): - """ direct_abstract_declarator : LPAREN abstract_declarator RPAREN """ - p[0] = p[2] - + """ direct_abstract_declarator : LPAREN abstract_declarator RPAREN """ + p[0] = p[2] + def p_direct_abstract_declarator_2(self, p): - """ direct_abstract_declarator : direct_abstract_declarator LBRACKET constant_expression_opt RBRACKET - """ - arr = c_ast.ArrayDecl( - type=None, - dim=p[3], - coord=p[1].coord) - - p[0] = self._type_modify_decl(decl=p[1], modifier=arr) - - def p_direct_abstract_declarator_3(self, p): - """ direct_abstract_declarator : LBRACKET constant_expression_opt RBRACKET - """ - p[0] = c_ast.ArrayDecl( - type=c_ast.TypeDecl(None, None, None), - dim=p[2], - coord=self._coord(p.lineno(1))) - + """ direct_abstract_declarator : direct_abstract_declarator LBRACKET constant_expression_opt RBRACKET + """ + arr = c_ast.ArrayDecl( + type=None, + dim=p[3], + coord=p[1].coord) + + p[0] = self._type_modify_decl(decl=p[1], modifier=arr) + + def p_direct_abstract_declarator_3(self, p): + """ direct_abstract_declarator : LBRACKET constant_expression_opt RBRACKET + """ + p[0] = c_ast.ArrayDecl( + type=c_ast.TypeDecl(None, None, None), + dim=p[2], + coord=self._coord(p.lineno(1))) + def p_direct_abstract_declarator_4(self, p): - """ direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN - """ - func = c_ast.FuncDecl( - args=p[3], - type=None, - coord=p[1].coord) - - p[0] = self._type_modify_decl(decl=p[1], modifier=func) - - def p_direct_abstract_declarator_5(self, p): - """ direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN - """ - p[0] = c_ast.FuncDecl( - args=p[2], - type=c_ast.TypeDecl(None, None, None), - coord=p[1].coord) - + """ direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN + """ + func = c_ast.FuncDecl( + args=p[3], + type=None, + coord=p[1].coord) + + p[0] = self._type_modify_decl(decl=p[1], modifier=func) + + def p_direct_abstract_declarator_5(self, p): + """ direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN + """ + p[0] = c_ast.FuncDecl( + args=p[2], + type=c_ast.TypeDecl(None, None, None), + coord=p[1].coord) + def p_compound_statement_1(self, p): - """ compound_statement : LBRACE statement_list_opt RBRACE """ - p[0] = c_ast.Compound( - decls=None, - stmts=p[2], - coord=self._coord(p.lineno(1))) - - def p_compound_statement_2(self, p): - """ compound_statement : LBRACE declaration_list RBRACE """ - p[0] = c_ast.Compound( - decls=p[2], - stmts=None, - coord=self._coord(p.lineno(1))) - - def p_compound_statement_3(self, p): - """ compound_statement : LBRACE declaration_list statement_list RBRACE """ - #~ print '((((((' - #~ print p[2] - #~ print p[3] - #~ print '((((((' - p[0] = c_ast.Compound( - decls=p[2], - stmts=p[3], - coord=self._coord(p.lineno(1))) - - # Note: this doesn't create an AST node, but a list of AST - # nodes that will be used as the statement list of a compound - # + """ compound_statement : LBRACE statement_list_opt RBRACE """ + p[0] = c_ast.Compound( + decls=None, + stmts=p[2], + coord=self._coord(p.lineno(1))) + + def p_compound_statement_2(self, p): + """ compound_statement : LBRACE declaration_list RBRACE """ + p[0] = c_ast.Compound( + decls=p[2], + stmts=None, + coord=self._coord(p.lineno(1))) + + def p_compound_statement_3(self, p): + """ compound_statement : LBRACE declaration_list statement_list RBRACE """ + #~ print '((((((' + #~ print p[2] + #~ print p[3] + #~ print '((((((' + p[0] = c_ast.Compound( + decls=p[2], + stmts=p[3], + coord=self._coord(p.lineno(1))) + + # Note: this doesn't create an AST node, but a list of AST + # nodes that will be used as the statement list of a compound + # def p_statement_list(self, p): - """ statement_list : statement - | statement_list statement - """ - if len(p) == 2: # single expr - p[0] = [p[1]] if p[1] else [] - else: - p[0] = p[1] + ([p[2]] if p[2] else []) - + """ statement_list : statement + | statement_list statement + """ + if len(p) == 2: # single expr + p[0] = [p[1]] if p[1] else [] + else: + p[0] = p[1] + ([p[2]] if p[2] else []) + def p_labeled_statement_1(self, p): - """ labeled_statement : ID COLON statement """ - p[0] = c_ast.Label(p[1], p[3], self._coord(p.lineno(1))) - - def p_labeled_statement_2(self, p): - """ labeled_statement : CASE constant_expression COLON statement """ - p[0] = c_ast.Case(p[2], p[4], self._coord(p.lineno(1))) - - def p_labeled_statement_3(self, p): - """ labeled_statement : DEFAULT COLON statement """ - p[0] = c_ast.Default(p[3], self._coord(p.lineno(1))) - + """ labeled_statement : ID COLON statement """ + p[0] = c_ast.Label(p[1], p[3], self._coord(p.lineno(1))) + + def p_labeled_statement_2(self, p): + """ labeled_statement : CASE constant_expression COLON statement """ + p[0] = c_ast.Case(p[2], p[4], self._coord(p.lineno(1))) + + def p_labeled_statement_3(self, p): + """ labeled_statement : DEFAULT COLON statement """ + p[0] = c_ast.Default(p[3], self._coord(p.lineno(1))) + def p_selection_statement_1(self, p): - """ selection_statement : IF LPAREN expression RPAREN statement """ - p[0] = c_ast.If(p[3], p[5], None, self._coord(p.lineno(1))) - + """ selection_statement : IF LPAREN expression RPAREN statement """ + p[0] = c_ast.If(p[3], p[5], None, self._coord(p.lineno(1))) + def p_selection_statement_2(self, p): - """ selection_statement : IF LPAREN expression RPAREN statement ELSE statement """ - p[0] = c_ast.If(p[3], p[5], p[7], self._coord(p.lineno(1))) - + """ selection_statement : IF LPAREN expression RPAREN statement ELSE statement """ + p[0] = c_ast.If(p[3], p[5], p[7], self._coord(p.lineno(1))) + def p_selection_statement_3(self, p): - """ selection_statement : SWITCH LPAREN expression RPAREN statement """ - p[0] = c_ast.Switch(p[3], p[5], self._coord(p.lineno(1))) - + """ selection_statement : SWITCH LPAREN expression RPAREN statement """ + p[0] = c_ast.Switch(p[3], p[5], self._coord(p.lineno(1))) + def p_iteration_statement_1(self, p): - """ iteration_statement : WHILE LPAREN expression RPAREN statement """ - p[0] = c_ast.While(p[3], p[5], self._coord(p.lineno(1))) - + """ iteration_statement : WHILE LPAREN expression RPAREN statement """ + p[0] = c_ast.While(p[3], p[5], self._coord(p.lineno(1))) + def p_iteration_statement_2(self, p): - """ iteration_statement : DO statement WHILE LPAREN expression RPAREN """ - p[0] = c_ast.DoWhile(p[5], p[2], self._coord(p.lineno(1))) - + """ iteration_statement : DO statement WHILE LPAREN expression RPAREN """ + p[0] = c_ast.DoWhile(p[5], p[2], self._coord(p.lineno(1))) + def p_iteration_statement_3(self, p): - """ iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement """ - p[0] = c_ast.For(p[3], p[5], p[7], p[9], self._coord(p.lineno(1))) - + """ iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement """ + p[0] = c_ast.For(p[3], p[5], p[7], p[9], self._coord(p.lineno(1))) + def p_jump_statement_1(self, p): - """ jump_statement : GOTO ID SEMI """ - p[0] = c_ast.Goto(p[2], self._coord(p.lineno(1))) - - def p_jump_statement_2(self, p): - """ jump_statement : BREAK SEMI """ - p[0] = c_ast.Break(self._coord(p.lineno(1))) - - def p_jump_statement_3(self, p): - """ jump_statement : CONTINUE SEMI """ - p[0] = c_ast.Continue(self._coord(p.lineno(1))) - - def p_jump_statement_4(self, p): - """ jump_statement : RETURN expression SEMI - | RETURN SEMI - """ - p[0] = c_ast.Return(p[2] if len(p) == 4 else None, self._coord(p.lineno(1))) - + """ jump_statement : GOTO ID SEMI """ + p[0] = c_ast.Goto(p[2], self._coord(p.lineno(1))) + + def p_jump_statement_2(self, p): + """ jump_statement : BREAK SEMI """ + p[0] = c_ast.Break(self._coord(p.lineno(1))) + + def p_jump_statement_3(self, p): + """ jump_statement : CONTINUE SEMI """ + p[0] = c_ast.Continue(self._coord(p.lineno(1))) + + def p_jump_statement_4(self, p): + """ jump_statement : RETURN expression SEMI + | RETURN SEMI + """ + p[0] = c_ast.Return(p[2] if len(p) == 4 else None, self._coord(p.lineno(1))) + def p_expression_statement(self, p): - """ expression_statement : expression_opt SEMI """ - p[0] = p[1] - - def p_expression(self, p): - """ expression : assignment_expression - | expression COMMA assignment_expression - """ - if len(p) == 2: - p[0] = p[1] - else: - if not isinstance(p[1], c_ast.ExprList): - p[1] = c_ast.ExprList([p[1]], p[1].coord) - - p[1].exprs.append(p[3]) - p[0] = p[1] - - def p_typedef_name(self, p): - """ typedef_name : TYPEID """ - p[0] = p[1] - + """ expression_statement : expression_opt SEMI """ + p[0] = p[1] + + def p_expression(self, p): + """ expression : assignment_expression + | expression COMMA assignment_expression + """ + if len(p) == 2: + p[0] = p[1] + else: + if not isinstance(p[1], c_ast.ExprList): + p[1] = c_ast.ExprList([p[1]], p[1].coord) + + p[1].exprs.append(p[3]) + p[0] = p[1] + + def p_typedef_name(self, p): + """ typedef_name : TYPEID """ + p[0] = p[1] + def p_assignment_expression(self, p): - """ assignment_expression : conditional_expression + """ assignment_expression : conditional_expression | unary_expression assignment_operator assignment_expression - """ - if len(p) == 2: - p[0] = p[1] - else: - p[0] = c_ast.Assignment(p[2], p[1], p[3], p[1].coord) - - # K&R2 defines these as many separate rules, to encode - # precedence and associativity. Why work hard ? I'll just use - # the built in precedence/associativity specification feature - # of PLY. (see precedence declaration above) - # + """ + if len(p) == 2: + p[0] = p[1] + else: + p[0] = c_ast.Assignment(p[2], p[1], p[3], p[1].coord) + + # K&R2 defines these as many separate rules, to encode + # precedence and associativity. Why work hard ? I'll just use + # the built in precedence/associativity specification feature + # of PLY. (see precedence declaration above) + # def p_assignment_operator(self, p): - """ assignment_operator : EQUALS - | XOREQUAL - | TIMESEQUAL - | DIVEQUAL - | MODEQUAL - | PLUSEQUAL - | MINUSEQUAL - | LSHIFTEQUAL - | RSHIFTEQUAL - | ANDEQUAL - | OREQUAL - """ - p[0] = p[1] - + """ assignment_operator : EQUALS + | XOREQUAL + | TIMESEQUAL + | DIVEQUAL + | MODEQUAL + | PLUSEQUAL + | MINUSEQUAL + | LSHIFTEQUAL + | RSHIFTEQUAL + | ANDEQUAL + | OREQUAL + """ + p[0] = p[1] + def p_constant_expression(self, p): - """ constant_expression : conditional_expression """ - p[0] = p[1] - + """ constant_expression : conditional_expression """ + p[0] = p[1] + def p_conditional_expression(self, p): - """ conditional_expression : binary_expression + """ conditional_expression : binary_expression | binary_expression CONDOP expression COLON conditional_expression - """ - if len(p) == 2: - p[0] = p[1] - else: - p[0] = c_ast.TernaryOp(p[1], p[3], p[5], p[1].coord) - + """ + if len(p) == 2: + p[0] = p[1] + else: + p[0] = c_ast.TernaryOp(p[1], p[3], p[5], p[1].coord) + def p_binary_expression(self, p): - """ binary_expression : cast_expression - | binary_expression TIMES binary_expression - | binary_expression DIVIDE binary_expression - | binary_expression MOD binary_expression - | binary_expression PLUS binary_expression - | binary_expression MINUS binary_expression - | binary_expression RSHIFT binary_expression - | binary_expression LSHIFT binary_expression - | binary_expression LT binary_expression - | binary_expression LE binary_expression - | binary_expression GE binary_expression - | binary_expression GT binary_expression - | binary_expression EQ binary_expression - | binary_expression NE binary_expression - | binary_expression AND binary_expression - | binary_expression OR binary_expression - | binary_expression XOR binary_expression - | binary_expression LAND binary_expression + """ binary_expression : cast_expression + | binary_expression TIMES binary_expression + | binary_expression DIVIDE binary_expression + | binary_expression MOD binary_expression + | binary_expression PLUS binary_expression + | binary_expression MINUS binary_expression + | binary_expression RSHIFT binary_expression + | binary_expression LSHIFT binary_expression + | binary_expression LT binary_expression + | binary_expression LE binary_expression + | binary_expression GE binary_expression + | binary_expression GT binary_expression + | binary_expression EQ binary_expression + | binary_expression NE binary_expression + | binary_expression AND binary_expression + | binary_expression OR binary_expression + | binary_expression XOR binary_expression + | binary_expression LAND binary_expression | binary_expression LOR binary_expression - """ - if len(p) == 2: - p[0] = p[1] - else: - p[0] = c_ast.BinaryOp(p[2], p[1], p[3], p[1].coord) - + """ + if len(p) == 2: + p[0] = p[1] + else: + p[0] = c_ast.BinaryOp(p[2], p[1], p[3], p[1].coord) + def p_cast_expression_1(self, p): - """ cast_expression : unary_expression """ - p[0] = p[1] - - def p_cast_expression_2(self, p): - """ cast_expression : LPAREN type_name RPAREN cast_expression """ - p[0] = c_ast.Cast(p[2], p[4], p[2].coord) - + """ cast_expression : unary_expression """ + p[0] = p[1] + + def p_cast_expression_2(self, p): + """ cast_expression : LPAREN type_name RPAREN cast_expression """ + p[0] = c_ast.Cast(p[2], p[4], p[2].coord) + def p_unary_expression_1(self, p): - """ unary_expression : postfix_expression """ - p[0] = p[1] - + """ unary_expression : postfix_expression """ + p[0] = p[1] + def p_unary_expression_2(self, p): - """ unary_expression : PLUSPLUS unary_expression - | MINUSMINUS unary_expression - | unary_operator cast_expression - """ - p[0] = c_ast.UnaryOp(p[1], p[2], p[2].coord) - - def p_unary_expression_3(self, p): - """ unary_expression : SIZEOF unary_expression - | SIZEOF LPAREN type_name RPAREN - """ - p[0] = c_ast.UnaryOp( - p[1], - p[2] if len(p) == 3 else p[3], - self._coord(p.lineno(1))) - + """ unary_expression : PLUSPLUS unary_expression + | MINUSMINUS unary_expression + | unary_operator cast_expression + """ + p[0] = c_ast.UnaryOp(p[1], p[2], p[2].coord) + + def p_unary_expression_3(self, p): + """ unary_expression : SIZEOF unary_expression + | SIZEOF LPAREN type_name RPAREN + """ + p[0] = c_ast.UnaryOp( + p[1], + p[2] if len(p) == 3 else p[3], + self._coord(p.lineno(1))) + def p_unary_operator(self, p): - """ unary_operator : AND - | TIMES - | PLUS - | MINUS - | NOT - | LNOT - """ - p[0] = p[1] - + """ unary_operator : AND + | TIMES + | PLUS + | MINUS + | NOT + | LNOT + """ + p[0] = p[1] + def p_postfix_exptession_1(self, p): - """ postfix_expression : primary_expression """ - p[0] = p[1] - - def p_postfix_exptession_2(self, p): - """ postfix_expression : postfix_expression LBRACKET expression RBRACKET """ - p[0] = c_ast.ArrayRef(p[1], p[3], p[1].coord) - + """ postfix_expression : primary_expression """ + p[0] = p[1] + + def p_postfix_exptession_2(self, p): + """ postfix_expression : postfix_expression LBRACKET expression RBRACKET """ + p[0] = c_ast.ArrayRef(p[1], p[3], p[1].coord) + def p_postfix_exptession_3(self, p): - """ postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN + """ postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN - """ - p[0] = c_ast.FuncCall(p[1], p[3] if len(p) == 5 else None) - + """ + p[0] = c_ast.FuncCall(p[1], p[3] if len(p) == 5 else None) + def p_postfix_expression_4(self, p): - """ postfix_expression : postfix_expression PERIOD identifier - | postfix_expression ARROW identifier - """ - p[0] = c_ast.StructRef(p[1], p[2], p[3], p[1].coord) - + """ postfix_expression : postfix_expression PERIOD identifier + | postfix_expression ARROW identifier + """ + p[0] = c_ast.StructRef(p[1], p[2], p[3], p[1].coord) + def p_postfix_expression_5(self, p): - """ postfix_expression : postfix_expression PLUSPLUS - | postfix_expression MINUSMINUS - """ - p[0] = c_ast.UnaryOp('p' + p[2], p[1], p[1].coord) - + """ postfix_expression : postfix_expression PLUSPLUS + | postfix_expression MINUSMINUS + """ + p[0] = c_ast.UnaryOp('p' + p[2], p[1], p[1].coord) + def p_primary_expression_1(self, p): - """ primary_expression : identifier """ - p[0] = p[1] - - def p_primary_expression_2(self, p): - """ primary_expression : constant """ - p[0] = p[1] - - def p_primary_expression_3(self, p): - """ primary_expression : STRING_LITERAL - | WSTRING_LITERAL - """ - p[0] = c_ast.Constant( - 'string', p[1], self._coord(p.lineno(1))) - + """ primary_expression : identifier """ + p[0] = p[1] + + def p_primary_expression_2(self, p): + """ primary_expression : constant """ + p[0] = p[1] + + def p_primary_expression_3(self, p): + """ primary_expression : STRING_LITERAL + | WSTRING_LITERAL + """ + p[0] = c_ast.Constant( + 'string', p[1], self._coord(p.lineno(1))) + def p_primary_expression_4(self, p): - """ primary_expression : LPAREN expression RPAREN """ - p[0] = p[2] - + """ primary_expression : LPAREN expression RPAREN """ + p[0] = p[2] + def p_argument_expression_list(self, p): - """ argument_expression_list : assignment_expression - | argument_expression_list COMMA assignment_expression - """ - if len(p) == 2: # single expr - p[0] = c_ast.ExprList([p[1]], p[1].coord) - else: - p[1].exprs.append(p[3]) - p[0] = p[1] - + """ argument_expression_list : assignment_expression + | argument_expression_list COMMA assignment_expression + """ + if len(p) == 2: # single expr + p[0] = c_ast.ExprList([p[1]], p[1].coord) + else: + p[1].exprs.append(p[3]) + p[0] = p[1] + def p_identifier(self, p): - """ identifier : ID """ - p[0] = c_ast.ID(p[1], self._coord(p.lineno(1))) - + """ identifier : ID """ + p[0] = c_ast.ID(p[1], self._coord(p.lineno(1))) + def p_constant_1(self, p): - """ constant : INT_CONST_DEC - | INT_CONST_OCT - | INT_CONST_HEX - """ - p[0] = c_ast.Constant( - 'int', p[1], self._coord(p.lineno(1))) - - def p_constant_2(self, p): - """ constant : FLOAT_CONST """ - p[0] = c_ast.Constant( - 'float', p[1], self._coord(p.lineno(1))) - + """ constant : INT_CONST_DEC + | INT_CONST_OCT + | INT_CONST_HEX + """ + p[0] = c_ast.Constant( + 'int', p[1], self._coord(p.lineno(1))) + + def p_constant_2(self, p): + """ constant : FLOAT_CONST """ + p[0] = c_ast.Constant( + 'float', p[1], self._coord(p.lineno(1))) + def p_constant_3(self, p): - """ constant : CHAR_CONST - | WCHAR_CONST - """ - p[0] = c_ast.Constant( - 'char', p[1], self._coord(p.lineno(1))) - - def p_empty(self, p): - 'empty : ' - p[0] = None - - def p_error(self, p): + """ constant : CHAR_CONST + | WCHAR_CONST + """ + p[0] = c_ast.Constant( + 'char', p[1], self._coord(p.lineno(1))) + + def p_empty(self, p): + 'empty : ' + p[0] = None + + def p_error(self, p): if p: - self._parse_error( - 'before: %s' % p.value, - self._coord(p.lineno)) - else: - self._parse_error('At end of input', '') - - -if __name__ == "__main__": - import pprint - import time - + self._parse_error( + 'before: %s' % p.value, + self._coord(p.lineno)) + else: + self._parse_error('At end of input', '') + + +if __name__ == "__main__": + import pprint + import time + t1 = time.time() - parser = CParser(lex_optimize=True, yacc_debug=True, yacc_optimize=False) - print time.time() - t1 - - buf = ''' - int (*k)(int); - ''' - - # set debuglevel to 2 for debugging - t = parser.parse(buf, 'x.c', debuglevel=0) - t.show(showcoord=True) + parser = CParser(lex_optimize=True, yacc_debug=True, yacc_optimize=False) + print time.time() - t1 + + buf = ''' + int (*k)(int); + ''' + + # set debuglevel to 2 for debugging + t = parser.parse(buf, 'x.c', debuglevel=0) + t.show(showcoord=True) diff --git a/plugins/pycparser/pycparser/plyparser.py b/plugins/pycparser/pycparser/plyparser.py index 8e9e573..e396e71 100644 --- a/plugins/pycparser/pycparser/plyparser.py +++ b/plugins/pycparser/pycparser/plyparser.py @@ -1,67 +1,67 @@ -#----------------------------------------------------------------- -# plyparser.py -# -# PLYParser class and other utilites for simplifying programming -# parsers with PLY -# -# Copyright (C) 2008-2009, Eli Bendersky -# License: LGPL -#----------------------------------------------------------------- - - -class Coord(object): - """ Coordinates of a syntactic element. Consists of: - - File name - - Line number - - (optional) column number, for the Lexer - """ - def __init__(self, file, line, column=None): - self.file = file - self.line = line - self.column = column - - def __str__(self): - str = "%s:%s" % (self.file, self.line) - if self.column: str += ":%s" % self.column - return str - - -class ParseError(Exception): pass - - +#----------------------------------------------------------------- +# plyparser.py +# +# PLYParser class and other utilites for simplifying programming +# parsers with PLY +# +# Copyright (C) 2008-2009, Eli Bendersky +# License: LGPL +#----------------------------------------------------------------- + + +class Coord(object): + """ Coordinates of a syntactic element. Consists of: + - File name + - Line number + - (optional) column number, for the Lexer + """ + def __init__(self, file, line, column=None): + self.file = file + self.line = line + self.column = column + + def __str__(self): + str = "%s:%s" % (self.file, self.line) + if self.column: str += ":%s" % self.column + return str + + +class ParseError(Exception): pass + + class PLYParser(object): - def _create_opt_rule(self, rulename): - """ Given a rule name, creates an optional ply.yacc rule - for it. The name of the optional rule is - _opt - """ - optname = rulename + '_opt' - - def optrule(self, p): - p[0] = p[1] - - optrule.__doc__ = '%s : empty\n| %s' % (optname, rulename) - optrule.__name__ = 'p_%s' % optname - setattr(self.__class__, optrule.__name__, optrule) - - def _coord(self, lineno, column=None): - return Coord( - file=self.clex.filename, - line=lineno, - column=column) - - def _parse_error(self, msg, coord): - raise ParseError("%s: %s" % (coord, msg)) - - -if __name__ == '__main__': - pp = PLYParser() - pp._create_opt_rule('java') - - ar = [4, 6] - pp.p_java_opt(ar) - - print ar - print pp.p_java_opt.__doc__ - - print dir(pp) + def _create_opt_rule(self, rulename): + """ Given a rule name, creates an optional ply.yacc rule + for it. The name of the optional rule is + _opt + """ + optname = rulename + '_opt' + + def optrule(self, p): + p[0] = p[1] + + optrule.__doc__ = '%s : empty\n| %s' % (optname, rulename) + optrule.__name__ = 'p_%s' % optname + setattr(self.__class__, optrule.__name__, optrule) + + def _coord(self, lineno, column=None): + return Coord( + file=self.clex.filename, + line=lineno, + column=column) + + def _parse_error(self, msg, coord): + raise ParseError("%s: %s" % (coord, msg)) + + +if __name__ == '__main__': + pp = PLYParser() + pp._create_opt_rule('java') + + ar = [4, 6] + pp.p_java_opt(ar) + + print ar + print pp.p_java_opt.__doc__ + + print dir(pp) diff --git a/plugins/pycparser/yacctab.py b/plugins/pycparser/yacctab.py index 544f84c..7296f23 100644 --- a/plugins/pycparser/yacctab.py +++ b/plugins/pycparser/yacctab.py @@ -6,7 +6,7 @@ _tabversion = '3.2' _lr_method = 'LALR' _lr_signature = "\n\x9d\xda\xf6\xeb\xf5\x97'\n\xff\xf7b(G7V" - + _lr_action_items = {'VOID':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[6,6,-51,-61,-60,-49,-46,-47,-27,-23,6,-45,-57,-53,-58,-44,6,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,6,-56,-54,-59,-62,6,-70,6,-69,-95,-24,6,-85,-84,6,-38,-39,6,-97,6,6,6,-76,6,6,6,6,-29,-40,6,-77,-71,6,6,-98,-100,-99,6,6,-86,-30,6,-73,-78,-72,6,6,-88,-87,-127,-128,-129,]),'LBRACKET':([1,2,3,5,6,8,9,12,14,15,16,17,19,21,22,23,25,28,31,33,34,36,37,38,39,40,42,43,44,46,48,49,50,54,56,57,58,59,60,67,73,76,78,83,84,85,86,87,90,95,97,101,102,106,107,111,116,125,126,136,137,138,139,140,149,153,160,183,184,185,186,191,192,197,229,231,236,238,239,242,258,259,260,288,292,295,320,321,327,328,329,347,348,],[-221,-51,-61,-60,-49,-46,-47,-221,-45,-57,-53,-58,-44,-48,-149,52,-221,-96,-50,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,52,-85,-84,-22,-101,-103,-21,-41,-97,-221,-221,-219,-210,-220,-218,-208,151,-217,-199,-214,-209,-216,-215,-207,189,-104,-102,-71,-17,-68,-18,-67,-205,-206,189,-98,-100,-99,189,286,189,-86,-214,-73,-72,-204,-203,-202,189,189,-211,286,-88,-87,-200,-201,-126,-122,-124,-123,-125,]),'WCHAR_CONST':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[85,-38,-39,-198,85,-196,-195,85,85,-194,85,85,-193,-197,85,85,-40,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,-32,-35,-31,85,85,-33,85,85,-130,-36,85,-34,85,-155,-158,-156,-152,-153,-157,-159,85,-161,-162,-154,-160,85,85,85,-127,-146,85,-128,-145,85,-143,-131,85,85,85,-142,85,85,85,85,85,-141,-129,-144,-134,85,-132,85,85,-133,85,85,85,-138,-137,-135,85,-139,85,-136,85,-140,]),'FLOAT_CONST':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[86,-38,-39,-198,86,-196,-195,86,86,-194,86,86,-193,-197,86,86,-40,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,86,-32,-35,-31,86,86,-33,86,86,-130,-36,86,-34,86,-155,-158,-156,-152,-153,-157,-159,86,-161,-162,-154,-160,86,86,86,-127,-146,86,-128,-145,86,-143,-131,86,86,86,-142,86,86,86,86,86,-141,-129,-144,-134,86,-132,86,86,-133,86,86,86,-138,-137,-135,86,-139,86,-136,86,-140,]),'MINUS':([52,66,70,81,82,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,99,100,101,102,103,104,106,107,110,111,128,131,133,143,146,147,149,151,152,153,154,155,156,157,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,229,232,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,319,320,321,322,324,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[89,-38,-39,-198,-185,-219,-210,-220,-218,-208,89,-196,-187,-195,89,89,-217,-194,-199,89,-166,89,-214,-209,-193,167,-216,-215,-197,-207,89,89,-40,89,89,-191,-205,89,89,-206,-190,89,-188,-185,-189,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,-32,-35,-31,89,89,-33,89,89,-130,-36,89,-34,-214,89,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,89,-161,-162,-154,-160,89,-211,89,167,167,167,-171,167,167,167,-170,167,167,-168,-167,167,167,167,167,167,-169,89,-127,-146,89,-128,-145,89,-143,-131,89,89,89,-142,89,89,-192,-200,-201,89,-186,89,89,-141,-129,-144,-134,89,-132,89,89,-133,89,89,89,-138,-137,-135,89,-139,89,-136,89,-140,]),'RPAREN':([1,2,3,5,6,8,9,12,14,15,16,17,19,21,22,23,25,28,31,33,34,36,37,38,39,40,42,43,44,45,46,48,49,50,53,54,56,57,58,59,60,67,73,76,78,82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,112,113,114,115,116,117,118,119,125,126,136,137,138,139,140,147,149,152,153,154,156,157,158,159,160,161,162,163,183,184,185,186,187,188,190,191,192,193,197,218,231,236,237,238,239,241,242,243,257,258,259,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,281,282,283,284,287,288,289,290,291,292,295,302,319,320,321,323,324,325,327,328,329,331,339,341,344,345,346,347,348,360,362,365,],[-221,-51,-61,-60,-49,-46,-47,-221,-45,-57,-53,-58,-44,-48,-149,-94,-221,-96,-50,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,73,-70,-69,-42,-95,-221,-85,-84,-22,-101,-103,-21,-41,-97,-221,-221,-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,-164,-216,-215,-207,184,-11,185,-107,-221,-12,-105,-111,-104,-102,-71,-17,-68,-18,-67,-191,-205,242,-206,-190,-188,-185,256,-147,-221,-150,260,-189,-98,-100,-99,-221,-110,-2,-109,-121,-119,-1,-86,-10,-73,-72,319,-204,-203,-212,-202,321,-118,-221,-119,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-15,-16,327,328,-221,-120,-112,-106,-108,-88,-87,-9,-192,-200,-201,-151,-186,-148,-126,-122,-124,348,352,354,356,-213,-165,-123,-125,363,-221,367,]),'LONG':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[16,16,-51,-61,-60,-49,-46,-47,-27,-23,16,-45,-57,-53,-58,-44,16,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,16,-56,-54,-59,-62,16,-70,16,-69,-95,-24,16,-85,-84,16,-38,-39,16,-97,16,16,16,-76,16,16,16,16,-29,-40,16,-77,-71,16,16,-98,-100,-99,16,16,-86,-30,16,-73,-78,-72,16,16,-88,-87,-127,-128,-129,]),'PLUS':([52,66,70,81,82,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,99,100,101,102,103,104,106,107,110,111,128,131,133,143,146,147,149,151,152,153,154,155,156,157,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,229,232,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,319,320,321,322,324,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[91,-38,-39,-198,-185,-219,-210,-220,-218,-208,91,-196,-187,-195,91,91,-217,-194,-199,91,-166,91,-214,-209,-193,171,-216,-215,-197,-207,91,91,-40,91,91,-191,-205,91,91,-206,-190,91,-188,-185,-189,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,91,-32,-35,-31,91,91,-33,91,91,-130,-36,91,-34,-214,91,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,91,-161,-162,-154,-160,91,-211,91,171,171,171,-171,171,171,171,-170,171,171,-168,-167,171,171,171,171,171,-169,91,-127,-146,91,-128,-145,91,-143,-131,91,91,91,-142,91,91,-192,-200,-201,91,-186,91,91,-141,-129,-144,-134,91,-132,91,91,-133,91,91,91,-138,-137,-135,91,-139,91,-136,91,-140,]),'ELLIPSIS':([195,],[290,]),'GT':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,172,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,172,-173,-171,-175,172,-174,-170,-177,172,-168,-167,-176,172,172,172,172,-169,-192,-200,-201,-186,]),'RBRACE':([66,70,75,77,82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,109,111,121,122,123,131,133,134,135,145,147,149,153,154,156,157,161,163,196,198,200,203,206,207,209,211,212,214,217,223,224,226,228,235,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,293,294,296,297,299,300,301,303,304,307,308,313,319,320,321,323,324,332,333,334,335,336,338,343,346,349,350,353,358,359,361,363,366,368,],[-38,-39,136,-76,-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,-164,-216,-215,-163,-207,-89,197,-92,-221,-40,231,-77,236,-191,-205,-206,-190,-188,-185,-150,-189,292,-90,295,-113,-32,-35,299,-31,303,-33,-20,-130,-36,-19,-34,-78,-204,-203,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-91,-93,-116,333,-127,-146,335,-128,-145,-143,-131,-142,-192,-200,-201,-151,-186,350,-114,-141,-129,-144,-134,-132,-165,-117,-115,-133,-138,-137,-135,-139,-136,-140,]),'ENUM':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[24,24,-51,-61,-60,-49,-46,-47,-27,-23,24,-45,-57,-53,-58,-44,24,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,24,-56,-54,-59,-62,24,-70,24,-69,-95,-24,24,-85,-84,24,-38,-39,24,-97,24,24,24,-76,24,24,24,24,-29,-40,24,-77,-71,24,24,-98,-100,-99,24,24,-86,-30,24,-73,-78,-72,24,24,-88,-87,-127,-128,-129,]),'PERIOD':([83,84,85,86,87,90,95,97,101,102,106,107,111,149,153,229,238,239,242,260,320,321,],[-219,-210,-220,-218,-208,150,-217,-199,-214,-209,-216,-215,-207,-205,-206,-214,-204,-203,-202,-211,-200,-201,]),'GE':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,176,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,176,-173,-171,-175,176,-174,-170,-177,176,-168,-167,-176,176,176,176,176,-169,-192,-200,-201,-186,]),'INT_CONST_DEC':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[107,-38,-39,-198,107,-196,-195,107,107,-194,107,107,-193,-197,107,107,-40,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,-32,-35,-31,107,107,-33,107,107,-130,-36,107,-34,107,-155,-158,-156,-152,-153,-157,-159,107,-161,-162,-154,-160,107,107,107,-127,-146,107,-128,-145,107,-143,-131,107,107,107,-142,107,107,107,107,107,-141,-129,-144,-134,107,-132,107,107,-133,107,107,107,-138,-137,-135,107,-139,107,-136,107,-140,]),'ARROW':([83,84,85,86,87,90,95,97,101,102,106,107,111,149,153,229,238,239,242,260,320,321,],[-219,-210,-220,-218,-208,148,-217,-199,-214,-209,-216,-215,-207,-205,-206,-214,-204,-203,-202,-211,-200,-201,]),'DOUBLE':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[34,34,-51,-61,-60,-49,-46,-47,-27,-23,34,-45,-57,-53,-58,-44,34,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,34,-56,-54,-59,-62,34,-70,34,-69,-95,-24,34,-85,-84,34,-38,-39,34,-97,34,34,34,-76,34,34,34,34,-29,-40,34,-77,-71,34,34,-98,-100,-99,34,34,-86,-30,34,-73,-78,-72,34,34,-88,-87,-127,-128,-129,]),'MINUSEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,245,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'INT_CONST_OCT':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[106,-38,-39,-198,106,-196,-195,106,106,-194,106,106,-193,-197,106,106,-40,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,-32,-35,-31,106,106,-33,106,106,-130,-36,106,-34,106,-155,-158,-156,-152,-153,-157,-159,106,-161,-162,-154,-160,106,106,106,-127,-146,106,-128,-145,106,-143,-131,106,106,106,-142,106,106,106,106,106,-141,-129,-144,-134,106,-132,106,106,-133,106,106,106,-138,-137,-135,106,-139,106,-136,106,-140,]),'TIMESEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,254,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'OR':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,181,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,181,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,181,-178,-180,-181,-169,-192,-200,-201,-186,]),'SHORT':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[2,2,-51,-61,-60,-49,-46,-47,-27,-23,2,-45,-57,-53,-58,-44,2,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,2,-56,-54,-59,-62,2,-70,2,-69,-95,-24,2,-85,-84,2,-38,-39,2,-97,2,2,2,-76,2,2,2,2,-29,-40,2,-77,-71,2,2,-98,-100,-99,2,2,-86,-30,2,-73,-78,-72,2,2,-88,-87,-127,-128,-129,]),'RETURN':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,213,-40,-32,-35,-31,213,-33,213,-130,-36,213,-34,-127,-146,213,-128,-145,-143,-131,213,-142,213,-141,-129,-144,-134,213,-132,213,-133,213,213,-138,-137,-135,-139,213,-136,213,-140,]),'RSHIFTEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,255,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'STATIC':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,48,50,51,53,54,56,64,66,70,72,73,131,132,133,136,183,184,185,186,195,197,205,212,231,236,258,287,292,295,299,303,335,],[8,8,-51,-61,-60,-49,-46,-47,-27,-23,8,-45,-57,-53,-58,-44,8,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,8,-56,-54,-59,-62,8,-70,-69,-95,-24,8,-85,-84,8,-38,-39,8,-97,8,-29,-40,-71,-98,-100,-99,8,8,-86,-30,8,-73,-72,8,8,-88,-87,-127,-128,-129,]),'SIZEOF':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[88,-38,-39,-198,88,-196,-195,88,88,-194,88,88,-193,-197,88,88,-40,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,-32,-35,-31,88,88,-33,88,88,-130,-36,88,-34,88,-155,-158,-156,-152,-153,-157,-159,88,-161,-162,-154,-160,88,88,88,-127,-146,88,-128,-145,88,-143,-131,88,88,88,-142,88,88,88,88,88,-141,-129,-144,-134,88,-132,88,88,-133,88,88,88,-138,-137,-135,88,-139,88,-136,88,-140,]),'UNSIGNED':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[15,15,-51,-61,-60,-49,-46,-47,-27,-23,15,-45,-57,-53,-58,-44,15,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,15,-56,-54,-59,-62,15,-70,15,-69,-95,-24,15,-85,-84,15,-38,-39,15,-97,15,15,15,-76,15,15,15,15,-29,-40,15,-77,-71,15,15,-98,-100,-99,15,15,-86,-30,15,-73,-78,-72,15,15,-88,-87,-127,-128,-129,]),'UNION':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[18,18,-51,-61,-60,-49,-46,-47,-27,-23,18,-45,-57,-53,-58,-44,18,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,18,-56,-54,-59,-62,18,-70,18,-69,-95,-24,18,-85,-84,18,-38,-39,18,-97,18,18,18,-76,18,18,18,18,-29,-40,18,-77,-71,18,18,-98,-100,-99,18,18,-86,-30,18,-73,-78,-72,18,18,-88,-87,-127,-128,-129,]),'COLON':([2,3,5,6,15,16,17,22,23,28,31,33,34,37,38,39,40,46,48,50,54,56,73,76,78,79,82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,109,111,136,137,138,139,140,142,147,149,153,154,156,157,159,161,163,183,184,185,197,219,229,231,234,236,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,292,295,311,319,320,321,323,324,325,346,],[-51,-61,-60,-49,-57,-53,-58,-149,-94,-96,-50,-52,-55,-56,-54,-59,-62,-70,-69,-95,-85,-84,-97,-221,-221,143,-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,-164,-216,-215,-163,-207,-71,-17,-68,-18,-67,232,-191,-205,-206,-190,-188,-185,-147,-150,-189,-98,-100,-99,-86,309,315,-73,143,-72,-204,-203,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,326,-181,-169,-88,-87,340,-192,-200,-201,-151,-186,-148,-165,]),'$end':([10,11,20,27,30,32,51,66,132,205,299,303,335,],[-27,-23,0,-26,-25,-28,-24,-38,-29,-30,-127,-128,-129,]),'WSTRING_LITERAL':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[84,-38,-39,-198,84,-196,-195,84,84,-194,84,84,-193,-197,84,84,-40,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,84,-32,-35,-31,84,84,-33,84,84,-130,-36,84,-34,84,-155,-158,-156,-152,-153,-157,-159,84,-161,-162,-154,-160,84,84,84,-127,-146,84,-128,-145,84,-143,-131,84,84,84,-142,84,84,84,84,84,-141,-129,-144,-134,84,-132,84,84,-133,84,84,84,-138,-137,-135,84,-139,84,-136,84,-140,]),'DIVIDE':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,174,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,174,174,174,174,174,174,174,174,174,174,-168,-167,174,174,174,174,174,-169,-192,-200,-201,-186,]),'FOR':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,215,-40,-32,-35,-31,215,-33,215,-130,-36,215,-34,-127,-146,215,-128,-145,-143,-131,215,-142,215,-141,-129,-144,-134,215,-132,215,-133,215,215,-138,-137,-135,-139,215,-136,215,-140,]),'PLUSPLUS':([52,66,70,81,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,100,101,102,103,106,107,110,111,128,131,133,143,146,149,151,152,153,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,229,232,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,260,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,320,321,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[94,-38,-39,-198,-219,-210,-220,-218,-208,94,-196,149,-195,94,94,-217,-194,-199,94,94,-214,-209,-193,-216,-215,-197,-207,94,94,-40,94,94,-205,94,94,-206,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,94,-32,-35,-31,94,94,-33,94,94,-130,-36,94,-34,-214,94,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,94,-161,-162,-154,-160,94,-211,94,94,-127,-146,94,-128,-145,94,-143,-131,94,94,94,-142,94,94,-200,-201,94,94,94,-141,-129,-144,-134,94,-132,94,94,-133,94,94,94,-138,-137,-135,94,-139,94,-136,94,-140,]),'EQUALS':([23,28,50,64,73,82,83,84,85,86,87,90,95,97,101,102,106,107,111,123,130,147,149,153,154,156,157,163,183,184,185,229,238,239,242,260,319,320,321,324,],[-94,-96,-95,128,-97,-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,199,128,-191,-205,-206,-190,-188,247,-189,-98,-100,-99,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'ELSE':([206,207,211,214,224,228,299,300,303,304,307,313,334,335,336,338,343,353,358,359,361,363,366,368,],[-32,-35,-31,-33,-36,-34,-127,-146,-128,-145,-143,-142,-141,-129,-144,-134,-132,-133,-138,-137,364,-139,-136,-140,]),'EQ':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,178,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,178,-173,-171,-175,-179,-174,-170,-177,178,-168,-167,-176,178,-178,178,178,-169,-192,-200,-201,-186,]),'AND':([52,66,70,81,82,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,99,100,101,102,103,104,106,107,110,111,128,131,133,143,146,147,149,151,152,153,154,155,156,157,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,229,232,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,319,320,321,322,324,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[103,-38,-39,-198,-185,-219,-210,-220,-218,-208,103,-196,-187,-195,103,103,-217,-194,-199,103,-166,103,-214,-209,-193,179,-216,-215,-197,-207,103,103,-40,103,103,-191,-205,103,103,-206,-190,103,-188,-185,-189,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,-32,-35,-31,103,103,-33,103,103,-130,-36,103,-34,-214,103,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,103,-161,-162,-154,-160,103,-211,103,-172,179,-173,-171,-175,-179,-174,-170,-177,179,-168,-167,-176,179,-178,-180,179,-169,103,-127,-146,103,-128,-145,103,-143,-131,103,103,103,-142,103,103,-192,-200,-201,103,-186,103,103,-141,-129,-144,-134,103,-132,103,103,-133,103,103,103,-138,-137,-135,103,-139,103,-136,103,-140,]),'TYPEID':([0,1,2,3,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23,24,27,28,29,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[22,22,-51,-61,-60,-49,46,-46,-47,-27,-23,22,-45,-57,-53,-58,-75,-44,22,-48,-149,-94,54,-26,-96,-74,-25,-50,-28,-52,-55,22,-56,-54,-59,-62,22,-70,22,-69,-95,-24,22,-85,-84,22,-38,-39,22,-97,22,22,22,-76,22,22,22,22,-29,-40,22,-77,-71,22,22,-98,-100,-99,22,22,-86,-30,22,-73,-78,-72,22,22,-88,-87,-127,-128,-129,]),'LBRACE':([7,18,23,24,28,29,41,46,48,50,54,56,64,66,68,70,71,72,73,128,129,131,133,183,184,185,204,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,332,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[47,-75,-94,55,-96,-74,-221,74,80,-95,120,124,-221,-38,-5,-39,131,-6,-97,204,131,131,-40,-98,-100,-99,204,-32,-35,-31,131,-33,131,-130,-36,131,-34,-127,-146,131,-128,-145,-143,-131,131,-142,131,204,-141,-129,-144,-134,131,-132,131,-133,131,131,-138,-137,-135,-139,131,-136,131,-140,]),'PPHASH':([0,10,11,20,27,30,32,51,66,132,205,299,303,335,],[32,-27,-23,32,-26,-25,-28,-24,-38,-29,-30,-127,-128,-129,]),'INT':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[33,33,-51,-61,-60,-49,-46,-47,-27,-23,33,-45,-57,-53,-58,-44,33,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,33,-56,-54,-59,-62,33,-70,33,-69,-95,-24,33,-85,-84,33,-38,-39,33,-97,33,33,33,-76,33,33,33,33,-29,-40,33,-77,-71,33,33,-98,-100,-99,33,33,-86,-30,33,-73,-78,-72,33,33,-88,-87,-127,-128,-129,]),'SIGNED':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[37,37,-51,-61,-60,-49,-46,-47,-27,-23,37,-45,-57,-53,-58,-44,37,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,37,-56,-54,-59,-62,37,-70,37,-69,-95,-24,37,-85,-84,37,-38,-39,37,-97,37,37,37,-76,37,37,37,37,-29,-40,37,-77,-71,37,37,-98,-100,-99,37,37,-86,-30,37,-73,-78,-72,37,37,-88,-87,-127,-128,-129,]),'CONTINUE':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,216,-40,-32,-35,-31,216,-33,216,-130,-36,216,-34,-127,-146,216,-128,-145,-143,-131,216,-142,216,-141,-129,-144,-134,216,-132,216,-133,216,216,-138,-137,-135,-139,216,-136,216,-140,]),'NOT':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[110,-38,-39,-198,110,-196,-195,110,110,-194,110,110,-193,-197,110,110,-40,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,110,-32,-35,-31,110,110,-33,110,110,-130,-36,110,-34,110,-155,-158,-156,-152,-153,-157,-159,110,-161,-162,-154,-160,110,110,110,-127,-146,110,-128,-145,110,-143,-131,110,110,110,-142,110,110,110,110,110,-141,-129,-144,-134,110,-132,110,110,-133,110,110,110,-138,-137,-135,110,-139,110,-136,110,-140,]),'OREQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,253,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'MOD':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,182,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,182,182,182,182,182,182,182,182,182,182,-168,-167,182,182,182,182,182,-169,-192,-200,-201,-186,]),'RSHIFT':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,164,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,164,-173,-171,164,164,164,-170,164,164,-168,-167,164,164,164,164,164,-169,-192,-200,-201,-186,]),'DEFAULT':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,219,-40,-32,-35,-31,219,-33,219,-130,-36,219,-34,-127,-146,219,-128,-145,-143,-131,219,-142,219,-141,-129,-144,-134,219,-132,219,-133,219,219,-138,-137,-135,-139,219,-136,219,-140,]),'CHAR':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[31,31,-51,-61,-60,-49,-46,-47,-27,-23,31,-45,-57,-53,-58,-44,31,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,31,-56,-54,-59,-62,31,-70,31,-69,-95,-24,31,-85,-84,31,-38,-39,31,-97,31,31,31,-76,31,31,31,31,-29,-40,31,-77,-71,31,31,-98,-100,-99,31,31,-86,-30,31,-73,-78,-72,31,31,-88,-87,-127,-128,-129,]),'WHILE':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,314,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,220,-40,-32,-35,-31,220,-33,220,-130,-36,220,-34,-127,-146,220,-128,-145,-143,-131,220,-142,342,220,-141,-129,-144,-134,220,-132,220,-133,220,220,-138,-137,-135,-139,220,-136,220,-140,]),'DIVEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,244,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'EXTERN':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,48,50,51,53,54,56,64,66,70,72,73,131,132,133,136,183,184,185,186,195,197,205,212,231,236,258,287,292,295,299,303,335,],[9,9,-51,-61,-60,-49,-46,-47,-27,-23,9,-45,-57,-53,-58,-44,9,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,9,-56,-54,-59,-62,9,-70,-69,-95,-24,9,-85,-84,9,-38,-39,9,-97,9,-29,-40,-71,-98,-100,-99,9,9,-86,-30,9,-73,-72,9,9,-88,-87,-127,-128,-129,]),'CASE':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,221,-40,-32,-35,-31,221,-33,221,-130,-36,221,-34,-127,-146,221,-128,-145,-143,-131,221,-142,221,-141,-129,-144,-134,221,-132,221,-133,221,221,-138,-137,-135,-139,221,-136,221,-140,]),'LAND':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,177,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,177,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-192,-200,-201,-186,]),'REGISTER':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,48,50,51,53,54,56,64,66,70,72,73,131,132,133,136,183,184,185,186,195,197,205,212,231,236,258,287,292,295,299,303,335,],[14,14,-51,-61,-60,-49,-46,-47,-27,-23,14,-45,-57,-53,-58,-44,14,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,14,-56,-54,-59,-62,14,-70,-69,-95,-24,14,-85,-84,14,-38,-39,14,-97,14,-29,-40,-71,-98,-100,-99,14,14,-86,-30,14,-73,-72,14,14,-88,-87,-127,-128,-129,]),'MODEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,246,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'NE':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,169,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,169,-173,-171,-175,-179,-174,-170,-177,169,-168,-167,-176,169,-178,169,169,-169,-192,-200,-201,-186,]),'SWITCH':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,222,-40,-32,-35,-31,222,-33,222,-130,-36,222,-34,-127,-146,222,-128,-145,-143,-131,222,-142,222,-141,-129,-144,-134,222,-132,222,-133,222,222,-138,-137,-135,-139,222,-136,222,-140,]),'INT_CONST_HEX':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[95,-38,-39,-198,95,-196,-195,95,95,-194,95,95,-193,-197,95,95,-40,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,-32,-35,-31,95,95,-33,95,95,-130,-36,95,-34,95,-155,-158,-156,-152,-153,-157,-159,95,-161,-162,-154,-160,95,95,95,-127,-146,95,-128,-145,95,-143,-131,95,95,95,-142,95,95,95,95,95,-141,-129,-144,-134,95,-132,95,95,-133,95,95,95,-138,-137,-135,95,-139,95,-136,95,-140,]),'PLUSEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,249,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'STRUCT':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[29,29,-51,-61,-60,-49,-46,-47,-27,-23,29,-45,-57,-53,-58,-44,29,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,29,-56,-54,-59,-62,29,-70,29,-69,-95,-24,29,-85,-84,29,-38,-39,29,-97,29,29,29,-76,29,29,29,29,-29,-40,29,-77,-71,29,29,-98,-100,-99,29,29,-86,-30,29,-73,-78,-72,29,29,-88,-87,-127,-128,-129,]),'CONDOP':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,180,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-192,-200,-201,-186,]),'BREAK':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,225,-40,-32,-35,-31,225,-33,225,-130,-36,225,-34,-127,-146,225,-128,-145,-143,-131,225,-142,225,-141,-129,-144,-134,225,-132,225,-133,225,225,-138,-137,-135,-139,225,-136,225,-140,]),'VOLATILE':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,25,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,57,59,64,66,70,72,73,74,75,76,77,78,80,98,125,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[40,40,-51,-61,-60,-49,-46,-47,-27,-23,40,-45,-57,-53,-58,-44,40,-48,-149,-94,40,-26,-96,-25,-50,-28,-52,-55,40,-56,-54,-59,-62,40,-70,40,-69,-95,-24,40,-85,-84,40,-103,40,-38,-39,40,-97,40,40,40,-76,40,40,40,-104,40,-29,-40,40,-77,-71,40,40,-98,-100,-99,40,40,-86,-30,40,-73,-78,-72,40,40,-88,-87,-127,-128,-129,]),'ANDEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,252,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'DO':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,227,-40,-32,-35,-31,227,-33,227,-130,-36,227,-34,-127,-146,227,-128,-145,-143,-131,227,-142,227,-141,-129,-144,-134,227,-132,227,-133,227,227,-138,-137,-135,-139,227,-136,227,-140,]),'LNOT':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[81,-38,-39,-198,81,-196,-195,81,81,-194,81,81,-193,-197,81,81,-40,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,-32,-35,-31,81,81,-33,81,81,-130,-36,81,-34,81,-155,-158,-156,-152,-153,-157,-159,81,-161,-162,-154,-160,81,81,81,-127,-146,81,-128,-145,81,-143,-131,81,81,81,-142,81,81,81,81,81,-141,-129,-144,-134,81,-132,81,81,-133,81,81,81,-138,-137,-135,81,-139,81,-136,81,-140,]),'CONST':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,25,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,57,59,64,66,70,72,73,74,75,76,77,78,80,98,125,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[3,3,-51,-61,-60,-49,-46,-47,-27,-23,3,-45,-57,-53,-58,-44,3,-48,-149,-94,3,-26,-96,-25,-50,-28,-52,-55,3,-56,-54,-59,-62,3,-70,3,-69,-95,-24,3,-85,-84,3,-103,3,-38,-39,3,-97,3,3,3,-76,3,3,3,-104,3,-29,-40,3,-77,-71,3,3,-98,-100,-99,3,3,-86,-30,3,-73,-78,-72,3,3,-88,-87,-127,-128,-129,]),'LOR':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,165,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-192,-200,-201,-186,]),'CHAR_CONST':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[83,-38,-39,-198,83,-196,-195,83,83,-194,83,83,-193,-197,83,83,-40,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,-32,-35,-31,83,83,-33,83,83,-130,-36,83,-34,83,-155,-158,-156,-152,-153,-157,-159,83,-161,-162,-154,-160,83,83,83,-127,-146,83,-128,-145,83,-143,-131,83,83,83,-142,83,83,83,83,83,-141,-129,-144,-134,83,-132,83,83,-133,83,83,83,-138,-137,-135,83,-139,83,-136,83,-140,]),'LSHIFT':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,166,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,166,-173,-171,166,166,166,-170,166,166,-168,-167,166,166,166,166,166,-169,-192,-200,-201,-186,]),'GOTO':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,208,-40,-32,-35,-31,208,-33,208,-130,-36,208,-34,-127,-146,208,-128,-145,-143,-131,208,-142,208,-141,-129,-144,-134,208,-132,208,-133,208,208,-138,-137,-135,-139,208,-136,208,-140,]),'LE':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,168,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,168,-173,-171,-175,168,-174,-170,-177,168,-168,-167,-176,168,168,168,168,-169,-192,-200,-201,-186,]),'SEMI':([1,2,3,5,6,8,9,12,14,15,16,17,19,21,22,23,26,28,31,33,34,35,36,37,38,39,40,42,43,44,46,48,49,50,54,56,61,62,63,64,65,66,67,69,70,73,82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,109,111,130,131,133,136,141,142,144,147,149,153,154,156,157,159,161,163,183,184,185,197,201,202,203,206,207,210,211,212,213,214,216,217,218,223,224,225,226,227,228,229,231,233,236,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,292,295,298,299,300,301,302,303,304,305,306,307,308,309,313,315,317,318,319,320,321,323,324,325,333,334,335,336,337,338,340,343,346,350,351,352,353,354,356,357,358,359,361,363,364,366,367,368,],[-221,-51,-61,-60,-49,-46,-47,-221,-45,-57,-53,-58,-44,-48,-149,-94,-221,-96,-50,-52,-55,66,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,-95,-85,-84,-14,-37,-13,-65,-63,-38,-41,-221,-39,-97,-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,-164,-216,-215,-163,-207,-65,-221,-40,-71,-79,-81,235,-191,-205,-206,-190,-188,-185,-147,-150,-189,-98,-100,-99,-86,-64,-66,-113,-32,-35,300,-31,-221,304,-33,307,-221,-10,-130,-36,313,-9,-221,-34,-214,-73,-83,-72,-204,-203,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,-88,-87,334,-127,-146,-221,-9,-128,-145,336,-221,-143,-131,-221,-142,-221,-82,-80,-192,-200,-201,-151,-186,-148,-114,-141,-129,-144,351,-134,-221,-132,-165,-115,-221,-221,-133,-221,-221,362,-138,-137,-135,-139,-221,-136,-221,-140,]),'LT':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,170,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,170,-173,-171,-175,170,-174,-170,-177,170,-168,-167,-176,170,170,170,170,-169,-192,-200,-201,-186,]),'COMMA':([1,2,3,5,6,8,9,12,14,15,16,17,19,21,22,23,25,28,31,33,34,36,37,38,39,40,42,43,44,46,48,49,50,54,56,57,58,59,60,61,64,65,67,73,82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,109,111,115,116,117,118,119,121,122,123,125,126,130,136,141,142,144,147,149,153,154,156,157,159,161,162,163,183,184,185,187,188,190,191,192,193,196,197,198,200,201,202,203,218,229,231,233,236,238,239,240,241,242,243,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,288,289,291,292,293,294,295,296,297,305,317,318,319,320,321,323,324,325,327,328,329,333,339,341,344,345,346,347,348,349,350,360,],[-221,-51,-61,-60,-49,-46,-47,-221,-45,-57,-53,-58,-44,-48,-149,-94,-221,-96,-50,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,-95,-85,-84,-22,-101,-103,-21,127,-65,-63,-41,-97,-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,-164,-216,-215,-163,-207,-107,-221,194,195,-111,-89,198,-92,-104,-102,-65,-71,-79,-81,234,-191,-205,-206,-190,-188,-185,-147,-150,261,-189,-98,-100,-99,-110,-2,-109,-121,-119,-1,198,-86,-90,198,-64,-66,-113,261,-214,-73,-83,-72,-204,-203,261,-212,-202,322,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,261,-181,-169,-120,-112,-108,-88,-91,-93,-87,-116,332,261,-82,-80,-192,-200,-201,-151,-186,-148,-126,-122,-124,-114,261,261,261,-213,-165,-123,-125,-117,-115,261,]),'TYPEDEF':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,48,50,51,53,54,56,64,66,70,72,73,131,132,133,136,183,184,185,186,195,197,205,212,231,236,258,287,292,295,299,303,335,],[21,21,-51,-61,-60,-49,-46,-47,-27,-23,21,-45,-57,-53,-58,-44,21,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,21,-56,-54,-59,-62,21,-70,-69,-95,-24,21,-85,-84,21,-38,-39,21,-97,21,-29,-40,-71,-98,-100,-99,21,21,-86,-30,21,-73,-72,21,21,-88,-87,-127,-128,-129,]),'XOR':([82,83,84,85,86,87,90,95,97,99,101,102,104,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-166,-214,-209,173,-216,-215,-207,-191,-205,-206,-190,-188,-185,-189,-214,-204,-203,-202,-211,-172,173,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,173,-178,-180,173,-169,-192,-200,-201,-186,]),'AUTO':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,48,50,51,53,54,56,64,66,70,72,73,131,132,133,136,183,184,185,186,195,197,205,212,231,236,258,287,292,295,299,303,335,],[19,19,-51,-61,-60,-49,-46,-47,-27,-23,19,-45,-57,-53,-58,-44,19,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,19,-56,-54,-59,-62,19,-70,-69,-95,-24,19,-85,-84,19,-38,-39,19,-97,19,-29,-40,-71,-98,-100,-99,19,19,-86,-30,19,-73,-72,19,19,-88,-87,-127,-128,-129,]),'TIMES':([0,1,2,3,4,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,25,26,27,30,31,32,33,34,36,37,38,39,40,42,43,44,46,48,49,51,52,54,56,57,58,59,60,66,67,69,70,76,78,79,81,82,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,99,100,101,102,103,104,106,107,110,111,116,125,127,128,131,132,133,136,137,138,139,140,143,146,147,149,151,152,153,154,155,156,157,160,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,186,189,197,199,204,205,206,207,211,212,213,214,217,221,223,224,227,228,229,231,232,234,236,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,258,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,286,292,295,299,300,301,303,304,306,307,308,309,310,312,313,315,316,319,320,321,322,324,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[25,-221,-51,-61,25,-60,-49,-46,-47,-27,-23,-221,-45,-57,-53,-58,-44,25,-48,-149,-221,25,-26,-25,-50,-28,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,-24,96,-85,-84,-22,25,-103,-21,-38,-41,25,-39,-221,-221,25,-198,-185,-219,-210,-220,-218,-208,96,-196,-187,-195,96,96,-217,-194,-199,96,-166,96,-214,-209,-193,175,-216,-215,-197,-207,25,-104,25,96,96,-29,-40,-71,-17,-68,-18,-67,96,96,-191,-205,96,96,-206,-190,96,-188,-185,25,-189,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,25,96,-86,96,96,-30,-32,-35,-31,96,96,-33,96,96,-130,-36,96,-34,-214,-73,96,25,-72,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,96,-161,-162,-154,-160,96,25,-211,96,175,175,175,175,175,175,175,175,175,175,-168,-167,175,175,175,175,175,-169,96,-88,-87,-127,-146,96,-128,-145,96,-143,-131,96,96,96,-142,96,96,-192,-200,-201,96,-186,96,96,-141,-129,-144,-134,96,-132,96,96,-133,96,96,96,-138,-137,-135,96,-139,96,-136,96,-140,]),'LPAREN':([0,1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,25,26,27,28,30,31,32,33,34,36,37,38,39,40,42,43,44,46,48,49,50,51,52,54,56,57,58,59,60,66,67,69,70,73,76,78,79,81,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,100,101,102,103,106,107,110,111,116,125,126,127,128,131,132,133,136,137,138,139,140,143,146,149,151,152,153,155,160,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,189,191,192,197,199,204,205,206,207,211,212,213,214,215,217,220,221,222,223,224,227,228,229,230,231,232,234,236,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,258,259,260,261,286,288,292,295,299,300,301,303,304,306,307,308,309,310,312,313,315,316,320,321,322,326,327,328,329,332,334,335,336,338,340,342,343,347,348,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[4,-221,-51,-61,4,-60,-49,-46,-47,-27,-23,-221,4,-45,-57,-53,-58,-44,4,-48,-149,53,-221,4,-26,-96,-25,-50,-28,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,53,-24,98,-85,-84,-22,-101,-103,-21,-38,-41,4,-39,-97,-221,-221,4,-198,-219,-210,-220,-218,-208,146,-196,152,-195,98,155,-217,-194,-199,98,155,-214,-209,-193,-216,-215,-197,-207,186,-104,-102,4,98,98,-29,-40,-71,-17,-68,-18,-67,98,98,-205,98,98,-206,98,258,98,98,98,98,98,98,98,98,98,98,98,98,98,98,98,98,98,98,98,-98,-100,-99,186,98,287,186,-86,98,98,-30,-32,-35,-31,98,98,-33,306,98,310,98,312,-130,-36,98,-34,-214,316,-73,98,4,-72,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,98,-161,-162,-154,-160,98,258,258,-211,98,98,287,-88,-87,-127,-146,98,-128,-145,98,-143,-131,98,98,98,-142,98,98,-200,-201,98,98,-126,-122,-124,98,-141,-129,-144,-134,98,355,-132,-123,-125,98,98,-133,98,98,98,-138,-137,-135,98,-139,98,-136,98,-140,]),'MINUSMINUS':([52,66,70,81,83,84,85,86,87,88,89,90,91,92,94,95,96,97,98,100,101,102,103,106,107,110,111,128,131,133,143,146,149,151,152,153,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,229,232,238,239,242,244,245,246,247,248,249,250,251,252,253,254,255,256,260,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,320,321,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[100,-38,-39,-198,-219,-210,-220,-218,-208,100,-196,153,-195,100,100,-217,-194,-199,100,100,-214,-209,-193,-216,-215,-197,-207,100,100,-40,100,100,-205,100,100,-206,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,-32,-35,-31,100,100,-33,100,100,-130,-36,100,-34,-214,100,-204,-203,-202,-155,-158,-156,-152,-153,-157,-159,100,-161,-162,-154,-160,100,-211,100,100,-127,-146,100,-128,-145,100,-143,-131,100,100,100,-142,100,100,-200,-201,100,100,100,-141,-129,-144,-134,100,-132,100,100,-133,100,100,100,-138,-137,-135,100,-139,100,-136,100,-140,]),'ID':([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,24,25,26,27,29,30,31,32,33,34,36,37,38,39,40,42,43,44,46,48,49,51,52,53,54,55,56,57,58,59,60,66,67,69,70,76,78,79,81,88,89,91,92,94,96,98,100,103,110,116,120,124,125,126,127,128,131,132,133,136,137,138,139,140,143,146,148,150,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,186,189,192,194,197,198,199,204,205,206,207,208,211,212,213,214,217,221,223,224,227,228,231,232,234,236,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,292,295,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[28,-221,-51,-61,28,-60,-49,48,-46,-47,-27,-23,-221,28,-45,-57,-53,-58,-75,-44,28,-48,-149,56,-221,28,-26,-74,-25,-50,-28,-52,-55,-221,-56,-54,-59,-62,-43,-7,-8,-70,-69,-42,-24,101,101,-85,123,-84,-22,-101,-103,-21,-38,-41,28,-39,-221,-221,28,-198,101,-196,-195,101,101,-194,101,101,-193,-197,28,123,123,-104,-102,28,101,229,-29,-40,-71,-17,-68,-18,-67,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,28,101,28,101,-86,123,101,101,-30,-32,-35,298,-31,229,101,-33,229,101,-130,-36,229,-34,-73,101,28,-72,-155,-158,-156,-152,-153,-157,-159,101,-161,-162,-154,-160,101,101,101,-88,-87,-127,-146,229,-128,-145,101,-143,-131,229,101,101,-142,229,101,101,101,101,-141,-129,-144,-134,229,-132,101,229,-133,229,101,229,-138,-137,-135,101,-139,229,-136,229,-140,]),'IF':([66,70,131,133,206,207,211,212,214,217,223,224,227,228,299,300,301,303,304,307,308,309,313,315,334,335,336,338,340,343,352,353,354,356,358,359,361,363,364,366,367,368,],[-38,-39,230,-40,-32,-35,-31,230,-33,230,-130,-36,230,-34,-127,-146,230,-128,-145,-143,-131,230,-142,230,-141,-129,-144,-134,230,-132,230,-133,230,230,-138,-137,-135,-139,230,-136,230,-140,]),'STRING_LITERAL':([52,66,70,81,88,89,91,92,94,96,98,100,103,110,128,131,133,143,146,151,152,155,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,189,199,204,206,207,211,212,213,214,217,221,223,224,227,228,232,244,245,246,247,248,249,250,251,252,253,254,255,256,261,286,299,300,301,303,304,306,307,308,309,310,312,313,315,316,322,326,332,334,335,336,338,340,343,351,352,353,354,355,356,358,359,361,362,363,364,366,367,368,],[102,-38,-39,-198,102,-196,-195,102,102,-194,102,102,-193,-197,102,102,-40,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,-32,-35,-31,102,102,-33,102,102,-130,-36,102,-34,102,-155,-158,-156,-152,-153,-157,-159,102,-161,-162,-154,-160,102,102,102,-127,-146,102,-128,-145,102,-143,-131,102,102,102,-142,102,102,102,102,102,-141,-129,-144,-134,102,-132,102,102,-133,102,102,102,-138,-137,-135,102,-139,102,-136,102,-140,]),'FLOAT':([0,1,2,3,5,6,8,9,10,11,12,14,15,16,17,19,20,21,22,23,27,28,30,31,32,33,34,36,37,38,39,40,41,46,47,48,50,51,53,54,56,64,66,70,72,73,74,75,76,77,78,80,98,131,132,133,134,135,136,145,146,183,184,185,186,195,197,205,212,231,235,236,258,287,292,295,299,303,335,],[38,38,-51,-61,-60,-49,-46,-47,-27,-23,38,-45,-57,-53,-58,-44,38,-48,-149,-94,-26,-96,-25,-50,-28,-52,-55,38,-56,-54,-59,-62,38,-70,38,-69,-95,-24,38,-85,-84,38,-38,-39,38,-97,38,38,38,-76,38,38,38,38,-29,-40,38,-77,-71,38,38,-98,-100,-99,38,38,-86,-30,38,-73,-78,-72,38,38,-88,-87,-127,-128,-129,]),'XOREQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,248,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'LSHIFTEQUAL':([82,83,84,85,86,87,90,95,97,101,102,106,107,111,147,149,153,154,156,157,163,229,238,239,242,260,319,320,321,324,],[-185,-219,-210,-220,-218,-208,-187,-217,-199,-214,-209,-216,-215,-207,-191,-205,-206,-190,-188,250,-189,-214,-204,-203,-202,-211,-192,-200,-201,-186,]),'RBRACKET':([52,82,83,84,85,86,87,90,93,95,97,99,101,102,104,105,106,107,108,109,111,147,149,153,154,156,157,159,161,163,189,238,239,240,242,260,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,279,280,285,286,319,320,321,323,324,325,330,346,],[-221,-185,-219,-210,-220,-218,-208,-187,-3,-217,-199,-166,-214,-209,-164,183,-216,-215,-4,-163,-207,-191,-205,-206,-190,-188,-185,-147,-150,-189,-221,-204,-203,320,-202,-211,-172,-184,-173,-171,-175,-179,-174,-170,-177,-182,-168,-167,-176,-183,-178,-180,-181,-169,329,-221,-192,-200,-201,-151,-186,-148,347,-165,]),} _lr_action = { } diff --git a/plugins/sieve.py b/plugins/sieve.py index cee8696..9a8ff00 100644 --- a/plugins/sieve.py +++ b/plugins/sieve.py @@ -2,7 +2,7 @@ from util import hook @hook.sieve -def sieve_suite(bot, input, func, kind, args): +def sieve_suite(bot, input, func, kind, args): if input.command == 'PRIVMSG' and input.nick.lower()[-3:] == 'bot' \ and args.get('ignorebots', True): return None @@ -17,5 +17,5 @@ def sieve_suite(bot, input, func, kind, args): denied_channels = map(unicode.lower, acl['allow-except']) if input.chan.lower() in denied_channels: return None - + return input diff --git a/plugins/tag.py b/plugins/tag.py index dc84c74..215f1a6 100644 --- a/plugins/tag.py +++ b/plugins/tag.py @@ -24,20 +24,20 @@ def add_tag(db, chan, nick, subject): (nick, chan, subject)).fetchall() if match: return 'already tagged' - + db.execute('replace into tag(chan, subject, nick) values(?,?,?)', (chan, subject, nick)) db.commit() return 'tag added' - + def delete_tag(db, chan, nick, del_tag): count = db.execute('delete from tag where lower(nick)=lower(?) and' ' chan=? and lower(subject)=lower(?)', (nick, chan, del_tag)).rowcount db.commit() - + if count: return 'deleted' else: @@ -69,7 +69,7 @@ def get_nicks_by_tag(db, chan, subject): nicks = db.execute("select nick from tag where lower(subject)=lower(?)" " and chan=?" " order by lower(nick)", (subject, chan)).fetchall() - + nicks = [munge(x[0], 3) for x in nicks] if not nicks: return 'tag not found' @@ -108,9 +108,9 @@ def tag(inp, chan='', db=None): if not tags: return get_nicks_by_tag(db, chan, inp) else: - return 'tags for "%s": ' % munge(inp, 3) + ', '.join( + return 'tags for "%s": ' % munge(inp, 1) + ', '.join( tag[0] for tag in tags) - + character_replacements = { 'a': 'รค', diff --git a/plugins/tell.py b/plugins/tell.py index ee4199f..5d52ce8 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -36,7 +36,8 @@ def tellinput(paraml, input=None, db=None, bot=None): user_from, message, time, chan = tells[0] reltime = timesince.timesince(time) - reply = "%s said %s ago in %s: %s" % (user_from, reltime, chan, message) + reply = "%s said %s ago in %s: %s" % (user_from, reltime, chan, + message) if len(tells) > 1: reply += " (+%d more, .showtells to view)" % (len(tells) - 1) diff --git a/plugins/util/hook.py b/plugins/util/hook.py index da62689..fa4985f 100644 --- a/plugins/util/hook.py +++ b/plugins/util/hook.py @@ -34,9 +34,10 @@ def _hook_add(func, add, name=''): args.append(0) # means kwargs present func._args = args - if not hasattr(func, '_thread'): # does function run in its own thread? + if not hasattr(func, '_thread'): # does function run in its own thread? func._thread = False + def sieve(func): if func.func_code.co_argcount != 5: raise ValueError( @@ -86,7 +87,7 @@ def singlethread(func): def regex(regex, flags=0, **kwargs): args = kwargs - + def regex_wrapper(func): args['name'] = func.func_name args['regex'] = regex