Commit | Line | Data |
---|---|---|
8b9d5b5e | 1 | %{ |
c59a87f5 MD |
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 | ||
8b9d5b5e | 20 | #include <stdio.h> |
34d3acc4 | 21 | #include "ctf-scanner.h" |
8b9d5b5e MD |
22 | #include "ctf-parser.h" |
23 | #include "ctf-ast.h" | |
24 | ||
609bd1bf MD |
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)); | |
34d3acc4 MD |
31 | |
32 | #define printf_dbg(fmt, args...) fprintf(stderr, "%s: " fmt, __func__, args) | |
33 | #define printf_dbg_noarg(fmt) fprintf(stderr, "%s: " fmt, __func__) | |
34 | ||
8b9d5b5e MD |
35 | %} |
36 | ||
37 | %x comment_ml comment_sl string_lit char_const | |
34d3acc4 MD |
38 | %option reentrant yylineno noyywrap bison-bridge |
39 | %option extra-type="struct ctf_scanner *" | |
40 | /* bison-locations */ | |
8b9d5b5e MD |
41 | INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) |
42 | DIGIT [0-9] | |
43 | NONDIGIT [a-zA-Z_] | |
44 | HEXDIGIT [0-9A-Fa-f] | |
45 | OCTALDIGIT [0-7] | |
46 | UCHARLOWERCASE \\u{HEXDIGIT}{4} | |
47 | UCHARUPPERCASE \\U{HEXDIGIT}{8} | |
48 | ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE} | |
49 | IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})* | |
50 | ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+) | |
51 | %% | |
52 | ||
53 | /* | |
54 | * Using start conditions to deal with comments | |
55 | * and strings. | |
56 | */ | |
57 | ||
58 | "/*" BEGIN(comment_ml); | |
59 | <comment_ml>[^*\n]* /* eat anything that's not a '*' */ | |
60 | <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ | |
61 | <comment_ml>\n ++yylineno; | |
62 | <comment_ml>"*"+"/" BEGIN(INITIAL); | |
63 | ||
64 | "//" BEGIN(comment_sl); | |
65 | <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL); | |
66 | ||
67 | L\' BEGIN(char_const); return CHARACTER_CONSTANT_START; | |
68 | \' BEGIN(char_const); return CHARACTER_CONSTANT_START; | |
69 | <char_const>\' BEGIN(INITIAL); return SQUOTE; | |
70 | ||
71 | L\" BEGIN(string_lit); return STRING_LITERAL_START; | |
72 | \" BEGIN(string_lit); return STRING_LITERAL_START; | |
73 | <string_lit>\" BEGIN(INITIAL); return DQUOTE; | |
74 | ||
75 | <char_const,string_lit>ESCSEQ return ESCSEQ; | |
76 | <char_const,string_lit>\n ; /* ignore */ | |
77 | <char_const,string_lit>. return CHAR_STRING_TOKEN; | |
78 | ||
79 | "[" return LSBRAC; | |
80 | "]" return RSBRAC; | |
81 | "(" return LPAREN; | |
82 | ")" return RPAREN; | |
83 | "{" return LBRAC; | |
84 | "}" return RBRAC; | |
85 | "->" return RARROW; | |
86 | "*" return STAR; | |
87 | "+" return PLUS; | |
88 | "-" return MINUS; | |
89 | "<" return LT; | |
90 | ">" return GT; | |
91 | := return TYPEASSIGN; | |
92 | : return COLON; | |
93 | ; return SEMICOLON; | |
94 | "..." return DOTDOTDOT; | |
95 | "." return DOT; | |
96 | = return EQUAL; | |
97 | "," return COMMA; | |
98 | const return CONST; | |
99 | char return CHAR; | |
100 | double return DOUBLE; | |
101 | enum return ENUM; | |
102 | event return EVENT; | |
103 | floating_point return FLOATING_POINT; | |
104 | float return FLOAT; | |
105 | integer return INTEGER; | |
106 | int return INT; | |
107 | long return LONG; | |
108 | short return SHORT; | |
109 | signed return SIGNED; | |
110 | stream return STREAM; | |
111 | string return STRING; | |
112 | struct return STRUCT; | |
113 | trace return TRACE; | |
114 | typealias return TYPEALIAS; | |
115 | typedef return TYPEDEF; | |
116 | unsigned return UNSIGNED; | |
117 | variant return VARIANT; | |
118 | void return VOID; | |
119 | _Bool return _BOOL; | |
120 | _Complex return _COMPLEX; | |
121 | _Imaginary return _IMAGINARY; | |
122 | [1-9]{DIGIT}*{INTEGER_SUFFIX}? return DECIMAL_CONSTANT; | |
123 | 0{OCTALDIGIT}*{INTEGER_SUFFIX}? return OCTAL_CONSTANT; | |
124 | 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? return HEXADECIMAL_CONSTANT; | |
34d3acc4 | 125 | {IDENTIFIER} printf_dbg("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; |
8b9d5b5e MD |
126 | [ \t\n]+ ; /* ignore */ |
127 | . return ERROR; | |
128 | %% |