lukeparser / pybison

Use Bison directly from Python
https://pypi.org/project/pybison
GNU General Public License v2.0
26 stars 6 forks source link

Walkthrough tutorial doesn't work #42

Closed RobertoCapoferri closed 1 year ago

RobertoCapoferri commented 1 year ago

I tried following the walkthrough but when i run my script it doesn't work. I do see warnings from the compilation, so it is doing something but the parser doesn't do anything no matter what i type. Below you can find the compilation output:

(.venv) skylake@LAPTOP:~/test-pybison$ ./run.py
tmp.y:9:1: warning: ‘dllexport’ attribute directive ignored [-Wattributes]
    9 | __attribute__ ((dllexport)) char *rules_hash = "e29390d88dafe94d44576021d631d35d8141573f";
      | ^~~~~~~~~~~~~
tmp.y: In function ‘yyparse’:
tmp.y:46:17: warning: assignment to ‘YYSTYPE’ {aka ‘int’} from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
   46 |           $$ = (*py_callback)(
      |                 ^

[ .... more warnings like the one above removed for clarity ... ]

tmp.y: At top level:
tmp.y:244:1: warning: ‘dllexport’ attribute directive ignored [-Wattributes]
  244 | {
      | ^

After this nothing happens when i type. Successive runs of the script, since the compilation is already done, do not output the warnings, i just get a blank line waiting for input that blocks my terminal until i press CTRL+Z.

Notes: The script is the same as the one in the walkthrough, i just changed the print to work on python 3

# from            
if option == 1:
    print "on_line: got exp %s" % items[0]
# to
if option == 1:
    print(f'on_line: got exp {items[0]}')

and comment out the int yylineno = 0; line, as the walkthrough says.

I am using the following version of software

pybison: 0.6.3
Python: 3.10.6
flex: 2.6.4
bison: 3.8.2
gcc: 11.3.0
sbrodehl commented 1 year ago

Hi @RobertoCapoferri,

thanks for pointing this out! Unfortunately, this walkthrough is very old (and outdated), and the used bison2py script only work for older bison files. (I think we pinned bison version 3.4 somewhere ...)

With a recent commit, I removed these outdated files, but also updated the calc example (which is now working again).

I hope this gets you up and running and provides a good base for your project, best of luck!

RobertoCapoferri commented 1 year ago

Thank you, i was able to run the example code.