Saturday, October 8

YACC program to convert infix

%{#include<stdio.h>
#include<ctype.h>
%}
%token num
%left '+''-'
%left '*' '/'
%%
s:e'\n'{}
e:e'+'e{printf("+");}
|e'-'e{printf("-");}
|e'/'e{printf("/");}
|e'*'e{printf("*");}
|num1{printf("%d",$1);}
num1:num1 num {$$=$1*10+$2;}
|num
;
%%
yylex()
{
 int c;
 c=getchar();
if(isdigit(c))
{ yylval=c-'0';
 return num;
}return c;
}
int main()
{
 yyparse();
return 1;
}
int yyerror()
{
return 1;
}
int yywrap()
{
 return 1;
}

9 comments :

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

thanh you...........

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

it is very simple program ...n easy 2 understand......all lex n yacc programs r quite easy 2 understand........thank you ........thank you.......

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

easily understanding code...
can u please help the code for , syntax analyzer for declaration and definition of user defined function in c... using lex and yacc concept..

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

output plz???

v!p!n said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Welcome Anonymous

v!p!n said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Welcome Anonymous.

Yup.. YACC is easily digesting dish,, ;)

v!p!n said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Sure Anonymous.

I will try to update it..!!

awesh said... Best Blogger Tips [Reply to comment] Best Blogger Templates

why this line "num1:num1 num {$$=$1*10+$2;}" when it is not necessary?

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Output please.

Post a Comment