Future Vision BIE Future Vision BIE


ONE STOP FOR ALL STUDY MATERIALS & LAB PROGRAMS


E MENU Whatsapp Share Join Telegram, to get Instant Updates
× NOTE! Click on MENU to Browse between Subjects...

Advertisement

SYSTEM SOFTWARE AND OPERATING SYSTEM LABORATORY

[As per Choice Based Credit System (CBCS) scheme]

(Effective from the academic year 2017 - 2018)

SEMESTER - VI

Subject Code 17CSL67

IA Marks 40

Number of Lecture Hours/Week 01I + 02P

Exam Marks 60



17CSL67 - SYSTEM SOFTWARE AND OPERATING SYSTEM LABORATORY

Program 1 B

Write YACC program to evaluate arithmetic expression involving operators: +, -, *, and /




Advertisement



Advertisement

Yacc Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
%{
#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. Invalid expression.\n");exit(0);}
		else $$=$1/$3;}
		|'('exp')'{$$=$2;}
		|num{$$=$1;};
%%

int yyerror()
{
	printf("Error. Invalid Expression.\n");
	exit(0);
}
int main()
{
	printf("Enter an expression:\n");
	yyparse();
}

Lex Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
%{
#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;}
%%

Output


Program Output



× Note Page Number is specified to navigate between Pages...
SYS = Syllabus
P = Program


-ADMIN



× Note Do Share the website link with Your Friends and known Students...

-ADMIN

lIKE OUR CONTENT SUPPORT US BY FOLLOWING US ON INSTAGRAM : @futurevisionbie

Latest Updates are also posted in instagram as Stories...

For immediate Notification Join the Telegram Channel




Advertisement