1 | %{ |
---|
2 | // |
---|
3 | // Lol Engine |
---|
4 | // |
---|
5 | // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> |
---|
6 | // (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> |
---|
7 | // (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> |
---|
8 | // This program is free software; you can redistribute it and/or |
---|
9 | // modify it under the terms of the Do What The Fuck You Want To |
---|
10 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
11 | // http://www.wtfpl.net/ for more details. |
---|
12 | // |
---|
13 | |
---|
14 | #if defined HAVE_CONFIG_H |
---|
15 | # include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <cstdlib> |
---|
19 | using std::exit; |
---|
20 | using std::malloc; |
---|
21 | using std::realloc; |
---|
22 | using std::free; |
---|
23 | |
---|
24 | #include "core.h" |
---|
25 | #include "easymesh/easymesh-compiler.h" |
---|
26 | |
---|
27 | typedef lol::EasyMeshParser::token token; |
---|
28 | typedef lol::EasyMeshParser::token_type token_type; |
---|
29 | |
---|
30 | #ifndef YY_DECL |
---|
31 | # define YY_DECL lol::EasyMeshParser::token_type \ |
---|
32 | lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \ |
---|
33 | lol::EasyMeshParser::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="EasyMesh" |
---|
42 | %option batch yywrap nounput stack |
---|
43 | |
---|
44 | %% |
---|
45 | |
---|
46 | %{ |
---|
47 | /* reset location at the beginning of yylex() */ |
---|
48 | yylloc->step(); |
---|
49 | %} |
---|
50 | |
---|
51 | sc { return token::T_COLOR; } |
---|
52 | scb { return token::T_BGCOLOR; } |
---|
53 | |
---|
54 | ch { return token::T_CHAMFER; } |
---|
55 | tx { return token::T_TRANSLATEX; } |
---|
56 | ty { return token::T_TRANSLATEY; } |
---|
57 | tz { return token::T_TRANSLATEZ; } |
---|
58 | t { return token::T_TRANSLATE; } |
---|
59 | rx { return token::T_ROTATEX; } |
---|
60 | ry { return token::T_ROTATEY; } |
---|
61 | rz { return token::T_ROTATEZ; } |
---|
62 | tax { return token::T_TAPERX; } |
---|
63 | tay { return token::T_TAPERY; } |
---|
64 | taz { return token::T_TAPERZ; } |
---|
65 | twx { return token::T_TWISTX; } |
---|
66 | twy { return token::T_TWISTY; } |
---|
67 | twz { return token::T_TWISTZ; } |
---|
68 | shx { return token::T_SHEARX; } |
---|
69 | shy { return token::T_SHEARY; } |
---|
70 | shz { return token::T_SHEARZ; } |
---|
71 | stx { return token::T_STRETCHX; } |
---|
72 | sty { return token::T_STRETCHY; } |
---|
73 | stz { return token::T_STRETCHZ; } |
---|
74 | bdxy { return token::T_BENDXY; } |
---|
75 | bdxz { return token::T_BENDXZ; } |
---|
76 | bdyx { return token::T_BENDYX; } |
---|
77 | bdyz { return token::T_BENDYZ; } |
---|
78 | bdzx { return token::T_BENDZX; } |
---|
79 | bdzy { return token::T_BENDZY; } |
---|
80 | sx { return token::T_SCALEX; } |
---|
81 | sy { return token::T_SCALEY; } |
---|
82 | sz { return token::T_SCALEZ; } |
---|
83 | s { return token::T_SCALE; } |
---|
84 | tsw { return token::T_TOGGLESCALEWINDING; } |
---|
85 | mx { return token::T_MIRRORX; } |
---|
86 | my { return token::T_MIRRORY; } |
---|
87 | mz { return token::T_MIRRORZ; } |
---|
88 | rj { return token::T_RADIALJITTER; } |
---|
89 | |
---|
90 | csgu { return token::T_CSGUNION; } |
---|
91 | csgs { return token::T_CSGSUBSTRACT; } |
---|
92 | csgsl { return token::T_CSGSUBSTRACTLOSS; } |
---|
93 | csga { return token::T_CSGAND; } |
---|
94 | csgx { return token::T_CSGXOR; } |
---|
95 | |
---|
96 | ab { return token::T_BOX; } |
---|
97 | ac { return token::T_CYLINDER; } |
---|
98 | acap { return token::T_CAPSULE; } |
---|
99 | acg { return token::T_COG; } |
---|
100 | ad { return token::T_DISC; } |
---|
101 | aes { return token::T_EXPANDEDSTAR; } |
---|
102 | afcb { return token::T_FLATCHAMFBOX; } |
---|
103 | aq { return token::T_QUAD; } |
---|
104 | as { return token::T_STAR; } |
---|
105 | ascb { return token::T_SMOOTHCHAMFBOX; } |
---|
106 | asph { return token::T_SPHERE; } |
---|
107 | at { return token::T_TRIANGLE; } |
---|
108 | ato { return token::T_TORUS; } |
---|
109 | |
---|
110 | #[0-9a-fA-F]{3} { |
---|
111 | uint32_t tmp = std::strtol(yytext + 1, NULL, 16); |
---|
112 | yylval->u32val = 0x11000000u * (tmp >> 8) |
---|
113 | | 0x00110000u * ((tmp >> 4) & 0xf) |
---|
114 | | 0x00001100u * (tmp & 0xf) |
---|
115 | | 0x000000ffu; |
---|
116 | return token::COLOR; } |
---|
117 | #[0-9a-fA-F]{4} { |
---|
118 | uint32_t tmp = std::strtol(yytext + 1, NULL, 16); |
---|
119 | yylval->u32val = 0x11000000u * (tmp >> 12) |
---|
120 | | 0x00110000u * ((tmp >> 8) & 0xf) |
---|
121 | | 0x00001100u * ((tmp >> 4) & 0xf) |
---|
122 | | 0x00000011u * (tmp & 0xf); |
---|
123 | return token::COLOR; } |
---|
124 | #[0-9a-fA-F]{6} { |
---|
125 | yylval->u32val = 0xffu |
---|
126 | | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16); |
---|
127 | return token::COLOR; } |
---|
128 | #[0-9a-fA-F]{8} { |
---|
129 | yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16); |
---|
130 | return token::COLOR; } |
---|
131 | [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? { |
---|
132 | yylval->fval = std::atof(yytext); return token::NUMBER; } |
---|
133 | - { return token_type('-'); } |
---|
134 | "[" { return token_type('['); } |
---|
135 | "]" { return token_type(']'); } |
---|
136 | [ ,] { /* ignore this */ } |
---|
137 | [\n] { /* ignore this */ } |
---|
138 | . { return token::T_ERROR; } |
---|
139 | |
---|
140 | %% |
---|
141 | |
---|
142 | lol::EasyMeshScanner::EasyMeshScanner(char const *command) |
---|
143 | : EasyMeshFlexLexer(0, 0), |
---|
144 | m_input(command) |
---|
145 | { |
---|
146 | } |
---|
147 | |
---|
148 | lol::EasyMeshScanner::~EasyMeshScanner() |
---|
149 | { |
---|
150 | } |
---|
151 | |
---|
152 | int lol::EasyMeshScanner::LexerInput(char* buf, int max_size) |
---|
153 | { |
---|
154 | (void)max_size; /* unused for now */ |
---|
155 | |
---|
156 | buf[0] = m_input[0]; |
---|
157 | if (buf[0]) |
---|
158 | ++m_input; |
---|
159 | return buf[0] ? 1 : 0; |
---|
160 | } |
---|
161 | |
---|
162 | #ifdef yylex |
---|
163 | #undef yylex |
---|
164 | #endif |
---|
165 | int EasyMeshFlexLexer::yylex() |
---|
166 | { |
---|
167 | std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl; |
---|
168 | return 0; |
---|
169 | } |
---|
170 | |
---|
171 | int EasyMeshFlexLexer::yywrap() |
---|
172 | { |
---|
173 | return 1; |
---|
174 | } |
---|
175 | |
---|