smvv / pybison Goto Github PK
View Code? Open in Web Editor NEWUse Bison directly from Python
License: GNU General Public License v2.0
Use Bison directly from Python
License: GNU General Public License v2.0
It will be great if we can do this
Hello,
I have an issue with pybison which is pretty annoying. When the parser fails with an error the line/column is not reported. As you can imagine this makes tracking down the error extremely hard.
When the parser finds an error I get the following for instance:
ERROR: 0.0-0.0: "syntax error, unexpected t_DOT, expecting t_MACROMODULE or t_MODULE or t_LPARENASTERISK" near ".".
ERROR: 0.0-0.0: "syntax error, unexpected t_ID, expecting t_MACROMODULE or t_MODULE or t_LPARENASTERISK" near "slave_mp".
Traceback (most recent call last):
File "./run_parser.py", line 15, in
sv_parser.run(read = file_input.read)
File "/bison/init.py", line 257, in run
self.engine.runEngine(debug)
File "bison_.pyx", line 614, in bison_.ParserEngine.runEngine
File "/bison/init.py", line 352, in report_syntax_error
raise BisonSyntaxError('%d.%d-%d.%d: "%s" near "%s".' % args, args)
bison.BisonSyntaxError: 0.0-0.0: "syntax error, unexpected t_ID, expecting t_MACROMODULE or t_MODULE or t_LPARENASTERISK" near "regbus_packed".
I am not sure but I assume the position of the parser should be displayed in the "ERROR: 0.0-0.0:" string, however as you can see I get only zeros...
I read in the documentation that there are some issues with the "int yylineno = 0;" statement. Effectively, just like in the calculator example, my lexscript has the said line commented, and the parsing fails if I uncomment it with the following message:
cc -fPIC -g -I -c ./tmp.bison.c -o ./tmp.bison.o -O3 -g
cc -fPIC -g -I -c ./tmp.lex.c -o ./tmp.lex.o -O3 -g
./tmp.l:3: error: redefinition of ‘yylineno’
lex.yy.c:342: note: previous definition of ‘yylineno’ was here
In file included from /Python.h:8,
from ./tmp.l:6:
/pyconfig.h:1182:1: warning: "POSIX_C_SOURCE" redefined
In file included from /usr/include/stdio.h:28,
from lex.yy.c:19:
/usr/include/features.h:213:1: warning: this is the location of the previous definition
Traceback (most recent call last):
File "./run_parser.py", line 11, in
sv_parser = parser_bison.SystemVerilogParser(verbose=args.debug, keepfiles=args.debug)
File "/bison/init.py", line 159, in init
self.engine = ParserEngine(self)
File "bison.pyx", line 123, in bison_.ParserEngine.init
File "bison_.pyx", line 156, in bison_.ParserEngine.openCurrentLib
File "bison_.pyx", line 528, in bison_.ParserEngine.buildLib
File "/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/distutils/unixccompiler.py", line 122, in _compile
raise CompileError, msg
distutils.errors.CompileError: command 'cc' failed with exit status 1
In my lexscript I have the following:
[\n] { yylineno++; }
As far as I understand, even with the "int yylineno = 0" line commented out, the fact that the parser does not throw an error everytime a newline is found indicated that yylineno is in fact declared somewhere else, as the compiling reports. If i write in my lescript:
[\n] { printf("current lineno: %d\n", yylineno); yylineno++; }
The parser effectively reports and incrementing yylineno value:
current lineno: 1
current lineno: 2
current lineno: 3
current lineno: 4
current lineno: 5
current lineno: 6
current lineno: 7
current lineno: 8
current lineno: 9
current lineno: 10
current lineno: 11
current lineno: 12
current lineno: 13
current lineno: 14
current lineno: 15
current lineno: 16
As I undersant this effectively means yylineno is incrementing, so if the parsing error is supposed to report the current lineno the error must be somewhere else...
Is there something I am doing wrong? is this a known issue?
Hello, forgive me for asking a possibly elementary question, but I am confused on how to get my on_someTarget methods to report an error (similar to yyerror) when an invalid input is passed into the parser. Ideally I want the code to print a message when there is an error to let the user know when the input does not follow the grammar rules. I need an answer pretty fast so if anyone can shed some light on how this works that would be wonderful.
Hi,
I don't know how much this repo is still maintained, but I would really want to see this to work on OS X. I attempted a quick change in setup.py to allow OS X to be treated just like linux:
https://github.com/thisiscam/pybison/blob/mac/setup.py#L19
Then, somehow when I run the calculator example, I will get error when the shared library is being compiled by distutils:
So I made a hacky fix here: https://github.com/thisiscam/pybison/commit/533b5e070a822599e8dcdf33319dd996c3f27870#diff-665d1650a9ed6aa0aca6fad5f2ba1b41R540
(Maybe someone can tell me why distutils's Compiler works on linux but not on Mac? So I can make a more appropriate fix?)
Finally, the thing that I'm currently running into when I run the calc example:
Segmentation fault: 11
A more detailed trace on gdb shows:
If anyone knows anything or is interested, I have a branch here https://github.com/thisiscam/pybison/tree/mac for my above attempts on OS X.
hi.
how can have better and PowerFull error manager(like bison)?
may say a example?
i want to compile calc1 of https://github.com/smvv/pybison using python 2.7 but show error.
My OS is GNU/Linux Ubuntu 16.10-64bit(GNOME)
calc test ==> is right.
calc1 test ==> have problem.
=============
information of flex :
root@system:/home/guest/Project/pybison-master# flex -V
flex 2.6.1
information of bison :
root@system:/home/guest/Project/pybison-master# bison -V
bison (GNU Bison) 3.0.4
Written by Robert Corbett and Richard Stallman.
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
information of gcc :
root@system:/home/guest/Project/pybison-master# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.2.0-5ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)
information of cython :
root@system:/home/guest/Project/pybison-master# cython -V
Cython version 0.24.1
Error Of PyCharm IDE:
tmp.tab.c:1302:16: warning: implicit declaration of function ‘yylex’ [-Wimplicit-function-declaration]
yychar = yylex ();
^~~~~
tmp.tab.c:2063:9: warning: implicit declaration of function ‘yyerror’ [-Wimplicit-function-declaration]
yyerror (yymsgp);
^~~~~~~
./tmp.l:3:5: error: redefinition of ‘yylineno’
int yylineno = 0;
^~~~~~~~
lex.yy.c:340:5: note: previous definition of ‘yylineno’ was here
int yylineno = 1;
^~~~~~~~
./tmp.l: In function ‘yylex’:
./tmp.l:36:10: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘char *’ [-Wformat=]
. { printf("unknown char %c ignored, yytext=0x%lx\n", yytext[0], yytext); /* ignore bad chars */}
^
./tmp.l: At top level:
./tmp.l:41:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
^
Traceback (most recent call last):
File "/home/guest/PycharmProjects/Interpreter/main.py", line 251, in <module>
p = Parser(keepfiles=0)
File "/usr/local/lib/python2.7/dist-packages/bison/__init__.py", line 159, in __init__
self.engine = ParserEngine(self)
File "bison_.pyx", line 123, in bison_.ParserEngine.__init__
File "bison_.pyx", line 144, in bison_.ParserEngine.openCurrentLib
File "bison_.pyx", line 525, in bison_.ParserEngine.buildLib
File "/usr/lib/python2.7/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/usr/lib/python2.7/distutils/unixccompiler.py", line 124, in _compile
raise CompileError, msg
distutils.errors.CompileError: command 'cc' failed with exit status 1
Process finished with exit code 1
How can I fix this problem?
When I run bison2python from Linux terminal it returns the error:
ImportError: cannot import name bisonToPython
Same error is also produced when I use following command in the Python shell
from bison import bisonToPython
Dear @smvv,
I write to ask about the current status of the project.
Me and my team use your tool for one of our projects (hopefully soon getting published on github) and would like to add several small features to pybison, including:
Looking at the network graph it seems that @csarn has ported the project to python3 and started some work there. I would cleanup our commits and merge our changes with his projects state.
Are these changes in comply with your project ideas?
Best regards,
da-h
Hello,
I read in the documentation that executing multiple parsers at the same time causes problems, I have indeed seen this issues.
Could you please elaborate further on what should be changed in order to avoid this?
Thanks.
EDIT: To be more precise I have noticed that bad things happen when I run a parser multiple times within a script (even if it is not really concurrent, or at least I dont think so). Usually once the parser has parsed a file and finished, it will keep returning the same object even if another run with another file is performed. I have tried to run parser.reset() with no luck. Could this have to do with the Lexer and the fact that EOF is my final symbol? I mean what happens when the parser reaches the end of a file? can I keep using that object?
I have also tried to create new instances for each parsing within the same script, but the same seems to happen (either that or the parser returns None)
I am getting following error while Running "python -c import bison"
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/bison.py", line 23, in
from bison_ import ParserEngine
ImportError: /usr/local/lib/python2.7/dist-packages/bison_.so: undefined symbol: py_callback
Hello,
I have been using pybison for some days now and I have come across what I believe is a "bug".
The issue appears whenever the parser throws an error. For example, when I try to parse a file with a syntax error I get the following:
Traceback (most recent call last):
File "./run_parser.py", line 15, in
sv_parser.run(read = file_input.read)
File "/bison/init.py", line 264, in run
self.report_last_error(filename, e)
File "/bison/init.py", line 340, in report_last_error
if not self.interactive:
AttributeError: 'SystemVerilogParser' object has no attribute 'interactive'
if I go to the line where the error is reported this is what is there:
` if not self.interactive:
raise
if self.verbose:
traceback.print_exc()
print 'ERROR:', error
`
Apparently the function report_last_error() tries to check the value of self.interactive, however I see no reference to an attribute called "interactive" anywhere before.
I worked around the issue by declaring an "interactive" attribute in my parser subclass with value True/False. I don't know if this was the original intent and this is just not explained in the documentation (or at least I have not seen it) or if this attribute is suposed to be declared inside BisonParser itself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.