| 1 | %{ |
| 2 | /* |
| 3 | * filter-lexer.l |
| 4 | * |
| 5 | * LTTng filter lexer |
| 6 | * |
| 7 | * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU Lesser General Public License, version 2.1 only, |
| 11 | * as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include "filter-ast.h" |
| 21 | #include "filter-parser.h" |
| 22 | |
| 23 | extern |
| 24 | void setstring(struct filter_parser_ctx *parser_ctx, YYSTYPE *lvalp, const char *src); |
| 25 | |
| 26 | static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner) |
| 27 | __attribute__((unused)); |
| 28 | static int input (yyscan_t yyscanner) __attribute__((unused)); |
| 29 | |
| 30 | %} |
| 31 | |
| 32 | %x comment_ml comment_sl string_lit char_const |
| 33 | %option reentrant yylineno noyywrap bison-bridge |
| 34 | %option extra-type="struct filter_parser_ctx *" |
| 35 | /* bison-locations */ |
| 36 | |
| 37 | D [0-9] |
| 38 | L [a-zA-Z_] |
| 39 | H [a-fA-F0-9] |
| 40 | E ([Ee][+-]?{D}+) |
| 41 | P ([Pp][+-]?{D}+) |
| 42 | FS (f|F|l|L) |
| 43 | IS ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U)) |
| 44 | |
| 45 | INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) |
| 46 | DIGIT [0-9] |
| 47 | NONDIGIT [a-zA-Z_] |
| 48 | HEXDIGIT [0-9A-Fa-f] |
| 49 | OCTALDIGIT [0-7] |
| 50 | UCHARLOWERCASE \\u{HEXDIGIT}{4} |
| 51 | UCHARUPPERCASE \\U{HEXDIGIT}{8} |
| 52 | ID_EXTRA_CHAR (":"|".") |
| 53 | ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}|{ID_EXTRA_CHAR} |
| 54 | IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})* |
| 55 | ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+) |
| 56 | %% |
| 57 | |
| 58 | /* |
| 59 | * Using start conditions to deal with comments |
| 60 | * and strings. |
| 61 | */ |
| 62 | |
| 63 | "/*" BEGIN(comment_ml); |
| 64 | <comment_ml>[^*\n]* /* eat anything that's not a '*' */ |
| 65 | <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ |
| 66 | <comment_ml>\n ++yylineno; |
| 67 | <comment_ml>"*"+"/" BEGIN(INITIAL); |
| 68 | |
| 69 | "//" BEGIN(comment_sl); |
| 70 | <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL); |
| 71 | |
| 72 | L\' BEGIN(char_const); return CHARACTER_CONSTANT_START; |
| 73 | \' BEGIN(char_const); return CHARACTER_CONSTANT_START; |
| 74 | <char_const>\' BEGIN(INITIAL); return SQUOTE; |
| 75 | |
| 76 | L\" BEGIN(string_lit); return STRING_LITERAL_START; |
| 77 | \" BEGIN(string_lit); return STRING_LITERAL_START; |
| 78 | <string_lit>\" BEGIN(INITIAL); return DQUOTE; |
| 79 | |
| 80 | <char_const,string_lit>ESCSEQ return ESCSEQ; |
| 81 | <char_const,string_lit>\n ; /* ignore */ |
| 82 | <char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN; |
| 83 | |
| 84 | |
| 85 | 0[xX]{H}+{IS}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT; |
| 86 | 0[0-7]*{IS}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT; |
| 87 | [1-9]{D}*{IS}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT; |
| 88 | |
| 89 | {D}+{E}{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 90 | {D}*"."{D}+{E}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 91 | {D}+"."{D}*{E}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 92 | 0[xX]{H}+{P}{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 93 | 0[xX]{H}*"."{H}+{P}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 94 | 0[xX]{H}+"."{H}*{P}?{FS}? setstring(yyextra, yylval, yytext); return FLOAT_CONSTANT; |
| 95 | |
| 96 | "[" return LSBRAC; |
| 97 | "]" return RSBRAC; |
| 98 | "(" return LPAREN; |
| 99 | ")" return RPAREN; |
| 100 | "{" return LBRAC; |
| 101 | "}" return RBRAC; |
| 102 | "->" return RARROW; |
| 103 | |
| 104 | "*" return STAR; |
| 105 | "+" return PLUS; |
| 106 | "-" return MINUS; |
| 107 | |
| 108 | "%" return MOD_OP; |
| 109 | "/" return DIV_OP; |
| 110 | ">>" return RIGHT_OP; |
| 111 | "<<" return LEFT_OP; |
| 112 | |
| 113 | "==" return EQ_OP; |
| 114 | "!=" return NE_OP; |
| 115 | "<=" return LE_OP; |
| 116 | ">=" return GE_OP; |
| 117 | "<" return LT_OP; |
| 118 | ">" return GT_OP; |
| 119 | "&&" return AND_OP; |
| 120 | "||" return OR_OP; |
| 121 | "!" return NOT_OP; |
| 122 | |
| 123 | ":=" return ASSIGN; |
| 124 | ":" return COLON; |
| 125 | ";" return SEMICOLON; |
| 126 | "..." return DOTDOTDOT; |
| 127 | "." return DOT; |
| 128 | "=" return EQUAL; |
| 129 | "," return COMMA; |
| 130 | "^" return XOR_BIN; |
| 131 | "&" return AND_BIN; |
| 132 | "|" return OR_BIN; |
| 133 | "~" return NOT_BIN; |
| 134 | "$"{IDENTIFIER} printf_debug("<GLOBAL_IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); return GLOBAL_IDENTIFIER; |
| 135 | {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); return IDENTIFIER; |
| 136 | [ \t\n]+ ; /* ignore */ |
| 137 | . return ERROR; |
| 138 | %% |