1 %{ 2 #include "stdio.h" // for fileno() prototype 3 #include "string.h" // for strdup() prototype 4 #include "ex2_parse.h" 5 #include "./ex_ast.h" 6 // http://flex.sourceforge.net/manual/Extra-Data.html 7 8 %} 9 10 %option reentrant 11 %option noyywrap 12 %option extra-type="struct _ex_ast_node_t **" 13 14 %% 15 16 "=" { 17 *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_SREC_ASSIGNMENT); 18 return MD_TOKEN_ASSIGN; 19 } 20 21 \$[a-zA-Z_0-9]+ { 22 // Note: the parser depends on the dollar sign being here. If this is changed, 23 // that needs to be changed as well. 24 *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_FIELD_NAME); 25 return MD_TOKEN_FIELD_NAME; 26 } 27 28 [0-9]+|[0-9]+\.[0-9]*|[0-9]*\.[0-9]+|[0-9]+[eE][0-9]+|[0-9]+[eE]-[0-9]+|[0-9]+\.[0-9]*[eE][0-9]+|[0-9]+\.[0-9]*[eE]-[0-9]+|[0-9]*\.[0-9]+[eE][0-9]+|[0-9]*\.[0-9]+[eE]-[0-9]+ { 29 // Leading minus sign is handled via the unary-minus operator, not here. 30 // 123 31 // 123. 123.4 32 // .234 33 // 1e2 34 // 1e-2 35 // 1.2e3 1.e3 36 // 1.2e-3 1.e-3 37 // .2e3 38 // .2e-3 1.e-3 39 *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_NUMERIC_LITERAL); 40 return MD_TOKEN_NUMBER; 41 } 42 0x[0-9a-fA-F]+ { 43 *yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_NUMERIC_LITERAL); 44 return MD_TOKEN_NUMBER; 45 } 46 47 [ \t\r\n] { } 48 49 . { 50 return -1; 51 } 52 %% 53