7 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * SPDX-License-Identifier: LGPL-2.1-only
14 #include "filter-ast.h"
15 #include "filter-parser.h"
18 void setstring(struct filter_parser_ctx *parser_ctx, YYSTYPE *lvalp, const char *src);
20 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
21 __attribute__((unused));
22 static int input (yyscan_t yyscanner) __attribute__((unused));
26 %x comment_ml comment_sl string_lit char_const
27 %option reentrant yylineno noyywrap bison-bridge
28 %option extra-type="struct filter_parser_ctx *"
37 IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))
39 INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
44 UCHARLOWERCASE \\u{HEXDIGIT}{4}
45 UCHARUPPERCASE \\U{HEXDIGIT}{8}
47 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}|{ID_EXTRA_CHAR}
48 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
49 ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
53 * Using start conditions to deal with comments
57 "/*" BEGIN(comment_ml);
58 <comment_ml>[^*\n]* /* eat anything that's not a '*' */
59 <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
60 <comment_ml>\n ++yylineno;
61 <comment_ml>"*"+"/" BEGIN(INITIAL);
63 "//" BEGIN(comment_sl);
64 <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
66 L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
67 \' BEGIN(char_const); return CHARACTER_CONSTANT_START;
68 <char_const>\' BEGIN(INITIAL); return SQUOTE;
70 L\" BEGIN(string_lit); return STRING_LITERAL_START;
71 \" BEGIN(string_lit); return STRING_LITERAL_START;
72 <string_lit>\" BEGIN(INITIAL); return DQUOTE;
74 <char_const,string_lit>ESCSEQ return ESCSEQ;
75 <char_const,string_lit>\n ; /* ignore */
76 <char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
79 0[xX]{H}+{IS}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
80 0[0-7]*{IS}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
81 [1-9]{D}*{IS}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
83 {D}+{E}{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
84 {D}*"."{D}+{E}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
85 {D}+"."{D}*{E}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
86 0[xX]{H}+{P}{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
87 0[xX]{H}*"."{H}+{P}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
88 0[xX]{H}+"."{H}*{P}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT;
104 ">>" return RIGHT_OP;
119 ";" return SEMICOLON;
120 "..." return DOTDOTDOT;
128 "$"{IDENTIFIER} printf_debug("<GLOBAL_IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); return GLOBAL_IDENTIFIER;
129 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); return IDENTIFIER;
130 [ \t\n]+ ; /* ignore */