I've been trying to compile my Bison code and it seems to be that something is wrong with my code and yet I just can't figure out why or where.
Here is my bison code, I am running GNU Bison 2.3 on OSX. The error I am receiving is:
romans.y:9.9-21: syntax error, unexpected string, expecting =
This is an error I do not appear to be receiving on my Linux machine but on the OSX machine
%{
// file created via echo
# include <stdio.h>
# include <stdlib.h>
int yyerror(char *s);
int yylex();
int yyparse();
%}
%output "roman.tab.c"
%token ARABIC_NUMERAL;
%token EOL
%%
calclist: /* nothing */ {}
| calclist arabic_numerals EOL { printf("%d\n", $2); }
;
arabic_numerals: ARABIC_NUMERAL
| ARABIC_NUMERAL { $$ = $$ + $2; }
;
/* ones:
| ONE {$$ = 1;}
| ONE ONE {$$ = 2;}
| ONE ONE ONE {$$ = 3;}
;
fives:
| FOUR {$$ = 4;}
| FIVE {$$ = 5;}
| FIVE ones { $$ = 5 +$2;}
;
tens:
| TEN {$$ = 10;}
| TEN TEN { $$ = 20;}
| TEN TEN TEN { $$ = 30;}
| TEN fives { $$ = 10 + $2}
| NINE { $$ = 9}
;
fifties:
| FIFTY { $$ = 50;}
|
:*/
%%
void yyerror(char *s)
{
printf("error: %s\n", s);
exit(0);
}
int
main()
{
// yydebug = 1;
yyparse();
return 0;
}
I have based my code off a program given to me by my professor, which is the following. When I attempted to compile it myself, I have the exact same issue. Is it a problem with the version of bison on my system?
%{
# include <stdio.h>
# include <stdlib.h>
void yyerror(char *s);
int yylex();
int yyparse();
%}
%output "brackets.c"
%token OP CP N EOL
%%
calclist: /* nothing */ {}
| calclist expr EOL { printf("Input conforms to grammar\n"); }
;
//expr: N N N { }
//;
expr: OP expr CP
| N
;
%%
void yyerror(char *s)
{
printf("error: %s\n", s);
}
int
main()
{
// yydebug = 1;
yyparse();
return 0;
}