source: trunk/src/easymesh/easymesh-scanner.l @ 2232

Last change on this file since 2232 was 2232, checked in by lolbot, 7 years ago

fixed 27 files out of 2315:

  • removed 0 CR characters
  • removed 188 trailing whitespaces
  • replaced 537 tabs with spaces
File size: 4.3 KB
Line 
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>
19using std::exit;
20using std::malloc;
21using std::realloc;
22using std::free;
23
24#include "core.h"
25#include "easymesh/easymesh-compiler.h"
26
27typedef lol::EasyMeshParser::token token;
28typedef 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
51sc    { return token::T_COLOR; }
52scb   { return token::T_BGCOLOR; }
53
54ch    { return token::T_CHAMFER; }
55tx    { return token::T_TRANSLATEX; }
56ty    { return token::T_TRANSLATEY; }
57tz    { return token::T_TRANSLATEZ; }
58t     { return token::T_TRANSLATE; }
59rx    { return token::T_ROTATEX; }
60ry    { return token::T_ROTATEY; }
61rz    { return token::T_ROTATEZ; }
62tax   { return token::T_TAPERX; }
63tay   { return token::T_TAPERY; }
64taz   { return token::T_TAPERZ; }
65sx    { return token::T_SCALEX; }
66sy    { return token::T_SCALEY; }
67sz    { return token::T_SCALEZ; }
68s     { return token::T_SCALE; }
69tsw      { return token::T_TOGGLESCALEWINDING; }
70mx    { return token::T_MIRRORX; }
71my    { return token::T_MIRRORY; }
72mz    { return token::T_MIRRORZ; }
73
74csgu  { return token::T_CSGUNION; }
75csgs  { return token::T_CSGSUBSTRACT; }
76csga  { return token::T_CSGAND; }
77csgx  { return token::T_CSGXOR; }
78
79ab    { return token::T_BOX; }
80ac    { return token::T_CYLINDER; }
81acap  { return token::T_CAPSULE; }
82acg   { return token::T_COG; }
83ad    { return token::T_DISC; }
84aes   { return token::T_EXPANDEDSTAR; }
85afcb  { return token::T_FLATCHAMFBOX; }
86aq    { return token::T_QUAD; }
87as    { return token::T_STAR; }
88ascb  { return token::T_SMOOTHCHAMFBOX; }
89asph  { return token::T_SPHERE; }
90at    { return token::T_TRIANGLE; }
91ato   { return token::T_TORUS; }
92
93#[0-9a-fA-F]{3} {
94        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
95        yylval->u32val = 0x11000000u * (tmp >> 8)
96                       | 0x00110000u * ((tmp >> 4) & 0xf)
97                       | 0x00001100u * (tmp & 0xf)
98                       | 0x000000ffu;
99        return token::COLOR; }
100#[0-9a-fA-F]{4} {
101        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
102        yylval->u32val = 0x11000000u * (tmp >> 12)
103                       | 0x00110000u * ((tmp >> 8) & 0xf)
104                       | 0x00001100u * ((tmp >> 4) & 0xf)
105                       | 0x00000011u * (tmp & 0xf);
106        return token::COLOR; }
107#[0-9a-fA-F]{6} {
108        yylval->u32val = 0xffu
109                       | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
110        return token::COLOR; }
111#[0-9a-fA-F]{8} {
112        yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
113        return token::COLOR; }
114[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
115        yylval->fval = std::atof(yytext); return token::NUMBER; }
116-     { return token_type('-'); }
117"["   { return token_type('['); }
118"]"   { return token_type(']'); }
119[ ,]  { /* ignore this */ }
120[\n]  { /* ignore this */ }
121.     { return token::T_ERROR; }
122
123%%
124
125lol::EasyMeshScanner::EasyMeshScanner(char const *command)
126    : EasyMeshFlexLexer(0, 0),
127      m_input(command)
128{
129}
130
131lol::EasyMeshScanner::~EasyMeshScanner()
132{
133}
134
135int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
136{
137    (void)max_size; /* unused for now */
138
139    buf[0] = m_input[0];
140    if (buf[0])
141        ++m_input;
142    return buf[0] ? 1 : 0;
143}
144
145#ifdef yylex
146#undef yylex
147#endif
148int EasyMeshFlexLexer::yylex()
149{
150    std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
151    return 0;
152}
153
154int EasyMeshFlexLexer::yywrap()
155{
156    return 1;
157}
158
Note: See TracBrowser for help on using the repository browser.