flex-bison-in-action/tutorial/test.l

37 lines
859 B
Plaintext
Raw 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 "test.tab.h"
В файле test.l есть строка:
c
Copy
#include "test.tab.h"
// Этот заголовочный файл генерируется Bison'ом и содержит:
// 2. Содержимое test.tab.h (примерно)
// typedef union {
// char *str;
// } YYSTYPE;
// extern YYSTYPE yylval;
// #define TEXT 258
// #define LBRACE 259
// #define RBRACE 260
#include <stdio.h>
#include <string.h>
void yyerror(const char *s);
%}
%%
"{" { return LBRACE; }
"}" { return RBRACE; }
[^{}]+ { // [^{}]+ = "один или больше символов, ни один из которых не является { или }"
yylval.str = strdup(yytext); // сохранение данных
return TEXT; } // возвращение типа токена
. { }
%%
int yywrap() {
return 1;
}