Why do I get "parser name defined to default :"parse" when I try to run my lex and yacc program?

178 Views Asked by At

I just installed Lex and Yacc in my Ubuntu Virtual Machine (14.02 LTS) and I am trying to run a Yacc program for the first time (Lex programs work fine), but i am getting the following error:

parser name defined to default :"parse"

The code I have entered in is as follows:

1b.lex

%{
#include "y.tab.h"
extern yylval;
%}
%%
[0-9]+ {yylval=atoi(yytext);return num;}
[\+\-\*\/] {return yytext[0];}
[)] {return yytext[0];}
[(] {return yytext[0];}
. {;}
\n {return 0;}
%%

1b.y

%{
#include<stdio.h>
#include<stdlib.h>
%}
%token num
%left '+' '-'
%left '*' '/'
%%
input:exp {printf("%d\n",$$);exit(0);}exp:exp'+'exp {$$=$1+$3;}
|exp'-'exp{$$=$1-$3;}
|exp'*'exp{$$=$1*$3;}
|exp'/'exp { if($3==0){printf("Divide by Zero\n");exit(0);}
else
$$=$1/$3;}
|'('exp')'{$$=$2;}
|num{$$=$1;};
%%
int yyerror()
{
printf("error");
exit(0);
}
int main()
{
printf("enter an expression\n");
yyparse();
}

Commands keyed in to get output lex 1b.lex (Successful) yacc –d 1b.y (I get the error when i key in this line)

The code I have must according to my knowledge be 100% correct, as I copiedit out from my college manual just to check whether or not my lex and yacc works fine.

Maybe I missed something during the installation procedure?


Command keyed in to install lex and yacc

  1. sudo apt-get update 2.sudo apt-get install flex 3.sudo apt-get install bison 4.sudo apt-get install byacc 5.sudo apt-get install bison++ 6.sudo apt-get install byacc -j

All the commands mentioned above were successfully ran.

0

There are 0 best solutions below