c++ – Bison: integer out of range
I am trying to make a simple compiler to base the language im trying to make off of. However, while trying to code the simple calculator myself, it pulls an error:
error: integer out of range: '$1'
error: integer out of range: '$2'
error: integer out of range: '$3'
Here is my code:
parser,y
%{
#include<stdio.h>
int regs[26];
int base;
%}
%token<val> NUMBER LETTER PLUS MINU SLAS MULT
%left "+" "-"
%left "*" "/"
%type<val> expr
%%
expr: expr
| { $$ = $2 }
|
NUMBER PLUS NUMBER
| { $$ = $1 + $3}
;
%%
int main()
{
return(yyparse());
}
void yyerror(s)
char *s;
{
fprintf(stderr, "%s\n",s);
}
int yywrap()
{
return(1);
}
lexer.l
%{
#include <stdio.h>
#include "parser.tab.h"
int c;
%}
%%
[a-zA-Z]* { return LETTER; }
[0-9]* { yylval = strtol(yytext, NULL, 10); return NUMBER; }
(\+) { return PLUS; }
(\*) { return MULT; }
(\/) { return SLAS; }
(\-) { return MINU; }
%%
This code was based off of the IBM example and a few stack overflow posts.
Any ideas? Thanks!
Read more here: Source link
