1 %{
2 #include "stdio.h"  // for fileno() prototype
3 #include "string.h" // for strdup() prototype
4 #include "ex0_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 [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]+ {
17 	// Leading minus sign is handled via the unary-minus operator, not here.
18 	// 123
19 	// 123. 123.4
20 	// .234
21 	// 1e2
22 	// 1e-2
23 	// 1.2e3 1.e3
24 	// 1.2e-3 1.e-3
25 	// .2e3
26 	// .2e-3 1.e-3
27 	*yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_NUMERIC_LITERAL);
28 	return MD_TOKEN_NUMBER;
29 }
30 
31 "+" {
32 	*yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_OPERATOR);
33 	return MD_TOKEN_PLUS;
34 }
35 "-" {
36 	*yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_OPERATOR);
37 	return MD_TOKEN_MINUS;
38 }
39 "*" {
40 	*yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_OPERATOR);
41 	return MD_TOKEN_TIMES;
42 }
43 "/" {
44 	*yyextra = ex_ast_node_alloc(yytext, MD_AST_NODE_TYPE_OPERATOR);
45 	return MD_TOKEN_DIVIDE;
46 }
47 
48 [ \t\r\n] { }
49 
50 . {
51 	return -1;
52 }
53 %%
54