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 6

Write YACC program to recognize valid identifier, operators and keywords in the given text (C program) file




Advertisement



Advertisement

Lex Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
%{
#include <stdio.h>
#include "y.tab.h"
extern yylval;
%}

%%
[ \t];
[+|-|*|/|=|<|>] {printf("operator is %s\n",yytext);return OP;}
[0-9]+ {yylval = atoi(yytext); printf("numbers is %d\n",yylval); return DIGIT;} 
int|char|bool|float|void|for|do|while|if|else|return|void {printf("keyword is %s\n",yytext);return KEY;}
[a-zA-Z0-9]+ {printf("identifier is %s\n",yytext);return ID;}
. ;
%%

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
31
32
33
34
35
36
37
38
39
40
41
42
43
%{
#include <stdio.h>
#include <stdlib.h>
int id=0, dig=0, key=0, op=0;
%}
%token DIGIT ID KEY OP

%%
input:
DIGIT input { dig++; }
| ID input { id++; }
| KEY input { key++; }
| OP input {op++;}
| DIGIT { dig++; }
| ID { id++; }
| KEY { key++; }
| OP { op++;}
;
%%

#include <stdio.h>
extern int yylex();
extern int yyparse();
extern FILE *yyin;
main() 
{
	FILE *myfile = fopen("f2.c", "r"); 
	if (!myfile) 
	{
		printf("I can't open f2.c!");
		return -1;
	}
	yyin = myfile;
	do{
		yyparse();
	}while (!feof(yyin));
	printf("numbers = %d\nKeywords = %d\nIdentifiers = %d\noperators = %d\n",dig, key,id, op);
}

void yyerror() {
	printf("EEK, parse error! Message: ");
	exit(-1);
}

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