\n {return 0;} . {return yytext[0];} %% YACC %{ #include<stdio.h> %} %token NUMBER ID %left '+' '-' %left '*' '/' %% expr: expr '+' expr |expr '-' expr |expr '*' expr |expr '/' expr |'-'NUMBER |'-'ID |'('expr')' |NUMBER |ID ; %% main() { printf("Enter the expression\n"); yyparse(); printf("\nExpression is valid\n"); exit(0); } int yyerror(char *s) { printf("\nExpression is invalid"); exit(0); } 31. Program to recognize a valid variable, which starts with a letter, followed by any number of letters or digits. LEX %{ #include"y.tab.h" extern yylval; %} %%
\n {return 0;} . {return yytext[0];} %% YACC %{ #include<stdio.h> %} %token NUMBER ID %left '+' '-' %left '*' '/' %% expr: expr '+' expr |expr '-' expr |expr '*' expr |expr '/' expr |'-'NUMBER |'-'ID |'('expr')' |NUMBER |ID ; %% main() { printf("Enter the expression\n"); yyparse(); printf("\nExpression is valid\n"); exit(0); } int yyerror(char *s) { printf("\nExpression is invalid"); exit(0); } 31. Program to recognize a valid variable, which starts with a letter, followed by any number of letters or digits. LEX %{ #include"y.tab.h" extern yylval; %} %%
compiler_design_manual.docx