Professional Documents
Culture Documents
CD Practical6
CD Practical6
Practical-6
AIM: Write a program to validate the variable declaration statement using Lex and
YACC.
Code:
pr6.lex
%{
#include <stdio.h>
#include "y.tab.h"
%}
%%
"int"|"float"|"char"|"String" return BUILTIN;
"new" return NEW;
"[" return OPEN_SQ;
"]" return CLOSE_SQ;
"=" return EQ;
"," return COMMA;
";" return SC;
[_a-zA-Z][_a-zA-Z0-9]* return ID;
[0-9]+ return DIGIT;
\n return 0;
%%
pr6.yacc
%{
#include <stdio.h>
#include <ctype.h>
#include <string.h>
{
printf("\nEnter Declaration Statement: ");
yyparse();
}
void yyerror(char *s) {
fprintf(stderr, "%s\n", s);
}
Output: