896+ Capstone Project is Available: Whatsapp: +91-7011258995, Email: sharecodepoint@gmail.com

Program to recognize a valid variable, which starts with a letter, followed by any number of letters or digits. | Compiler Design Lab Programs | Yacc Programs


Yacc Part :

%token DIGIT LETTER NL UND
%%
stmt : variable NL { printf(“Valid Identifiers\n”); exit(0);}
 ;

variable : LETTER alphanumeric
 ;
alphanumeric: LETTER alphanumeric
 | DIGIT alphanumeric
 | UND alphanumeric
 | LETTER
 | DIGIT
 | UND
 ;
%%
int yyerror(char *msg)
{
 printf(“Invalid Expression\n”);
 exit(0);
}
main ()
{
 printf(“Enter the variable name\n”);
 yyparse();

Lex Part :

%{
 #include “y.tab.h”
%}
%%
[a-zA-Z] { return LETTER ;}
[0-9] { return DIGIT ; }
[\n] { return NL ;}
[_] { return UND; }
. { return yytext[0]; }
%%

Sharecodepoint

Sharecodepoint is the junction where every essential thing is shared for college students in the well-defined packets of codes. We are focused on providing you the best material package like Question papers, MCQ'S, and one NIGHT STUDY MATERIAL. facebook twitter youtube instagram

Post a Comment

Previous Post Next Post

Contact Form