The code is for study bison and flex, I am new but I want to learn to handle them.
I'm trying to run this code but I don't know where the mistake is because the compiler says it is ok, but I don't know why there is the error when I test with the number +573002597643. It is a number that's valid because I tried taking care of my rules.
My code:
bison:
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
extern int yyparse();
extern FILE* yyin;
void yyerror(const char* s);
%}
%union {
int ival;
float fval;
}
%token S_COL
%token<ival> I_AUX I_REGFIJO I_REGCEL I_NUMFIJO
%token T_NEWLINE T_QUIT
%start calculation
%%
calculation: T_NEWLINE
| S_COL I_REGCEL I_AUX I_NUMFIJO{ printf("Number phone: \n"); }
| S_COL I_REGFIJO I_REGFIJO I_NUMFIJO{ printf("Number local phone: \n"); }
| T_QUIT T_NEWLINE { printf("bye!\n"); exit(0); }
;
%%
int main() {
yyin = stdin;
do {
yyparse();
} while(!feof(yyin));
return 0;
}
void yyerror(const char* s) {
fprintf(stderr, "Parse error: %s\n", s);
exit(1);
}
flex file
%option noyywrap
%{
#include <stdio.h>
#define YY_DECL int yylex()
#include "tel.tab.h"
%}
%%
[ \t] ; // ignore all whitespace
\n {return T_NEWLINE;}
[1-9] {return I_REGFIJO;}
[0-9] {return I_AUX;}
[3][0-9][0-9] {return I_REGCEL;}
[\+][5][7] {return S_COL;}
[0-9][0-9][0-9][0-9][0-9][0-9] {return I_NUMFIJO;}
"exit" {return T_QUIT;}
"quit" {return T_QUIT;}
%%