flex-bison-in-action/analyzers/calc/calc.l

13 lines
836 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

%{
#include "calc.tab.h" // Автоматически создаётся Bison
%}
%%
[0-9]+ { yylval = atoi(yytext); return NUMBER; } // Если ввод - набор цифр, то возвращаем int
[-+*/()] { return yytext[0]; } // Если символ совпал с каким то из этих, то он возвращается, далее bison будет его использовать
[ \t] ; // Пробелы и табы игнорируются
\n { return 0; } // Энтер обозначает конец ввода
. { printf("unknown: %s\n", yytext); } // Неподдерживаемый символ
%%
int yywrap() { return 1; }