/
niceSOFT
/
flex
Обзор
Документация
Войти
/
niceSOFT
/
flex
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/manual/example_er.lex
35 строк
706 B
Eric S. Raymond
Update all the examples to use the new API elements.
13 окт 2020, 04:07
13 окт 2020, 04:07
8d0162b
Код
Авторство
О чём код?
/* basic example, fully reentrant thread-safe version */ %{ struct stats { int num_lines; int num_chars; }; %} %option reentrant noyywrap %option extra-type="struct stats" %% \n { struct stats ns = yyget_extra(yyscanner); ++ns.num_lines; ++ns.num_chars; yyset_extra(ns, yyscanner); } . { struct stats ns = yyget_extra(yyscanner); ++ns.num_chars; yyset_extra(ns, yyscanner); } %% int main() { yyscan_t scanner; struct stats ns; yylex_init ( &scanner ); yylex ( scanner ); ns = yyget_extra(scanner); printf( "# of lines = %d, # of chars = %d\n", ns.num_lines, ns.num_chars); yylex_destroy ( scanner ); }