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

Last change on this file since 1875 was 1875, checked in by sam, 7 years ago

easymesh: first shot at a simple, flat shaded torus.

File size: 4.1 KB
Line 
1%{
2//
3// Lol Engine
4//
5// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
6//            (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
7//            (c) 2009-2012 Benjamin 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://sam.zoy.org/projects/COPYING.WTFPL 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; }
69mx    { return token::T_MIRRORX; }
70my    { return token::T_MIRRORY; }
71mz    { return token::T_MIRRORZ; }
72
73ac    { return token::T_CYLINDER; }
74ab    { return token::T_BOX; }
75ascb  { return token::T_SMOOTHCHAMFBOX; }
76afcb  { return token::T_FLATCHAMFBOX; }
77acap  { return token::T_CAPSULE; }
78asph  { return token::T_SPHERE; }
79at    { return token::T_TORUS; }
80as    { return token::T_STAR; }
81aes   { return token::T_EXPANDEDSTAR; }
82ad    { return token::T_DISC; }
83at    { return token::T_TRIANGLE; }
84aq    { return token::T_QUAD; }
85acg   { return token::T_COG; }
86
87#[0-9a-fA-F]{3} {
88        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
89        yylval->u32val = 0x11000000u * (tmp >> 8)
90                       | 0x00110000u * ((tmp >> 4) & 0xf)
91                       | 0x00001100u * (tmp & 0xf)
92                       | 0x000000ffu;
93        return token::COLOR; }
94#[0-9a-fA-F]{4} {
95        uint32_t tmp = std::strtol(yytext + 1, NULL, 16);
96        yylval->u32val = 0x11000000u * (tmp >> 12)
97                       | 0x00110000u * ((tmp >> 8) & 0xf)
98                       | 0x00001100u * ((tmp >> 4) & 0xf)
99                       | 0x00000011u * (tmp & 0xf);
100        return token::COLOR; }
101#[0-9a-fA-F]{6} {
102        yylval->u32val = 0xffu
103                       | 0x100u * (uint32_t)std::strtol(yytext + 1, NULL, 16);
104        return token::COLOR; }
105#[0-9a-fA-F]{8} {
106        yylval->u32val = (uint32_t)std::strtol(yytext + 1, NULL, 16);
107        return token::COLOR; }
108[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? {
109        yylval->fval = std::atof(yytext); return token::NUMBER; }
110-     { return token_type('-'); }
111"["   { return token_type('['); }
112"]"   { return token_type(']'); }
113[ ,]  { /* ignore this */ }
114[\n]  { /* ignore this */ }
115.     { return token::T_ERROR; }
116
117%%
118
119lol::EasyMeshScanner::EasyMeshScanner(char const *command)
120    : EasyMeshFlexLexer(0, 0),
121      m_input(command)
122{
123}
124
125lol::EasyMeshScanner::~EasyMeshScanner()
126{
127}
128
129int lol::EasyMeshScanner::LexerInput(char* buf, int max_size)
130{
131    (void)max_size; /* unused for now */
132
133    buf[0] = m_input[0];
134    if (buf[0])
135        ++m_input;
136    return buf[0] ? 1 : 0;
137}
138
139#ifdef yylex
140#undef yylex
141#endif
142int EasyMeshFlexLexer::yylex()
143{
144    std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl;
145    return 0;
146}
147
148int EasyMeshFlexLexer::yywrap()
149{
150    return 1;
151}
152
Note: See TracBrowser for help on using the repository browser.