lukeparser/pybison

C & Java examples fail to run

Opened this issue · 11 comments

The examples are built without issue, but running them raises multiple warnings and errors. The message starts with

/tmp/pybison/pybison_Parser/tmp.y:9:1: warning: ‘dllexport’ attribute directive ignored [-Wattributes]
 __attribute__ ((dllexport)) char *rules_hash = "e75e4fff863f00275cca52cdad5000500054ed4d";
 ^~~~~~~~~~~~~
/tmp/pybison/pybison_Parser/tmp.y: In function ‘yyparse’:
/tmp/pybison/pybison_Parser/tmp.y:58:19: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
           $$ = (*py_callback)(

followed by many assignment from int without cast warnings and ends with

tmp.tab.c:6024:18: warning: passing argument 1 of ‘yyerror’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
In file included from /tmp/pybison/pybison_Parser/tmp.y:3:0:
/tmp/pybison/pybison_Parser/tmp.y:27:5: note: expected ‘char *’ but argument is of type ‘const char *’
 int yyerror(char *msg);
     ^~~~~~~
/tmp/pybison/pybison_Parser/tmp.y: At top level:
/tmp/pybison/pybison_Parser/tmp.y:3444:1: warning: ‘dllexport’ attribute directive ignored [-Wattributes]
 {
 ^
/tmp/pybison/pybison_Parser/tmp.l:20:10: fatal error: tokens.h: No such file or directory
 #include "tokens.h"
          ^~~~~~~~~~
compilation terminated.
Traceback (most recent call last):
  File "/usr/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
    extra_postargs)
  File "/usr/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/usr/lib/python3.6/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/usr/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
    % (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'cc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c.py", line 1162, in <module>
    main(*(sys.argv[1:]))
  File "c.py", line 1157, in main
    p = Parser(verbose=verbose, keepfiles=keepfiles)
  File "/home/alex/.local/lib/python3.6/site-packages/bison/__init__.py", line 224, in __init__
    self.engine = ParserEngine(self)
  File "src/bison/cython/bison_.pyx", line 135, in bison.bison_.ParserEngine.__init__
  File "src/bison/cython/bison_.pyx", line 172, in bison.bison_.ParserEngine.openCurrentLib
  File "src/bison/cython/bison_.pyx", line 691, in bison.bison_.ParserEngine.buildLib
  File "/usr/lib/python3.6/distutils/ccompiler.py", line 574, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/usr/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'cc' failed with exit status 1

I get the same message for both C and Java examples. The issue is similar to #19 and was supposedly fixed in the latest version.

OS: Ubuntu 18.04.5 (also tested on CentOS 7 & 8)

Tool versions: flex 2.6.4 (latest), bison 3.0.4 (latest), pybison 0.2.9 (latest)

Hey @AlexPoupakis, thanks for reaching out!

I fixed the error: tokens.h: No such file or directory, this will get the example parser compile again.

But, the examples are a little bit out of date, so they are currently not running.

I added a short introduction in the README.md on debugging, so that you can better debug the parser you are creating.

Thanks @sbrodehl. I updated pybison (even uninstalling and re-installing it) but still get the error: tokens.h: No such file or directory...

Have you used the updated example files as well? Which example do you use?

Ahh sorry, I was using the old ones for C. Something else I noticed is that in the python script, you are calling main with a tuple and then calling args.remove(). Since args contains just a tuple, remove will cause an error because tuples are immutable.

@sbrodehl I am also unable to run the examples for C and Java as well, I got the error
self.engine.runEngine(debug)
NameError: name 'debug' is not defined

I am using ubuntu 18.04, and I have python 3.6.9 installed

Hi @yh0508619,
the variable debugshould be defined 🤔
What version are you using? Maybe try the latest release?

On a general note, the examples and tests are very outdated and do not work with current flex/bison versions!

@sbrodehl Thanks for your rapid response
I am using the latest version on the github.
The versions for bison and flex are:
bison (GNU Bison) 3.0.4
flex 2.6.4

Hi @sbrodehl

Sorry to bother you again, which python version you are using ? I installed python 3.9, but error becomes:
ImportError: cannot import name 'BisonParser' from 'bison'

Thanks!

Have you installed the pybison package? Make sure to build the shared libraries, e.g. using python setup.py build.

Have you installed the pybison package? Make sure to build the shared libraries, e.g. using python setup.py build.

Yeah, bison, flex and pybison are installed

Sorry, I can not reproduce this.
Maybe submit a detailed report as a separate issue?