YACC Program to Check Variable Declaration
This is the yacc program to validate variable declaration syntax and semantics using regular expressions
Lex Program:
%{
#include<stdio.h>
#include "y.tab.h"
%}
%%
int|float|char return BUILTIN;
"," return COMMA;
";" return SC;
[a-zA-Z]+[a-zA-Z0-9]* return ID;
"n" return NL;
%%
YACC Program:
%{
#include<stdio.h>
%}
%token ID BUILTIN SC NL COMMA
%%
start:BUILTIN varlist SC NL {printf("valid");}
|
varlist:varlist COMMA ID|ID;
%%
void yyerror(const char *str){printf("error");}
int yywrap(){return 0;}
main(){yyparse();}
how to add ‘ _ ‘ in ID