Академический Документы
Профессиональный Документы
Культура Документы
LEX:
%{
#include"y.tab.h"
%}
LINE "/"
%%
^[+-]?(([1-9][0-9]*)|(0))/{LINE} {yylval=atoi(yytext); return NUM;}
\/[+-]?[0]$ {yylval=atoi(yytext+1); return DEN1;}
\/[+-]?([1-9][0-9]*)$ {yylval=atoi(yytext+1); return DEN;}
([a-zA-z ]*[0-9]*)* {return ER;}
\n | . ;
YACC:
%{
#include <stdio.h>
%}
%start list
%token NUM DEN DEN1 ER
%%
list:
|list drob
;
drob: NUM DEN {printf("Result = %.3E\n",(double)$1/$2); return 0;}
|NUM DEN1 {puts("ZERO FAKE"); return 0;}
|NUM ER {puts("ERROR"); return 0;}
;
%%
int yyerror()
{puts("ERROR");}
int yywrap()
{return 0;}
main()
{yyparse();}