Note that there are some explanatory texts on larger screens.

plurals
  1. POuse bison to make executable file but error
    text
    copied!<p>I followed the <a href="http://aquamentus.com/flex_bison.html" rel="nofollow">Flex and Bison tutorial</a> to learn flex &amp; bison , but I'm stuck. When I compile with "g++ snazzle.tab.c lex.yy.c -lfl -o snazzle", I get these error messages:</p> <pre><code> snazzle.tab.c: In function ‘int yyparse()’: snazzle.tab.c:1403: warning: deprecated conversion from string constant to ‘char*’ snazzle.tab.c:1546: warning: deprecated conversion from string constant to ‘char*’ /tmp/ccFyBCBm.o: In function `yyparse': snazzle.tab.c:(.text+0x1e0): undefined reference to `yylex' collect2: ld returned 1 exit status </code></pre> <p>my env is ubuntu 10.04 bison 2.4.1 flex 2.5.35</p> <p>I still can not find the problem. first I compile with "bison -o snazzle.y", then it generate two snazzle.tab.c and snazzle.tab.h respectively. finally I compile with "g++ snazzle.tab.c lex.yy.c -lfl -o snazzle". my code as follew : </p> <pre><code>snazzle.l %{ #include &lt;cstdio&gt; #include &lt;iostream&gt; using namespace std; #include "snazzle.tab.h" %} %% [ \t] ; [0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; } [0-9]+ { yylval.ival = atoi(yytext); return INT; } [a-zA-Z0-9]+ { // we have to copy because we can't rely on yytext not changing underneath us: yylval.sval = strdup(yytext); return STRING; } . ; %% </code></pre> <hr> <pre><code>snazzle.y %{ #include &lt;cstdio&gt; #include &lt;iostream&gt; using namespace std; extern "C" int yylex(); extern "C" int yyparse(); extern "C" FILE *yyin; void yyerror(char *s); %} %union { int ival; float fval; char *sval; } %token &lt;ival&gt; INT %token &lt;fval&gt; FLOAT %token &lt;sval&gt; STRING %% snazzle: INT snazzle { cout &lt;&lt; "bison found an int: " &lt;&lt; $1 &lt;&lt; endl; } | FLOAT snazzle { cout &lt;&lt; "bison found a float: " &lt;&lt; $1 &lt;&lt; endl; } | STRING snazzle { cout &lt;&lt; "bison found a string: " &lt;&lt; $1 &lt;&lt; endl; } | INT { cout &lt;&lt; "bison found an int: " &lt;&lt; $1 &lt;&lt; endl; } | FLOAT { cout &lt;&lt; "bison found a float: " &lt;&lt; $1 &lt;&lt; endl; } | STRING { cout &lt;&lt; "bison found a string: " &lt;&lt; $1 &lt;&lt; endl; } ; %% main() { // open a file handle to a particular file: FILE *myfile = fopen("a.snazzle.file", "r"); // make sure it is valid: if (!myfile) { cout &lt;&lt; "I can't open a.snazzle.file!" &lt;&lt; endl; return -1; } // set flex to read from it instead of defaulting to STDIN: yyin = myfile; // parse through the input until there is no more: do { yyparse(); } while (!feof(yyin)); } void yyerror(char *s) { cout &lt;&lt; "EEK, parse error! Message: " &lt;&lt; s &lt;&lt; endl; // might as well halt now: exit(-1); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload