| 1 | %{ |
| 2 | /* |
| 3 | * ctf-lexer.l |
| 4 | * |
| 5 | * Common Trace Formal Lexer |
| 6 | * |
| 7 | * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | * of this software and associated documentation files (the "Software"), to deal |
| 11 | * in the Software without restriction, including without limitation the rights |
| 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | * copies of the Software, and to permit persons to whom the Software is |
| 14 | * furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include "ctf-scanner.h" |
| 22 | #include "ctf-parser.h" |
| 23 | #include "ctf-ast.h" |
| 24 | |
| 25 | extern |
| 26 | void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src); |
| 27 | |
| 28 | static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner) |
| 29 | __attribute__((unused)); |
| 30 | static int input (yyscan_t yyscanner) __attribute__((unused)); |
| 31 | |
| 32 | #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, ##args) |
| 33 | |
| 34 | %} |
| 35 | |
| 36 | %x comment_ml comment_sl string_lit char_const |
| 37 | %option reentrant yylineno noyywrap bison-bridge |
| 38 | %option extra-type="struct ctf_scanner *" |
| 39 | /* bison-locations */ |
| 40 | INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) |
| 41 | DIGIT [0-9] |
| 42 | NONDIGIT [a-zA-Z_] |
| 43 | HEXDIGIT [0-9A-Fa-f] |
| 44 | OCTALDIGIT [0-7] |
| 45 | UCHARLOWERCASE \\u{HEXDIGIT}{4} |
| 46 | UCHARUPPERCASE \\U{HEXDIGIT}{8} |
| 47 | ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE} |
| 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}+) |
| 50 | %% |
| 51 | |
| 52 | /* |
| 53 | * Using start conditions to deal with comments |
| 54 | * and strings. |
| 55 | */ |
| 56 | |
| 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); |
| 62 | |
| 63 | "//" BEGIN(comment_sl); |
| 64 | <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL); |
| 65 | |
| 66 | L\' BEGIN(char_const); return CHARACTER_CONSTANT_START; |
| 67 | \' BEGIN(char_const); return CHARACTER_CONSTANT_START; |
| 68 | <char_const>\' BEGIN(INITIAL); return SQUOTE; |
| 69 | |
| 70 | L\" BEGIN(string_lit); return STRING_LITERAL_START; |
| 71 | \" BEGIN(string_lit); return STRING_LITERAL_START; |
| 72 | <string_lit>\" BEGIN(INITIAL); return DQUOTE; |
| 73 | |
| 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; |
| 77 | |
| 78 | "[" return LSBRAC; |
| 79 | "]" return RSBRAC; |
| 80 | "(" return LPAREN; |
| 81 | ")" return RPAREN; |
| 82 | "{" return LBRAC; |
| 83 | "}" return RBRAC; |
| 84 | "->" return RARROW; |
| 85 | "*" return STAR; |
| 86 | "+" return PLUS; |
| 87 | "-" return MINUS; |
| 88 | "<" return LT; |
| 89 | ">" return GT; |
| 90 | := return TYPEASSIGN; |
| 91 | : return COLON; |
| 92 | ; return SEMICOLON; |
| 93 | "..." return DOTDOTDOT; |
| 94 | "." return DOT; |
| 95 | = return EQUAL; |
| 96 | "," return COMMA; |
| 97 | const setstring(yyextra, yylval, yytext); return CONST; |
| 98 | char setstring(yyextra, yylval, yytext); return CHAR; |
| 99 | double setstring(yyextra, yylval, yytext); return DOUBLE; |
| 100 | enum setstring(yyextra, yylval, yytext); return ENUM; |
| 101 | event setstring(yyextra, yylval, yytext); return EVENT; |
| 102 | floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT; |
| 103 | float setstring(yyextra, yylval, yytext); return FLOAT; |
| 104 | integer setstring(yyextra, yylval, yytext); return INTEGER; |
| 105 | int setstring(yyextra, yylval, yytext); return INT; |
| 106 | long setstring(yyextra, yylval, yytext); return LONG; |
| 107 | short setstring(yyextra, yylval, yytext); return SHORT; |
| 108 | signed setstring(yyextra, yylval, yytext); return SIGNED; |
| 109 | stream setstring(yyextra, yylval, yytext); return STREAM; |
| 110 | string setstring(yyextra, yylval, yytext); return STRING; |
| 111 | struct setstring(yyextra, yylval, yytext); return STRUCT; |
| 112 | trace setstring(yyextra, yylval, yytext); return TRACE; |
| 113 | typealias setstring(yyextra, yylval, yytext); return TYPEALIAS; |
| 114 | typedef setstring(yyextra, yylval, yytext); return TYPEDEF; |
| 115 | unsigned setstring(yyextra, yylval, yytext); return UNSIGNED; |
| 116 | variant setstring(yyextra, yylval, yytext); return VARIANT; |
| 117 | void setstring(yyextra, yylval, yytext); return VOID; |
| 118 | _Bool setstring(yyextra, yylval, yytext); return _BOOL; |
| 119 | _Complex setstring(yyextra, yylval, yytext); return _COMPLEX; |
| 120 | _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY; |
| 121 | [1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT; |
| 122 | 0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT; |
| 123 | 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT; |
| 124 | {IDENTIFIER} printf_dbg("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; |
| 125 | [ \t\n]+ ; /* ignore */ |
| 126 | . return ERROR; |
| 127 | %% |