1 | %{ |
---|
2 | // |
---|
3 | // Orbital |
---|
4 | // |
---|
5 | // Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> |
---|
6 | // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> |
---|
7 | // (c) 2012 Sam Hocevar <sam@hocevar.net> |
---|
8 | // |
---|
9 | |
---|
10 | #if defined HAVE_CONFIG_H |
---|
11 | # include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <cstdlib> |
---|
15 | using std::exit; |
---|
16 | using std::malloc; |
---|
17 | using std::realloc; |
---|
18 | using std::free; |
---|
19 | |
---|
20 | #include "core.h" |
---|
21 | #include "loldebug.h" |
---|
22 | |
---|
23 | using namespace lol; |
---|
24 | |
---|
25 | #include "../gun-compiler.h" |
---|
26 | |
---|
27 | typedef orbital::GunParser::token token; |
---|
28 | typedef orbital::GunParser::token_type token_type; |
---|
29 | |
---|
30 | #ifndef YY_DECL |
---|
31 | # define YY_DECL orbital::GunParser::token_type \ |
---|
32 | orbital::GunScanner::lex(orbital::GunParser::semantic_type* yylval, \ |
---|
33 | orbital::GunParser::location_type* yylloc) |
---|
34 | #endif |
---|
35 | |
---|
36 | #define yyterminate() return token::T_END |
---|
37 | #define YY_NO_UNISTD_H |
---|
38 | #define YY_USER_ACTION yylloc->columns(yyleng); |
---|
39 | %} |
---|
40 | |
---|
41 | %option c++ prefix="Gun" |
---|
42 | %option batch yywrap nounput stack |
---|
43 | |
---|
44 | %% |
---|
45 | |
---|
46 | %{ |
---|
47 | /* reset location at the beginning of yylex() */ |
---|
48 | yylloc->step(); |
---|
49 | %} |
---|
50 | |
---|
51 | ai { return token::T_AI; } |
---|
52 | pai { return token::T_PAI; } |
---|
53 | ca { return token::T_CA; } |
---|
54 | sa { return token::T_SA; } |
---|
55 | tim { return token::T_TIM; } |
---|
56 | so { return token::T_SO; } |
---|
57 | rd { return token::T_RD; } |
---|
58 | spd { return token::T_SPD; } |
---|
59 | moda { return token::T_MODA; } |
---|
60 | modb { return token::T_MODB; } |
---|
61 | ffb { return token::T_FFB; } |
---|
62 | ffp { return token::T_FFP; } |
---|
63 | fb { return token::T_FB; } |
---|
64 | fp { return token::T_FP; } |
---|
65 | sk { return token::T_SK; } |
---|
66 | loop { return token::T_LOOP; } |
---|
67 | |
---|
68 | [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? { |
---|
69 | yylval->fval = std::atof(yytext); return token::NUMBER; } |
---|
70 | - { return token_type('-'); } |
---|
71 | , { return token_type(','); } |
---|
72 | [.\n] { /* ignore everything else */ } |
---|
73 | |
---|
74 | %% |
---|
75 | |
---|
76 | orbital::GunScanner::GunScanner(char const *command) |
---|
77 | : GunFlexLexer(0, 0), |
---|
78 | m_input(command) |
---|
79 | { |
---|
80 | } |
---|
81 | |
---|
82 | orbital::GunScanner::~GunScanner() |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | int orbital::GunScanner::LexerInput(char* buf, int max_size) |
---|
87 | { |
---|
88 | buf[0] = m_input[0]; |
---|
89 | if (buf[0]) |
---|
90 | ++m_input; |
---|
91 | return buf[0] ? 1 : 0; |
---|
92 | } |
---|
93 | |
---|
94 | #ifdef yylex |
---|
95 | #undef yylex |
---|
96 | #endif |
---|
97 | int GunFlexLexer::yylex() |
---|
98 | { |
---|
99 | std::cerr << "in GunFlexLexer::yylex() !" << std::endl; |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | int GunFlexLexer::yywrap() |
---|
104 | { |
---|
105 | return 1; |
---|
106 | } |
---|
107 | |
---|