hi Manish,
Your files look fine. To compile and run calc, follow this sequence of
steps (or write these steps in a Makefile):
1. Compile a.y --> a.tab.c, a.tab.h
$ bison -d a.y
2. In your a.l lexer file replace the line
#include "example.parser.h"
with
#include "a.tab.h"
3. Comiple a.l --> lex.yy.c
$ flex a.l
4. Compile lex.yy.c -->lex.yy.o (compile only)
$ gcc -c lex.yy.c
5. Compile a.tab.c --> a.tab.o (Compile only)
$ gcc -c a.tab.c
6. Now link both into the final executable
$ gcc -o calc a.tab.o lex.yy.o
7. Execute calc program and enjoy your day
$ ./calc
Hope it helps
./satya.
On 5/31/06, Manish Katiyar <[EMAIL PROTECTED]> wrote:
Hello friends,
I downloaded the bison-2.1 and built it on an HPUX-Itanium machine.
Now whenever i try to compile the C file generated from bison I am
getting syntax errors. I am generating with the command "bison -d a.y"
and running it with "cc a.tab.c" ........Is there anything that we
need to specify on Itanium to work???
My .y file looks like this which I downloaded from a site. Please help
/* example.y */
%{
#define YYSTYPE int
%}
%token PLUS MINUS STAR LPAREN RPAREN NUMBER NEWLINE
%left PLUS MINUS
%left STAR
%%
line : /* empty */
| line expr NEWLINE { printf("%d\n", $2); }
expr : LPAREN expr RPAREN { $$ = $2; }
| expr PLUS expr { $$ = $1 + $3; }
| expr MINUS expr { $$ = $1 - $3; }
| expr STAR expr { $$ = $1 * $3; }
| NUMBER { $$ = $1; }
;
%%
int yyerror (char const *msg) {
printf("Error: %s\n", msg);
}
int main() {
printf("%d\n", yyparse());
return 0;
}
The Flex lexer used by this parser looks like this:
/* example.lex */
%{
#include "example.parser.h"
%}
%option noyywrap
%%
[ \t]+ { /* ignore whitespace */ }
"(" { return LPAREN; }
")" { return RPAREN; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return STAR; }
\n { return NEWLINE; }
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
. { printf("Invalid character '%s'", yytext); }
%%
The errors which i am getting are
Warning 361: "a.y", line 21 # Value-returning function might end
without executing a return statement.
int yyerror (char const *msg) {
^^^^^^^
Error 419: "a.y", line 30 # 'The' is used as a type, but has not been
defined as a type.
The Flex lexer used by this parser looks like this:
^^^
Error 20: "a.y", line 30 # ';' expected before 'lexer'.
The Flex lexer used by this parser looks like this:
^^^^^
Error 419: "a.y", line 30 # 'lexer' is used as a type, but has not
been defined as a type.
The Flex lexer used by this parser looks like this:
^^^^^
Error 20: "a.y", line 30 # ';' expected before 'by'.
The Flex lexer used by this parser looks like this:
^^
Error 419: "a.y", line 30 # 'by' is used as a type, but has not been
defined as a type.
The Flex lexer used by this parser looks like this:
^^
Error 20: "a.y", line 30 # ';' expected before 'parser'.
The Flex lexer used by this parser looks like this:
^^^^^^
Error 419: "a.y", line 30 # 'parser' is used as a type, but has not
been defined as a type.
The Flex lexer used by this parser looks like this:
--
Thanks & Regards,
********************************************
Manish Katiyar
Ozone 2, SP Infocity (Software Park),
New Survey #208 Manjari Stud Farms Ltd.,
Phursungi Village, Haveli Taluka, Saswad Road,
Hadapsar, Pune - 412308, India
***********************************************
_______________________________________________
[email protected] http://lists.gnu.org/mailman/listinfo/help-bison
--
"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth".
-Sherlock Holmes, The sign of four.
_______________________________________________
[email protected] http://lists.gnu.org/mailman/listinfo/help-bison