Enter your email address & Win:

System Software Lab Programs ( Lex and Yaac Programs ) 4a

// June 11th, 2009 // Educational, Engineering, Unix and System Software Lab // Written by sandeephegde

-->

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

………………………………………………………………………………………………………………………….
PART – A

………………………………………………………………………………………………………………………….

4) a. Program to recognize a valid arithmetic expression that uses operators+, -, * and /.

4a.l

%{
#include “y.tab.h”
extern int yylval;
%}

%%
[0-9]+ {yylval=atoi(yytext); return NUM; }
[ \t] ;
\n return 0;
. return yytext[0];
%%

———————————————–

4a.y

%{
#include<stdio.h>
%}

%%

%token NUM
%left ‘+’ ‘-’
%left ‘+’ ‘-’
%nonassoc UMINUS

%%

e:e’+'e |
e’-'e |
e’*'e |
e’/'e {if($3==0)  {printf(“\n DIVIDE BY ZERO ERROR”); exit(0);}} |
‘(‘e’)’ |
‘-’e %prec UMINUS |
NUM
;
%%

yyerror()
{
printf(“invalid exppression\n”);
exit(0);
}

int main()
{
printf(“enter an expression:”);
yyparse();
printf(“valid expression”);
return 0;
}




If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. System Software Lab Programs ( Lex and Yaac Programs ) 5a
  2. System Software Lab Programs ( Lex and Yaac Programs ) 6a
  3. System Software Lab Programs ( Lex and Yaac Programs ) 5b
  4. System Software Lab Programs ( Lex and Yaac Programs )2a.l
  5. System Software Lab Programs ( Lex and Yaac Programs )1b
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes