Name: Shubhangi Mapare Roll no: 17112
Div: TE A Subject: SPOS Lab
Assignment No: B4
Problem statement: Write a program using YACC specifications to implement syntax analysis
phase of compiler to validate type and syntax of variable declaration in Java
Input code:
validate.l
%{
#include "y.tab.h"
%}
%%
int|float|char|double return DT;
"," return COMMA;
";" return SC;
[a-zA-Z][a-zA-Z0-9_]* return ID;
[0-9]+ return NUM;
"=" return EQ;
%%
int yywrap()
{
return 1;
}
validate.y
%{
#include<stdio.h>
%}
%token ID DT SC COMMA NUM EQ
%%
start1:DT varlist SC {printf("valid\n");exit(0);};
varlist:ID EQ NUM
|ID
|varlist COMMA ID EQ NUM
|varlist COMMA ID
;
%%
main()
{
printf("Enter the exp: ");
yyparse();
}
int yyerror(char *s)
{
fprintf(stderr,"%s\n",s);
}
Output: