Skip to content
Merged
11 changes: 5 additions & 6 deletions examples/json/jsonparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(self, **kwargs):
#include <stdio.h>
#include <string.h>
#include "Python.h"
#define YYSTYPE void *
#include "tokens.h"
#include "tmp.tab.h"
int yycolumn = 1;
int yywrap() { return(1); }
extern void *py_parser;
Expand Down Expand Up @@ -168,7 +167,7 @@ def on_elements(self, target, option, names, values):
if __name__ == '__main__':

start = time.time()
j = JSONParser(verbose=False, debugSymbols=False)
j = JSONParser(verbose=True, debugSymbols=False)
duration = time.time() - start
print('instantiate parser', duration)

Expand All @@ -178,12 +177,12 @@ def on_elements(self, target, option, names, values):
with open(file) as fh:
result_json = json.load(fh)
duration = time.time() - start
print('json', duration)
print('json {}'.format(duration))

start = time.time()
result_bison = j.run(file=file, debug=0)
duration = time.time() - start
print('bison-based JSONParser', duration)
print('result equal to json:', result_json == result_bison)
print('bison-based JSONParser {}'.format(duration))
print('result equal to json: {}'.format(result_json == result_bison))

print('filesize: {} kB'.format(os.stat(file).st_size / 1024))
31 changes: 14 additions & 17 deletions src/bison/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ class BisonParser(object):
raw_c_rules = ''

# Command and options for running yacc/bison, except for filename arg
bisonCmd = []
bisonCmd = ['bison']
if sys.platform == 'win32':
bisonCmd = [WIN_BISON, '-d', '-v', '-t']
else:
bisonCmd.append('bison')
bisonCmd = ['bison', '-d', '-v', '-t']
bisonCmd = [WIN_BISON]
# add bison args
bisonCmd += ['-d', '-v', '-t']

bisonFile = 'tmp.y'
bisonCFile = 'tmp.tab.c'
Expand All @@ -90,26 +89,24 @@ class BisonParser(object):
bisonHFile = 'tmp.tab.h'

# C output file from bison gets renamed to this.
bisonCFile1 = 'tmp.bison.c'

bisonCFile1 = bisonCFile # 'tmp.bison.c'
# Bison-generated header file gets renamed to this.
bisonHFile1 = 'tokens.h'
bisonHFile1 = bisonHFile # 'tokens.h'

# flex file names
flexFile = 'tmp.l'
flexCFile = 'lex.yy.c'
flexHFile = 'lex.yy.h'
# command and options for running [f]lex, except for filename arg.
flexCmd = []
flexCmd = ['flex']
if sys.platform == 'win32':
# flexCmd.append('-DYY_NO_UNISTD_H=false')
flexCmd = [WIN_FLEX, '--wincompat']
else:
flexCmd = ['flex']

flexFile = 'tmp.l'
flexCFile = 'lex.yy.c'
flexHFile = 'lex.yy.h'
flexCmd += ['-v', '--header-file="{}"'.format(flexHFile)]

# C output file from flex gets renamed to this.
flexCFile1 = 'tmp.lex.c'
flexHFile1 = 'tmp.lex.h'
flexCFile1 = flexCFile # 'tmp.lex.c'
flexHFile1 = flexHFile # 'tmp.lex.h'

# CFLAGS added before all command line arguments.
cflags_pre = ['-fPIC'] if sys.platform.startswith('linux') else []
Expand Down
Loading