SPCC Exp3
SPCC Exp3
Experiment No: 3
Lex Program:
%{
/* Definition section*/
#include "y.tab.h"
extern yylval;
%}
%%a
[0-9]+ {
yylval = atoi(yytext);
return NUMBER;
}
[a-zA-Z]+ { return ID; }
\n { return 0; }
. { return yytext[0]; }
%%
Yaac Program :
%{
#include <stdio.h>
Universal College of Engineering, Kaman
Department of Computer Engineering
Subject: SPCC
#include <stdlib.h>
%}
%token NUMBER ID
%%
/* Grammar rules */
E:T{
printf("Result = %d\n", $$); return 0;
}
%%
int main() {
printf("Enter the expression:\n"); yyparse();
return 0;
}
/* Error handling function */ int
yyerror(const char* s) {
printf("\nExpression is invalid\n"); return 0;
Universal College of Engineering, Kaman
Department of Computer Engineering
Subject: SPCC
Output: