diff --git a/Makefile.am b/Makefile.am index ccafb7b9..f5cf8bbd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,7 @@ lolremez-$(LOLREMEZ_VERSION).tar.gz: $(top_srcdir)/test/math/remez.vcxproj.filters \ lolremez-$(LOLREMEZ_VERSION)/ cp $(top_srcdir)/src/lol/math/real.h \ - $(top_srcdir)/src/lol/math/matrix.h \ + $(top_srcdir)/src/lol/math/vector.h \ $(top_srcdir)/src/lol/math/remez.h \ lolremez-$(LOLREMEZ_VERSION)/lol/math/ printf 'remez: real.cpp remez.cpp\n' > lolremez-$(LOLREMEZ_VERSION)/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 9ef0d738..66215073 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,9 +15,17 @@ liblol_a_SOURCES = \ lol/unit.h lol/debug.h \ lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ \ + generated/location.hh generated/position.hh generated/stack.hh \ + \ application/application.cpp application/application.h \ eglapp.cpp eglapp.h \ \ + easymesh/easymesh.cpp easymesh/easymesh.h \ + easymesh/shiny.lolfx \ + easymesh/easymesh-compiler.cpp easymesh/easymesh-compiler.h \ + generated/easymesh-parser.cpp generated/easymesh-parser.h \ + generated/easymesh-scanner.cpp \ + \ $(ps3_sources) \ $(xbox_sources) \ $(nacl_sources) \ @@ -59,6 +67,18 @@ SUFFIXES = .lolfx $(SED) 's/\([^\r]*\).*/"\1\\n"/'; \ echo ";") | $(CXXCOMPILE) -xc++ -c - -o $@ +if TRUE +generated: .FORCE + $(MKDIR_P) generated + rm -f generated/[a-zA-Z]* + flex -o generated/easymesh-scanner.cpp easymesh/easymesh-scanner.l + bison -o generated/easymesh-parser.cpp --defines=generated/easymesh-parser.h \ + -d -b generated/easymesh easymesh/easymesh-parser.y +.FORCE: +endif + +EXTRA_DIST = easymesh/easymesh-scanner.l easymesh/easymesh-parser.y + sdl_sources = \ image/codec/sdl-image.cpp \ platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ diff --git a/src/core.h b/src/core.h index 389de12d..40f2b261 100644 --- a/src/core.h +++ b/src/core.h @@ -112,6 +112,7 @@ static inline int isnan(float f) #include "gpu/framebuffer.h" #include "image/image.h" #include "application/application.h" +#include "easymesh/easymesh.h" // Managers #include "ticker.h" diff --git a/src/easymesh/easymesh-compiler.cpp b/src/easymesh/easymesh-compiler.cpp new file mode 100644 index 00000000..10735dd3 --- /dev/null +++ b/src/easymesh/easymesh-compiler.cpp @@ -0,0 +1,52 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" +#include "easymesh/easymesh-compiler.h" + +namespace lol +{ + +EasyMeshCompiler::EasyMeshCompiler(EasyMesh &mesh) + : m_mesh(mesh) +{ +} + +bool EasyMeshCompiler::ParseString(char const *command) +{ + EasyMeshScanner scanner(command); + m_lexer = &scanner; + EasyMeshParser parser(*this); + if (parser.parse() != 0) + return false; + return true; +} + +void EasyMeshCompiler::Error(const class location& l, const std::string& m) +{ + Log::Error("Syntax error line %d column %d: %s", + l.begin.line, l.begin.column, m.c_str()); +} + +void EasyMeshCompiler::Error(const std::string& m) +{ + Log::Error("Syntax error: %s", m.c_str()); +} + +} /* namespace lol */ + diff --git a/src/easymesh/easymesh-compiler.h b/src/easymesh/easymesh-compiler.h new file mode 100644 index 00000000..8cfa4808 --- /dev/null +++ b/src/easymesh/easymesh-compiler.h @@ -0,0 +1,61 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#ifndef __EASYMESH_COMPILER_H__ +#define __EASYMESH_COMPILER_H__ + +#include + +#ifndef __FLEX_LEXER_H +# define yyFlexLexer EasyMeshFlexLexer +# include "FlexLexer.h" +# undef yyFlexLexer +#endif + +#include "generated/easymesh-parser.h" + +class EasyMesh; + +namespace lol +{ + +class EasyMeshScanner : public EasyMeshFlexLexer +{ +public: + EasyMeshScanner(char const *command); + virtual ~EasyMeshScanner(); + virtual int LexerInput(char* buf, int max_size); + virtual EasyMeshParser::token_type lex(EasyMeshParser::semantic_type* yylval, + EasyMeshParser::location_type* yylloc); + +private: + char const *m_input; +}; + +class EasyMeshCompiler +{ +public: + EasyMeshCompiler(class EasyMesh &mesh); + + bool ParseString(char const *command); + + void Error(const class location& l, const std::string& m); + void Error(const std::string& m); + + class EasyMeshScanner* m_lexer; + class EasyMesh &m_mesh; +}; + +} /* namespace lol */ + +#endif /* __EASYMESH_COMPILER_H__ */ + diff --git a/src/easymesh/easymesh-parser.y b/src/easymesh/easymesh-parser.y new file mode 100644 index 00000000..1f182757 --- /dev/null +++ b/src/easymesh/easymesh-parser.y @@ -0,0 +1,182 @@ +%{ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "easymesh/easymesh.h" + +#include + +%} + +%require "2.3" +%debug +%defines +%skeleton "lalr1.cc" +%name-prefix="lol" +%define parser_class_name "EasyMeshParser" +%locations +%parse-param { class EasyMeshCompiler& mc } +%error-verbose + +%union +{ + float fval; + /* Can't use uin32_t here for some reason */ + unsigned u32val; + struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args; +} + +%start mesh_description + +%token T_COLOR T_BGCOLOR + +%token T_TRANSLATEX T_ROTATEX T_TAPERX T_SCALEX T_MIRRORX +%token T_TRANSLATEY T_ROTATEY T_TAPERY T_SCALEY T_MIRRORY +%token T_TRANSLATEZ T_ROTATEZ T_TAPERZ T_SCALEZ T_MIRRORZ +%token T_TRANSLATE T_SCALE +%token T_CHAMFER + +%token T_CYLINDER T_BOX T_SMOOTHCHAMFBOX T_FLATCHAMFBOX T_SPHERE T_STAR +%token T_EXPANDEDSTAR T_DISC T_TRIANGLE T_QUAD T_COG + +%token T_END 0 +%token T_ERROR + +%token NUMBER +%token COLOR + +%type number +%type args1 args2 args3 args4 args5 args6 args7 args8 + +%{ +#include "easymesh/easymesh-compiler.h" + +#undef yylex +#define yylex mc.m_lexer->lex +%} + +%% + +mesh_description: + mesh_expression_list T_END + ; + +mesh_expression_list: + mesh_expression + | mesh_expression mesh_expression_list + ; + +mesh_expression: + mesh_command_list + | mesh_open mesh_expression_list mesh_close + ; + +mesh_open: + '[' { mc.m_mesh.OpenBrace(); } + ; + +mesh_close: + ']' { mc.m_mesh.CloseBrace(); } + ; + +mesh_command_list: + mesh_command + | mesh_command_list mesh_command + ; + +mesh_command: + color_command + | transform_command + | primitive_command + ; + +color_command: + T_COLOR args4 { mc.m_mesh.SetCurColor(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } + | T_COLOR COLOR { uint32_t x = $2; + vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + mc.m_mesh.SetCurColor(vec4(v) * (1. / 255)); } + | T_BGCOLOR args4 { mc.m_mesh.SetCurColor2(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } + | T_BGCOLOR COLOR { uint32_t x = $2; + vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + mc.m_mesh.SetCurColor2(vec4(v) * (1. / 255)); } + ; + +transform_command: + T_CHAMFER args1 { mc.m_mesh.Chamfer($2.f0); } + | T_TRANSLATEX args1 { mc.m_mesh.Translate(vec3($2.f0, 0, 0)); } + | T_TRANSLATEY args1 { mc.m_mesh.Translate(vec3(0, $2.f0, 0)); } + | T_TRANSLATEZ args1 { mc.m_mesh.Translate(vec3(0, 0, $2.f0)); } + | T_TRANSLATE args3 { mc.m_mesh.Translate(vec3($2.f0, $2.f1, $2.f2)); } + | T_ROTATEX args1 { mc.m_mesh.RotateX($2.f0); } + | T_ROTATEY args1 { mc.m_mesh.RotateY($2.f0); } + | T_ROTATEZ args1 { mc.m_mesh.RotateZ($2.f0); } + | T_TAPERX args3 { mc.m_mesh.TaperX($2.f0, $2.f1, $2.f2); } + | T_TAPERY args3 { mc.m_mesh.TaperY($2.f0, $2.f1, $2.f2); } + | T_TAPERZ args3 { mc.m_mesh.TaperZ($2.f0, $2.f1, $2.f2); } + | T_SCALEX args1 { mc.m_mesh.Scale(vec3($2.f0, 0, 0)); } + | T_SCALEY args1 { mc.m_mesh.Scale(vec3(0, $2.f0, 0)); } + | T_SCALEZ args1 { mc.m_mesh.Scale(vec3(0, 0, $2.f0)); } + | T_SCALE args3 { mc.m_mesh.Scale(vec3($2.f0, $2.f1, $2.f2)); } + | T_MIRRORX { mc.m_mesh.MirrorX(); } + | T_MIRRORY { mc.m_mesh.MirrorY(); } + | T_MIRRORZ { mc.m_mesh.MirrorZ(); } + ; + +primitive_command: + T_CYLINDER args6 { mc.m_mesh.AppendCylinder((int)$2.f0, $2.f1, + $2.f2, $2.f3, + (int)$2.f4, (int)$2.f5); } + | T_BOX args3 { mc.m_mesh.AppendBox(vec3($2.f0, $2.f1, $2.f2)); } + | T_SMOOTHCHAMFBOX args4 { mc.m_mesh.AppendSmoothChamfBox(vec3($2.f0, $2.f1, + $2.f2), $2.f3); } + | T_FLATCHAMFBOX args4 { mc.m_mesh.AppendFlatChamfBox(vec3($2.f0, $2.f1, + $2.f2), $2.f3); } + | T_SPHERE args4 { mc.m_mesh.AppendSphere($2.f0, + vec3($2.f1, $2.f2, $2.f3)); } + | T_STAR args5 { mc.m_mesh.AppendStar((int)$2.f0, $2.f1, $2.f2, + (int)$2.f3, (int)$2.f4); } + | T_EXPANDEDSTAR args4 { mc.m_mesh.AppendExpandedStar((int)$2.f0, $2.f1, + $2.f2, $2.f3); } + | T_DISC args3 { mc.m_mesh.AppendDisc((int)$2.f0, $2.f1, (int)$2.f2); } + | T_TRIANGLE args2 { mc.m_mesh.AppendSimpleTriangle($2.f0, (int)$2.f1); } + | T_QUAD args2 { mc.m_mesh.AppendSimpleQuad($2.f0, (int)$2.f1); } + | T_COG args8 { mc.m_mesh.AppendCog((int)$2.f0, $2.f1, $2.f2, $2.f3, + $2.f4, $2.f5, $2.f6, (int)$2.f7); } + ; + +args1: number { $$.f0 = $1; } ; +args2: args1 number { $$ = $1; $$.f1 = $2; } ; +args3: args2 number { $$ = $1; $$.f2 = $2; } ; +args4: args3 number { $$ = $1; $$.f3 = $2; } ; +args5: args4 number { $$ = $1; $$.f4 = $2; } ; +args6: args5 number { $$ = $1; $$.f5 = $2; } ; +args7: args6 number { $$ = $1; $$.f6 = $2; } ; +args8: args7 number { $$ = $1; $$.f7 = $2; } ; + +number: + NUMBER { $$ = $1; } + | '-' number { $$ = -$2; } + ; + +%% + +void lol::EasyMeshParser::error(const EasyMeshParser::location_type& l, + const std::string& m) +{ + mc.Error(l, m); +} + diff --git a/src/easymesh/easymesh-scanner.l b/src/easymesh/easymesh-scanner.l new file mode 100644 index 00000000..cd4573e8 --- /dev/null +++ b/src/easymesh/easymesh-scanner.l @@ -0,0 +1,142 @@ +%{ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "easymesh/easymesh-compiler.h" + +typedef lol::EasyMeshParser::token token; +typedef lol::EasyMeshParser::token_type token_type; + +#ifndef YY_DECL +# define YY_DECL lol::EasyMeshParser::token_type \ + lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \ + lol::EasyMeshParser::location_type* yylloc) +#endif + +#define yyterminate() return token::T_END +#define YY_NO_UNISTD_H +#define YY_USER_ACTION yylloc->columns(yyleng); +%} + +%option c++ prefix="EasyMesh" +%option batch yywrap nounput stack + +%% + +%{ + /* reset location at the beginning of yylex() */ + yylloc->step(); +%} + +sc { return token::T_COLOR; } +scb { return token::T_BGCOLOR; } + +ch { return token::T_CHAMFER; } +tx { return token::T_TRANSLATEX; } +ty { return token::T_TRANSLATEY; } +tz { return token::T_TRANSLATEZ; } +t { return token::T_TRANSLATE; } +rx { return token::T_ROTATEX; } +ry { return token::T_ROTATEY; } +rz { return token::T_ROTATEZ; } +tax { return token::T_TAPERX; } +tay { return token::T_TAPERY; } +taz { return token::T_TAPERZ; } +sx { return token::T_SCALEX; } +sy { return token::T_SCALEY; } +sz { return token::T_SCALEZ; } +s { return token::T_SCALE; } +mx { return token::T_MIRRORX; } +my { return token::T_MIRRORY; } +mz { return token::T_MIRRORZ; } + +ac { return token::T_CYLINDER; } +ab { return token::T_BOX; } +ascb { return token::T_SMOOTHCHAMFBOX; } +afcb { return token::T_FLATCHAMFBOX; } +asph { return token::T_SPHERE; } +as { return token::T_STAR; } +aes { return token::T_EXPANDEDSTAR; } +ad { return token::T_DISC; } +at { return token::T_TRIANGLE; } +aq { return token::T_QUAD; } +acg { return token::T_COG; } + +#[0-9a-f]{3} { + uint32_t tmp = strtol(yytext + 1, NULL, 16); + yylval->u32val = 0x11000000u * (tmp >> 8) + | 0x00110000u * ((tmp >> 4) & 0xf) + | 0x00001100u * (tmp & 0xf) + | 0x000000ffu; + return token::COLOR; } +#[0-9a-f]{4} { + uint32_t tmp = strtol(yytext + 1, NULL, 16); + yylval->u32val = 0x11000000u * (tmp >> 12) + | 0x00110000u * ((tmp >> 8) & 0xf) + | 0x00001100u * ((tmp >> 4) & 0xf) + | 0x00000011u * (tmp & 0xf); + return token::COLOR; } +#[0-9a-f]{6} { + yylval->u32val = 0xffu + | 0x100u * (uint32_t)strtol(yytext + 1, NULL, 16); + return token::COLOR; } +#[0-9a-f]{8} { + yylval->u32val = (uint32_t)strtol(yytext + 1, NULL, 16); + return token::COLOR; } +[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? { + yylval->fval = atof(yytext); return token::NUMBER; } +- { return token_type('-'); } +"[" { return token_type('['); } +"]" { return token_type(']'); } +[ ,] { /* ignore this */ } +[\n] { /* ignore this */ } +. { return token::T_ERROR; } + +%% + +lol::EasyMeshScanner::EasyMeshScanner(char const *command) + : EasyMeshFlexLexer(0, 0), + m_input(command) +{ +} + +lol::EasyMeshScanner::~EasyMeshScanner() +{ +} + +int lol::EasyMeshScanner::LexerInput(char* buf, int max_size) +{ + buf[0] = m_input[0]; + if (buf[0]) + ++m_input; + return buf[0] ? 1 : 0; +} + +#ifdef yylex +#undef yylex +#endif +int EasyMeshFlexLexer::yylex() +{ + std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl; + return 0; +} + +int EasyMeshFlexLexer::yywrap() +{ + return 1; +} + diff --git a/src/easymesh/easymesh.cpp b/src/easymesh/easymesh.cpp new file mode 100644 index 00000000..572effaa --- /dev/null +++ b/src/easymesh/easymesh.cpp @@ -0,0 +1,721 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The EasyMesh class +// ------------------ +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "easymesh/easymesh-compiler.h" + +extern char const *lolfx_shiny; + +namespace lol +{ + +EasyMesh::EasyMesh() + : m_color(0), m_color2(0) +{ + m_cursors.Push(0, 0); +} + +bool EasyMesh::Compile(char const *command) +{ + EasyMeshCompiler mc(*this); + return mc.ParseString(command); +} + +void EasyMesh::OpenBrace() +{ + m_cursors.Push(m_vert.Count(), m_indices.Count()); +} + +void EasyMesh::CloseBrace() +{ + m_cursors.Pop(); +} + +void EasyMesh::MeshConvert() +{ + m_gpu.shader = Shader::Create(lolfx_shiny); + + m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView"); + m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj"); + m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat"); + m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage"); + m_gpu.coord = m_gpu.shader->GetAttribLocation("in_Vertex", + VertexUsage::Position, 0); + m_gpu.norm = m_gpu.shader->GetAttribLocation("in_Normal", + VertexUsage::Normal, 0); + m_gpu.color = m_gpu.shader->GetAttribLocation("in_Color", + VertexUsage::Color, 0); + + m_gpu.vdecl = new VertexDeclaration( + VertexStream(VertexUsage::Position, + VertexUsage::Normal, + VertexUsage::Color)); + + Array vertexlist; + for (int i = 0; i < m_vert.Count(); i++) + vertexlist.Push(m_vert[i].m1, + m_vert[i].m2, + (u8vec4)(m_vert[i].m3 * 255.f)); + + Array indexlist; + for (int i = 0; i < m_indices.Count(); i += 3) + { + indexlist << m_indices[i + 0]; + indexlist << m_indices[i + 1]; + indexlist << m_indices[i + 2]; + } + + m_gpu.vbo = new VertexBuffer(vertexlist.Bytes()); + void *mesh = m_gpu.vbo->Lock(0, 0); + memcpy(mesh, &vertexlist[0], vertexlist.Bytes()); + m_gpu.vbo->Unlock(); + + m_gpu.ibo = new IndexBuffer(indexlist.Bytes()); + void *indices = m_gpu.ibo->Lock(0, 0); + memcpy(indices, &indexlist[0], indexlist.Bytes()); + m_gpu.ibo->Unlock(); + + m_gpu.vertexcount = vertexlist.Count(); + m_gpu.indexcount = indexlist.Count(); +} + +void EasyMesh::Render(mat4 const &model, float damage) +{ + mat4 modelview = Scene::GetDefault()->GetViewMatrix() * model; + mat3 normalmat = transpose(inverse(mat3(modelview))); + + m_gpu.shader->Bind(); + m_gpu.shader->SetUniform(m_gpu.modelview, modelview); + m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix()); + m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat); + m_gpu.shader->SetUniform(m_gpu.damage, damage); + m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord, m_gpu.norm, m_gpu.color); + m_gpu.vdecl->Bind(); + m_gpu.ibo->Bind(); + m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles, + 0, 0, m_gpu.vertexcount, + 0, m_gpu.indexcount / 3); + m_gpu.ibo->Unbind(); + m_gpu.vdecl->Unbind(); +} + +void EasyMesh::SetCurColor(vec4 const &color) +{ + m_color = color; +} + +void EasyMesh::SetCurColor2(vec4 const &color) +{ + m_color2 = color; +} + +void EasyMesh::AddVertex(vec3 const &coord) +{ + m_vert.Push(coord, vec3(0.f, 1.f, 0.f), m_color); +} + +void EasyMesh::AddDuplicateVertex(int i) +{ + m_vert.Push(m_vert[i].m1, vec3(0.f, 1.f, 0.f), m_vert[i].m3); +} + +void EasyMesh::AppendQuad(int i1, int i2, int i3, int i4, int base) +{ + m_indices << base + i1; + m_indices << base + i2; + m_indices << base + i3; + + m_indices << base + i4; + m_indices << base + i1; + m_indices << base + i3; +} + +void EasyMesh::AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base) +{ + m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i2); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); + + m_indices << m_vert.Count(); AddDuplicateVertex(base + i4); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); +} + +void EasyMesh::AppendTriangle(int i1, int i2, int i3, int base) +{ + m_indices << base + i1; + m_indices << base + i2; + m_indices << base + i3; +} + +void EasyMesh::AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base) +{ + m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i2); + m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); +} + +void EasyMesh::ComputeNormals(int start, int vcount) +{ + for (int i = 0; i < vcount; i += 3) + { + vec3 v0 = m_vert[m_indices[start + i + 2]].m1 + - m_vert[m_indices[start + i + 0]].m1; + vec3 v1 = m_vert[m_indices[start + i + 1]].m1 + - m_vert[m_indices[start + i + 0]].m1; + vec3 n = normalize(cross(v1, v0)); + + for (int j = 0; j < 3; j++) + m_vert[m_indices[start + i + j]].m2 = n; + } +} + +void EasyMesh::SetVertColor(vec4 const &color) +{ + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + m_vert[i].m3 = color; +} + +void EasyMesh::SetCurVertNormal(vec3 const &normal) +{ + m_vert[m_vert.Count() - 1].m2 = normal; +} + +void EasyMesh::SetCurVertColor(vec4 const &color) +{ + m_vert[m_vert.Count() - 1].m3 = color; +} + +void EasyMesh::Translate(vec3 const &v) +{ + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + m_vert[i].m1 += v; +} + +void EasyMesh::RotateX(float t) { Rotate(t, vec3(1, 0, 0)); } +void EasyMesh::RotateY(float t) { Rotate(t, vec3(0, 1, 0)); } +void EasyMesh::RotateZ(float t) { Rotate(t, vec3(0, 0, 1)); } + +void EasyMesh::Rotate(float t, vec3 const &axis) +{ + mat3 m = mat3::rotate(t, axis); + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + { + m_vert[i].m1 = m * m_vert[i].m1; + m_vert[i].m2 = m * m_vert[i].m2; + } +} + +void EasyMesh::TaperX(float y, float z, float xoff) +{ + /* FIXME: this code breaks normals! */ + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + { + m_vert[i].m1.y *= 1.f + (y * m_vert[i].m1.x + xoff); + m_vert[i].m1.z *= 1.f + (z * m_vert[i].m1.x + xoff); + } +} + +void EasyMesh::TaperY(float x, float z, float yoff) +{ + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + { + m_vert[i].m1.x *= 1.f + (x * m_vert[i].m1.y + yoff); + m_vert[i].m1.z *= 1.f + (z * m_vert[i].m1.y + yoff); + } +} + +void EasyMesh::TaperZ(float x, float y, float zoff) +{ + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + { + m_vert[i].m1.x *= 1.f + (x * m_vert[i].m1.z + zoff); + m_vert[i].m1.y *= 1.f + (y * m_vert[i].m1.z + zoff); + } +} + +void EasyMesh::Scale(vec3 const &s) +{ + vec3 const invs = vec3(1) / s; + + for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) + { + m_vert[i].m1 *= s; + m_vert[i].m2 = normalize(m_vert[i].m2 * invs); + } + + /* Flip winding if the scaling involves mirroring */ + if (s.x * s.y * s.z < 0) + { + for (int i = m_cursors.Last().m2; i < m_indices.Count(); i += 3) + { + uint16_t tmp = m_indices[i + 0]; + m_indices[i + 0] = m_indices[i + 1]; + m_indices[i + 1] = tmp; + } + } +} + +void EasyMesh::MirrorX() { DupAndScale(vec3(-1, 1, 1)); } +void EasyMesh::MirrorY() { DupAndScale(vec3(1, -1, 1)); } +void EasyMesh::MirrorZ() { DupAndScale(vec3(1, 1, -1)); } + +void EasyMesh::DupAndScale(vec3 const &s) +{ + int vlen = m_vert.Count() - m_cursors.Last().m1; + int tlen = m_indices.Count() - m_cursors.Last().m2; + + for (int i = 0; i < vlen; i++) + m_vert << m_vert[m_cursors.Last().m1++]; + + for (int i = 0; i < tlen; i++) + m_indices << m_indices[m_cursors.Last().m2++] + vlen; + + Scale(s); + + m_cursors.Last().m1 -= vlen; + m_cursors.Last().m2 -= tlen; +} + +void EasyMesh::AppendCylinder(int nsides, float h, float r1, float r2, + int dualside, int smooth) +{ + int vbase = m_vert.Count(); + + mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f); + vec3 p1(r1, -h * .5f, 0.f), p2(r2, h * .5f, 0.f), n; + + /* Construct normal */ + n = p2; + n.y = r1 * (r1 - r2) / h; + if (!smooth) + n = mat3::rotate(180.0f / nsides, 0.f, 1.f, 0.f) * n; + n = normalize(n); + + /* FIXME: normals should be flipped in two-sided mode, but that + * means duplicating the vertices again... */ + for (int i = 0; i < nsides; i++) + { + AddVertex(p1); SetCurVertNormal(n); + AddVertex(p2); SetCurVertNormal(n); + SetCurVertColor(m_color2); + + if (smooth) + { + int j = (i + 1) % nsides; + AppendQuad(j * 2, j * 2 + 1, i * 2 + 1, i * 2, vbase); + if (dualside) + AppendQuad(i * 2, i * 2 + 1, j * 2 + 1, j * 2, vbase); + } + + p1 = rotmat * p1; + p2 = rotmat * p2; + + if (!smooth) + { + AddVertex(p1); SetCurVertNormal(n); + AddVertex(p2); SetCurVertNormal(n); + SetCurVertColor(m_color2); + + AppendQuad(i * 4 + 2, i * 4 + 3, i * 4 + 1, i * 4, vbase); + if (dualside) + AppendQuad(i * 4, i * 4 + 1, i * 4 + 3, i * 4 + 2, vbase); + } + + n = rotmat * n; + } +} + +void EasyMesh::AppendSphere(int ndivisions, vec3 const &size) +{ + ndivisions *= 2; + + int ibase = m_indices.Count(); + int vbase = m_vert.Count(); + + vec3 d = size * 0.5f; + float const pi = std::acos(-1.0f); + + Array table; + for (int i = 0; i <= ndivisions; i++) + table.Push(vec2(std::sin(pi * 2 / ndivisions * i) + 1e-5f, + std::cos(pi * 2 / ndivisions * i) + 1e-5f)); + + for (int j = 0; j <= ndivisions / 2; j++) + for (int i = 0; i < ndivisions; i++) + { + int j2 = j + 1; + int i2 = (i + 1) % ndivisions; + + AddVertex(d * vec3(table[i], 1.0f) * table[j].xxy); + AddVertex(d * vec3(table[i2], 1.0f) * table[j].xxy); + AddVertex(d * vec3(table[i2], 1.0f) * table[j2].xxy); + AddVertex(d * vec3(table[i], 1.0f) * table[j2].xxy); + } + + for (int i = vbase; i < m_vert.Count(); i += 4) + AppendQuad(0, 1, 2, 3, i); + + ComputeNormals(ibase, m_indices.Count() - ibase); +} + +void EasyMesh::AppendBox(vec3 const &size, float chamf) +{ + AppendBox(size, chamf, false); +} + +void EasyMesh::AppendSmoothChamfBox(vec3 const &size, float chamf) +{ + AppendBox(size, chamf, true); +} + +void EasyMesh::AppendFlatChamfBox(vec3 const &size, float chamf) +{ + AppendBox(size, chamf, false); +} + +void EasyMesh::AppendBox(vec3 const &size, float chamf, bool smooth) +{ + if (chamf < 0.0f) + { + AppendBox(size + vec3(chamf * 2.0f), -chamf, smooth); + return; + } + + int vbase = m_vert.Count(); + int ibase = m_indices.Count(); + + vec3 d = size * 0.5f; + + AddVertex(vec3(-d.x, -d.y, -d.z - chamf)); + AddVertex(vec3(-d.x, +d.y, -d.z - chamf)); + AddVertex(vec3(+d.x, +d.y, -d.z - chamf)); + AddVertex(vec3(+d.x, -d.y, -d.z - chamf)); + + AddVertex(vec3(-d.x - chamf, -d.y, +d.z)); + AddVertex(vec3(-d.x - chamf, +d.y, +d.z)); + AddVertex(vec3(-d.x - chamf, +d.y, -d.z)); + AddVertex(vec3(-d.x - chamf, -d.y, -d.z)); + + AddVertex(vec3(+d.x, -d.y, +d.z + chamf)); + AddVertex(vec3(+d.x, +d.y, +d.z + chamf)); + AddVertex(vec3(-d.x, +d.y, +d.z + chamf)); + AddVertex(vec3(-d.x, -d.y, +d.z + chamf)); + + AddVertex(vec3(+d.x + chamf, -d.y, -d.z)); + AddVertex(vec3(+d.x + chamf, +d.y, -d.z)); + AddVertex(vec3(+d.x + chamf, +d.y, +d.z)); + AddVertex(vec3(+d.x + chamf, -d.y, +d.z)); + + AddVertex(vec3(-d.x, -d.y - chamf, +d.z)); + AddVertex(vec3(-d.x, -d.y - chamf, -d.z)); + AddVertex(vec3(+d.x, -d.y - chamf, -d.z)); + AddVertex(vec3(+d.x, -d.y - chamf, +d.z)); + + AddVertex(vec3(-d.x, +d.y + chamf, -d.z)); + AddVertex(vec3(-d.x, +d.y + chamf, +d.z)); + AddVertex(vec3(+d.x, +d.y + chamf, +d.z)); + AddVertex(vec3(+d.x, +d.y + chamf, -d.z)); + + /* The 6 quads on each side of the box */ + for (int i = 0; i < 24; i += 4) + AppendQuad(i, i + 1, i + 2, i + 3, vbase); + + ComputeNormals(ibase, m_indices.Count() - ibase); + ibase = m_indices.Count(); + + /* The 8 quads at each edge of the box */ + if (chamf) + { + static int const quadlist[48] = + { + 0, 3, 18, 17, 4, 7, 17, 16, 8, 11, 16, 19, 12, 15, 19, 18, + 2, 1, 20, 23, 6, 5, 21, 20, 10, 9, 22, 21, 14, 13, 23, 22, + 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 3, 2, + }; + + for (int i = 0; i < 48; i += 4) + { + if (smooth) + AppendQuad(quadlist[i], quadlist[i + 1], + quadlist[i + 2], quadlist[i + 3], vbase); + else + AppendQuadDuplicateVerts(quadlist[i], quadlist[i + 1], + quadlist[i + 2], quadlist[i + 3], vbase); + } + } + + /* The 8 triangles at each corner of the box */ + if (chamf) + { + static int const trilist[24] = + { + 3, 12, 18, 15, 8, 19, 11, 4, 16, 7, 0, 17, + 2, 23, 13, 14, 22, 9, 10, 21, 5, 6, 20, 1, + }; + + for (int i = 0; i < 24; i += 3) + { + if (smooth) + AppendTriangle(trilist[i], trilist[i + 1], + trilist[i + 2], vbase); + else + AppendTriangleDuplicateVerts(trilist[i], trilist[i + 1], + trilist[i + 2], vbase); + } + } + + if (!smooth) + ComputeNormals(ibase, m_indices.Count() - ibase); +} + +void EasyMesh::AppendStar(int nbranches, float r1, float r2, + int fade, int fade2) +{ + int vbase = m_vert.Count(); + + AddVertex(vec3(0.f, 0.f, 0.f)); + + mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); + vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f); + + p2 = rotmat * p2; + rotmat = rotmat * rotmat; + + for (int i = 0; i < nbranches; i++) + { + AddVertex(p1); + if (fade2) + SetCurVertColor(m_color2); + + AddVertex(p2); + if (fade) + SetCurVertColor(m_color2); + + AppendQuad(0, 2 * i + 1, 2 * i + 2, (2 * i + 3) % (2 * nbranches), + vbase); + + p1 = rotmat * p1; + p2 = rotmat * p2; + } +} + +void EasyMesh::AppendExpandedStar(int nbranches, float r1, + float r2, float extrar) +{ + int vbase = m_vert.Count(); + + AddVertex(vec3(0.f, 0.f, 0.f)); + + mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); + vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f), + p3(r1 + extrar, 0.f, 0.f), p4(r2 + extrar, 0.f, 0.f);; + + p2 = rotmat * p2; + p4 = rotmat * p4; + rotmat = rotmat * rotmat; + + for (int i = 0; i < nbranches; i++) + { + AddVertex(p1); + AddVertex(p2); + AddVertex(p3); SetCurVertColor(m_color2); + AddVertex(p4); SetCurVertColor(m_color2); + + int j = (i + 1) % nbranches; + AppendQuad(0, 4 * i + 1, 4 * i + 2, 4 * j + 1, vbase); + AppendQuad(4 * i + 1, 4 * i + 3, 4 * i + 4, 4 * i + 2, vbase); + AppendQuad(4 * j + 1, 4 * i + 2, 4 * i + 4, 4 * j + 3, vbase); + + p1 = rotmat * p1; + p2 = rotmat * p2; + p3 = rotmat * p3; + p4 = rotmat * p4; + } +} + +void EasyMesh::AppendDisc(int nsides, float r, int fade) +{ + int vbase = m_vert.Count(); + + AddVertex(vec3(0.f, 0.f, 0.f)); + + mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f); + vec3 p1(r, 0.f, 0.f); + + for (int i = 0; i < nsides; i++) + { + AddVertex(p1); + if (fade) + SetCurVertColor(m_color2); + AppendTriangle(0, i + 1, ((i + 1) % nsides) + 1, vbase); + p1 = rotmat * p1; + } +} + +void EasyMesh::AppendSimpleTriangle(float size, int fade) +{ + mat3 m = mat3::rotate(120.f, 0.f, 1.f, 0.f); + vec3 p(0.f, 0.f, size); + + AddVertex(p); + p = m * p; + AddVertex(p); + if (fade) + SetCurVertColor(m_color2); + p = m * p; + AddVertex(p); + if (fade) + SetCurVertColor(m_color2); + + AppendTriangle(0, 1, 2, m_vert.Count() - 3); +} + +void EasyMesh::AppendSimpleQuad(float size, int fade) +{ + AppendSimpleQuad(vec2(size * .5f), vec2(size * -.5f), 0.f, fade); +} + +void EasyMesh::AppendSimpleQuad(vec2 p1, vec2 p2, float z, int fade) +{ + AddVertex(vec3(p2.x, z, -p1.y)); + AddVertex(vec3(p2.x, z, -p2.y)); + AddVertex(vec3(p1.x, z, -p2.y)); + if (fade) + SetCurVertColor(m_color2); + AddVertex(vec3(p1.x, z, -p1.y)); + if (fade) + SetCurVertColor(m_color2); + + AppendQuad(3, 2, 1, 0, m_vert.Count() - 4); + ComputeNormals(m_indices.Count() - 6, 6); +} + +void EasyMesh::AppendCog(int nbsides, float h, float r1, float r2, float r12, + float r22, float sidemul, int offset) +{ + int ibase = m_indices.Count(); + int vbase = m_vert.Count(); + + AddVertex(vec3(0.f, h * .5f, 0.f)); + AddVertex(vec3(0.f, h * -.5f, 0.f)); + SetCurVertColor(m_color2); + + mat3 rotmat = mat3::rotate(180.0f / nbsides, 0.f, 1.f, 0.f); + mat3 smat1 = mat3::rotate(sidemul * 180.0f / nbsides, 0.f, 1.f, 0.f); + mat3 smat2 = mat3::rotate(sidemul * -360.0f / nbsides, 0.f, 1.f, 0.f); + + vec3 p[8]; + + p[0] = vec3(r1, h * .5f, 0.f); + p[1] = rotmat * p[0]; + p[2] = smat1 * (rotmat * vec3(r1 + r12, h * .5f, 0.f)); + p[3] = smat2 * (rotmat * p[2]); + + p[4] = vec3(r2, h * -.5f, 0.f); + p[5] = rotmat * p[4]; + p[6] = smat1 * (rotmat * vec3(r2 + r22, h * -.5f, 0.f)); + p[7] = smat2 * (rotmat * p[6]); + + if (offset & 1) + for (int n = 0; n < 8; n++) + p[n] = rotmat * p[n]; + + rotmat = rotmat * rotmat; + + for (int i = 0; i < nbsides; i++) + { + /* Each vertex will share three faces, so three different + * normals, therefore we add each vertex three times. */ + for (int n = 0; n < 24; n++) + { + AddVertex(p[n / 3]); + if (n / 3 >= 4) + SetCurVertColor(m_color2); + } + + int j = 24 * i, k = 24 * ((i + 1) % nbsides); + + /* The top and bottom faces */ + AppendQuad(0, j + 2, j + 5, k + 2, vbase); + AppendQuad(1, k + 14, j + 17, j + 14, vbase); + AppendQuad(j + 5, j + 8, j + 11, k + 2, vbase); + AppendQuad(k + 14, j + 23, j + 20, j + 17, vbase); + + /* The side quads */ + AppendQuad(j + 6, j + 3, j + 15, j + 18, vbase); + AppendQuad(j + 9, j + 7, j + 19, j + 21, vbase); + AppendQuad(j + 12, j + 10, j + 22, j + 24, vbase); + AppendQuad(k + 4, j + 13, j + 25, k + 16, vbase); + + for (int n = 0; n < 8; n++) + p[n] = rotmat * p[n]; + } + + ComputeNormals(ibase, m_indices.Count() - ibase); +} + +void EasyMesh::Chamfer(float f) +{ + int vlen = m_vert.Count() - m_cursors.Last().m1; + int ilen = m_indices.Count() - m_cursors.Last().m2; + + /* Step 1: enumerate all faces. This is done by merging triangles + * that are coplanar and share an edge. */ + int *triangle_classes = new int[ilen / 3]; + for (int i = 0; i < ilen / 3; i++) + triangle_classes[i] = -1; + + for (int i = 0; i < ilen / 3; i++) + { + + } + + /* Fun shit: reduce all triangles */ + int *vertices = new int[vlen]; + memset(vertices, 0, vlen * sizeof(int)); + for (int i = 0; i < ilen; i++) + vertices[m_indices[i]]++; + + for (int i = 0; i < ilen / 3; i++) + { + #if 0 + if (vertices[m_indices[i * 3]] > 1) + continue; + if (vertices[m_indices[i * 3 + 1]] > 1) + continue; + if (vertices[m_indices[i * 3 + 2]] > 1) + continue; + #endif + + vec3 bary = 1.f / 3.f * (m_vert[m_indices[i * 3]].m1 + + m_vert[m_indices[i * 3 + 1]].m1 + + m_vert[m_indices[i * 3 + 2]].m1); + for (int k = 0; k < 3; k++) + { + vec3 &p = m_vert[m_indices[i * 3 + k]].m1; + p -= normalize(p - bary) * f; + } + } +} + +} /* namespace lol */ + diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h new file mode 100644 index 00000000..91951c43 --- /dev/null +++ b/src/easymesh/easymesh.h @@ -0,0 +1,107 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The EasyMesh class +// ------------------ +// + +#if !defined __EASYMESH_EASYMESH_H__ +#define __EASYMESH_EASYMESH_H__ + +namespace lol +{ + +class EasyMesh +{ + friend class EasyMeshParser; + +public: + EasyMesh(); + + bool Compile(char const *command); + void MeshConvert(); + void Render(mat4 const &model, float damage = 0.f); + +private: + void OpenBrace(); + void CloseBrace(); + + void SetCurColor(vec4 const &color); + void SetCurColor2(vec4 const &color); + void AddVertex(vec3 const &coord); + void AddDuplicateVertex(int i); + void AppendQuad(int i1, int i2, int i3, int i4, int base); + void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base); + void AppendTriangle(int i1, int i2, int i3, int base); + void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base); + void ComputeNormals(int start, int vcount); + void SetVertColor(vec4 const &color); + void SetCurVertNormal(vec3 const &normal); + void SetCurVertColor(vec4 const &color); + + void Translate(vec3 const &v); + void RotateX(float t); + void RotateY(float t); + void RotateZ(float t); + void Rotate(float t, vec3 const &axis); + void TaperX(float y, float z, float xoff); + void TaperY(float x, float z, float yoff); + void TaperZ(float x, float y, float zoff); + void Scale(vec3 const &s); + void MirrorX(); + void MirrorY(); + void MirrorZ(); + void DupAndScale(vec3 const &s); + void Chamfer(float f); + + void AppendCylinder(int nsides, float h, float r1, float r2, + int dualside, int smooth); + void AppendSphere(int ndivisions, vec3 const &size); + void AppendBox(vec3 const &size, float chamf = 0.f); + void AppendSmoothChamfBox(vec3 const &size, float chamf); + void AppendFlatChamfBox(vec3 const &size, float chamf); + void AppendBox(vec3 const &size, float chamf, bool smooth); + void AppendStar(int nbranches, float r1, float r2, + int fade = 0, int fade2 = 0); + void AppendExpandedStar(int nbranches, float r1, float r2, float extrar); + void AppendDisc(int nsides, float r, int fade = 0); + void AppendSimpleTriangle(float size, int fade = 0); + void AppendSimpleQuad(float size, int fade = 0); + void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0); + void AppendCog(int nbsides, float h, float r1, float r2, + float r12, float r22, float sidemul, int offset); + +private: + vec4 m_color, m_color2; + Array m_indices; + Array m_vert; + Array m_cursors; + + /* FIXME: put this in a separate class so that we can copy meshes. */ + struct + { + Shader *shader; + ShaderAttrib coord, norm, color; + ShaderUniform modelview, proj, normalmat, damage; + VertexDeclaration *vdecl; + VertexBuffer *vbo; + IndexBuffer *ibo; + int vertexcount, indexcount; + } + m_gpu; +}; + +} /* namespace lol */ + +#endif /* __EASYMESH_EASYMESH_H__ */ + diff --git a/src/easymesh/shiny.lolfx b/src/easymesh/shiny.lolfx new file mode 100644 index 00000000..f1a4cb79 --- /dev/null +++ b/src/easymesh/shiny.lolfx @@ -0,0 +1,109 @@ + +-- GLSL.Vert -- +#version 120 + +attribute vec3 in_Vertex; +attribute vec3 in_Normal; +attribute vec4 in_Color; +uniform mat4 in_ModelView; +uniform mat4 in_Proj; +uniform mat3 in_NormalMat; +uniform float in_Damage; +varying vec4 pass_Color; + +void main(void) +{ + /* Material properties */ + vec3 specular_reflect = vec3(0.8, 0.75, 0.4); + float specular_power = 60.0; + + /* World properties */ + float ambient_mul = 0.5; + vec3 light_dir = normalize(vec3(0.3, 0.3, 0.7)); + vec3 ambient_color = vec3(0.25, 0.2, 0.35); + vec3 diffuse_color = vec3(1.0, 1.0, 0.6); + vec3 specular_color = vec3(1.0, 1.0, 0.6); + + vec3 tnorm = normalize(in_NormalMat * in_Normal); + vec4 eye = in_ModelView * vec4(in_Vertex, 1.0); + + vec3 s = light_dir; /* normalize(eye - lightpos); */ + vec3 v = normalize(-eye.xyz); + vec3 r = reflect(-s, tnorm); + + vec3 ambient = ambient_color; + float sdotn = max(dot(s, tnorm), 0.0); + vec3 diffuse = diffuse_color * sdotn; + vec3 specular = vec3(0.0, 0.0, 0.0); + if (sdotn > 0.0) + specular = specular_color * specular_reflect + * pow(max(dot(r, v), 0.0), specular_power); + vec3 light = ambient + diffuse + specular; + + vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0) + + (1.0 - in_Damage) * in_Color; + pass_Color = real_color * vec4(light, 1.0); + gl_Position = in_Proj * eye; +} + +-- GLSL.Frag -- +#version 120 + +//precision highp float; +varying vec4 pass_Color; + +void main(void) { + gl_FragColor = pass_Color; +} + +-- HLSL.Vert -- + +void main(float3 in_Vertex : POSITION, + float3 in_Normal : NORMAL, + float4 in_Color : COLOR, + uniform float4x4 in_ModelView, + uniform float4x4 in_Proj, + uniform float3x3 in_NormalMat, + uniform float in_Damage, + out float4 out_Position : POSITION, + out float4 pass_Color : COLOR) +{ + float3 specular_reflect = float3(0.8, 0.75, 0.4); + float specular_power = 60.0; + float ambient_mul = 0.5; + float3 light_dir = normalize(float3(0.3, 0.3, 0.7)); + float3 ambient_color = float3(0.25, 0.2, 0.35); + float3 diffuse_color = float3(1.0, 1.0, 0.6); + float3 specular_color = float3(1.0, 1.0, 0.6); + float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); + float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); + float3 s = light_dir; + float3 v = normalize(-eye.xyz); + float3 r = reflect(-s, tnorm); + float3 ambient = ambient_color; + float sdotn = max(dot(s, tnorm), 0.0); + float3 diffuse = diffuse_color * sdotn; + float3 specular = float3(0.0, 0.0, 0.0); + if (sdotn > 0.0) + specular = specular_color * specular_reflect + * pow(max(dot(r, v), 0.0), specular_power); + float3 light = ambient + diffuse + specular; +#ifdef _XBOX + float4 real_color = in_Color.abgr; +#else + float4 real_color = in_Color; +#endif + real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0) + + (1.0 - in_Damage) * real_color; + pass_Color = real_color * float4(light, 1.0); + out_Position = mul(in_Proj, eye); +} + +-- HLSL.Frag -- + +void main(float4 pass_Color : COLOR, + out float4 out_FragColor : COLOR) +{ + out_FragColor = pass_Color; +} + diff --git a/src/generated/easymesh-parser.cpp b/src/generated/easymesh-parser.cpp new file mode 100644 index 00000000..763faa40 --- /dev/null +++ b/src/generated/easymesh-parser.cpp @@ -0,0 +1,1387 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Skeleton implementation for Bison LALR(1) parsers in C++ + + Copyright (C) 2002-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +// Take the name prefix into account. +#define yylex lollex + +/* First part of user declarations. */ + +/* Line 293 of lalr1.cc */ +#line 1 "easymesh/easymesh-parser.y" + +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "easymesh/easymesh.h" + +#include + + + +/* Line 293 of lalr1.cc */ +#line 66 "generated/easymesh-parser.cpp" + + +#include "easymesh-parser.h" + +/* User implementation prologue. */ + +/* Line 299 of lalr1.cc */ +#line 65 "easymesh/easymesh-parser.y" + +#include "easymesh/easymesh-compiler.h" + +#undef yylex +#define yylex mc.m_lexer->lex + + +/* Line 299 of lalr1.cc */ +#line 83 "generated/easymesh-parser.cpp" + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* FIXME: INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (false) +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#define YYUSE(e) ((void) (e)) + +/* Enable debugging if requested. */ +#if YYDEBUG + +/* A pseudo ostream that takes yydebug_ into account. */ +# define YYCDEBUG if (yydebug_) (*yycdebug_) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_symbol_print_ ((Type), (Value), (Location)); \ + *yycdebug_ << std::endl; \ + } \ +} while (false) + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug_) \ + yy_reduce_print_ (Rule); \ +} while (false) + +# define YY_STACK_PRINT() \ +do { \ + if (yydebug_) \ + yystack_print_ (); \ +} while (false) + +#else /* !YYDEBUG */ + +# define YYCDEBUG if (false) std::cerr +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_REDUCE_PRINT(Rule) +# define YY_STACK_PRINT() + +#endif /* !YYDEBUG */ + +#define yyerrok (yyerrstatus_ = 0) +#define yyclearin (yychar = yyempty_) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYRECOVERING() (!!yyerrstatus_) + + +namespace lol { + +/* Line 382 of lalr1.cc */ +#line 169 "generated/easymesh-parser.cpp" + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + EasyMeshParser::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr = ""; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + + /// Build a parser object. + EasyMeshParser::EasyMeshParser (class EasyMeshCompiler& mc_yyarg) + : +#if YYDEBUG + yydebug_ (false), + yycdebug_ (&std::cerr), +#endif + mc (mc_yyarg) + { + } + + EasyMeshParser::~EasyMeshParser () + { + } + +#if YYDEBUG + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + inline void + EasyMeshParser::yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yyvaluep); + switch (yytype) + { + default: + break; + } + } + + + void + EasyMeshParser::yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") + << ' ' << yytname_[yytype] << " (" + << *yylocationp << ": "; + yy_symbol_value_print_ (yytype, yyvaluep, yylocationp); + *yycdebug_ << ')'; + } +#endif + + void + EasyMeshParser::yydestruct_ (const char* yymsg, + int yytype, semantic_type* yyvaluep, location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yymsg); + YYUSE (yyvaluep); + + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } + } + + void + EasyMeshParser::yypop_ (unsigned int n) + { + yystate_stack_.pop (n); + yysemantic_stack_.pop (n); + yylocation_stack_.pop (n); + } + +#if YYDEBUG + std::ostream& + EasyMeshParser::debug_stream () const + { + return *yycdebug_; + } + + void + EasyMeshParser::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + EasyMeshParser::debug_level_type + EasyMeshParser::debug_level () const + { + return yydebug_; + } + + void + EasyMeshParser::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } +#endif + + inline bool + EasyMeshParser::yy_pact_value_is_default_ (int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + inline bool + EasyMeshParser::yy_table_value_is_error_ (int yyvalue) + { + return yyvalue == yytable_ninf_; + } + + int + EasyMeshParser::parse () + { + /// Lookahead and lookahead in internal form. + int yychar = yyempty_; + int yytoken = 0; + + /* State. */ + int yyn; + int yylen = 0; + int yystate = 0; + + /* Error handling. */ + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// Semantic value of the lookahead. + semantic_type yylval; + /// Location of the lookahead. + location_type yylloc; + /// The locations where the error started and ended. + location_type yyerror_range[3]; + + /// $$. + semantic_type yyval; + /// @$. + location_type yyloc; + + int yyresult; + + YYCDEBUG << "Starting parse" << std::endl; + + + /* Initialize the stacks. The initial state will be pushed in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystate_stack_ = state_stack_type (0); + yysemantic_stack_ = semantic_stack_type (0); + yylocation_stack_ = location_stack_type (0); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* New state. */ + yynewstate: + yystate_stack_.push (yystate); + YYCDEBUG << "Entering state " << yystate << std::endl; + + /* Accept? */ + if (yystate == yyfinal_) + goto yyacceptlab; + + goto yybackup; + + /* Backup. */ + yybackup: + + /* Try to take a decision without lookahead. */ + yyn = yypact_[yystate]; + if (yy_pact_value_is_default_ (yyn)) + goto yydefault; + + /* Read a lookahead token. */ + if (yychar == yyempty_) + { + YYCDEBUG << "Reading a token: "; + yychar = yylex (&yylval, &yylloc); + } + + + /* Convert token to internal form. */ + if (yychar <= yyeof_) + { + yychar = yytoken = yyeof_; + YYCDEBUG << "Now at end of input." << std::endl; + } + else + { + yytoken = yytranslate_ (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) + goto yydefault; + + /* Reduce or error. */ + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yy_table_value_is_error_ (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the token being shifted. */ + yychar = yyempty_; + + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus_) + --yyerrstatus_; + + yystate = yyn; + goto yynewstate; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen) + yyval = yysemantic_stack_[yylen - 1]; + else + yyval = yysemantic_stack_[0]; + + { + slice slice (yylocation_stack_, yylen); + YYLLOC_DEFAULT (yyloc, slice, yylen); + } + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 7: + +/* Line 690 of lalr1.cc */ +#line 89 "easymesh/easymesh-parser.y" + { mc.m_mesh.OpenBrace(); } + break; + + case 8: + +/* Line 690 of lalr1.cc */ +#line 93 "easymesh/easymesh-parser.y" + { mc.m_mesh.CloseBrace(); } + break; + + case 14: + +/* Line 690 of lalr1.cc */ +#line 108 "easymesh/easymesh-parser.y" + { mc.m_mesh.SetCurColor(vec4((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3)); } + break; + + case 15: + +/* Line 690 of lalr1.cc */ +#line 109 "easymesh/easymesh-parser.y" + { uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); + vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + mc.m_mesh.SetCurColor(vec4(v) * (1. / 255)); } + break; + + case 16: + +/* Line 690 of lalr1.cc */ +#line 112 "easymesh/easymesh-parser.y" + { mc.m_mesh.SetCurColor2(vec4((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3)); } + break; + + case 17: + +/* Line 690 of lalr1.cc */ +#line 113 "easymesh/easymesh-parser.y" + { uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); + vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + mc.m_mesh.SetCurColor2(vec4(v) * (1. / 255)); } + break; + + case 18: + +/* Line 690 of lalr1.cc */ +#line 119 "easymesh/easymesh-parser.y" + { mc.m_mesh.Chamfer((yysemantic_stack_[(2) - (2)].args).f0); } + break; + + case 19: + +/* Line 690 of lalr1.cc */ +#line 120 "easymesh/easymesh-parser.y" + { mc.m_mesh.Translate(vec3((yysemantic_stack_[(2) - (2)].args).f0, 0, 0)); } + break; + + case 20: + +/* Line 690 of lalr1.cc */ +#line 121 "easymesh/easymesh-parser.y" + { mc.m_mesh.Translate(vec3(0, (yysemantic_stack_[(2) - (2)].args).f0, 0)); } + break; + + case 21: + +/* Line 690 of lalr1.cc */ +#line 122 "easymesh/easymesh-parser.y" + { mc.m_mesh.Translate(vec3(0, 0, (yysemantic_stack_[(2) - (2)].args).f0)); } + break; + + case 22: + +/* Line 690 of lalr1.cc */ +#line 123 "easymesh/easymesh-parser.y" + { mc.m_mesh.Translate(vec3((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2)); } + break; + + case 23: + +/* Line 690 of lalr1.cc */ +#line 124 "easymesh/easymesh-parser.y" + { mc.m_mesh.RotateX((yysemantic_stack_[(2) - (2)].args).f0); } + break; + + case 24: + +/* Line 690 of lalr1.cc */ +#line 125 "easymesh/easymesh-parser.y" + { mc.m_mesh.RotateY((yysemantic_stack_[(2) - (2)].args).f0); } + break; + + case 25: + +/* Line 690 of lalr1.cc */ +#line 126 "easymesh/easymesh-parser.y" + { mc.m_mesh.RotateZ((yysemantic_stack_[(2) - (2)].args).f0); } + break; + + case 26: + +/* Line 690 of lalr1.cc */ +#line 127 "easymesh/easymesh-parser.y" + { mc.m_mesh.TaperX((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2); } + break; + + case 27: + +/* Line 690 of lalr1.cc */ +#line 128 "easymesh/easymesh-parser.y" + { mc.m_mesh.TaperY((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2); } + break; + + case 28: + +/* Line 690 of lalr1.cc */ +#line 129 "easymesh/easymesh-parser.y" + { mc.m_mesh.TaperZ((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2); } + break; + + case 29: + +/* Line 690 of lalr1.cc */ +#line 130 "easymesh/easymesh-parser.y" + { mc.m_mesh.Scale(vec3((yysemantic_stack_[(2) - (2)].args).f0, 0, 0)); } + break; + + case 30: + +/* Line 690 of lalr1.cc */ +#line 131 "easymesh/easymesh-parser.y" + { mc.m_mesh.Scale(vec3(0, (yysemantic_stack_[(2) - (2)].args).f0, 0)); } + break; + + case 31: + +/* Line 690 of lalr1.cc */ +#line 132 "easymesh/easymesh-parser.y" + { mc.m_mesh.Scale(vec3(0, 0, (yysemantic_stack_[(2) - (2)].args).f0)); } + break; + + case 32: + +/* Line 690 of lalr1.cc */ +#line 133 "easymesh/easymesh-parser.y" + { mc.m_mesh.Scale(vec3((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2)); } + break; + + case 33: + +/* Line 690 of lalr1.cc */ +#line 134 "easymesh/easymesh-parser.y" + { mc.m_mesh.MirrorX(); } + break; + + case 34: + +/* Line 690 of lalr1.cc */ +#line 135 "easymesh/easymesh-parser.y" + { mc.m_mesh.MirrorY(); } + break; + + case 35: + +/* Line 690 of lalr1.cc */ +#line 136 "easymesh/easymesh-parser.y" + { mc.m_mesh.MirrorZ(); } + break; + + case 36: + +/* Line 690 of lalr1.cc */ +#line 140 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendCylinder((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, + (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3, + (int)(yysemantic_stack_[(2) - (2)].args).f4, (int)(yysemantic_stack_[(2) - (2)].args).f5); } + break; + + case 37: + +/* Line 690 of lalr1.cc */ +#line 143 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendBox(vec3((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2)); } + break; + + case 38: + +/* Line 690 of lalr1.cc */ +#line 144 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendSmoothChamfBox(vec3((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, + (yysemantic_stack_[(2) - (2)].args).f2), (yysemantic_stack_[(2) - (2)].args).f3); } + break; + + case 39: + +/* Line 690 of lalr1.cc */ +#line 146 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendFlatChamfBox(vec3((yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, + (yysemantic_stack_[(2) - (2)].args).f2), (yysemantic_stack_[(2) - (2)].args).f3); } + break; + + case 40: + +/* Line 690 of lalr1.cc */ +#line 148 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendSphere((yysemantic_stack_[(2) - (2)].args).f0, + vec3((yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3)); } + break; + + case 41: + +/* Line 690 of lalr1.cc */ +#line 150 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendStar((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, + (int)(yysemantic_stack_[(2) - (2)].args).f3, (int)(yysemantic_stack_[(2) - (2)].args).f4); } + break; + + case 42: + +/* Line 690 of lalr1.cc */ +#line 152 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendExpandedStar((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, + (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3); } + break; + + case 43: + +/* Line 690 of lalr1.cc */ +#line 154 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendDisc((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (int)(yysemantic_stack_[(2) - (2)].args).f2); } + break; + + case 44: + +/* Line 690 of lalr1.cc */ +#line 155 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendSimpleTriangle((yysemantic_stack_[(2) - (2)].args).f0, (int)(yysemantic_stack_[(2) - (2)].args).f1); } + break; + + case 45: + +/* Line 690 of lalr1.cc */ +#line 156 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendSimpleQuad((yysemantic_stack_[(2) - (2)].args).f0, (int)(yysemantic_stack_[(2) - (2)].args).f1); } + break; + + case 46: + +/* Line 690 of lalr1.cc */ +#line 157 "easymesh/easymesh-parser.y" + { mc.m_mesh.AppendCog((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3, + (yysemantic_stack_[(2) - (2)].args).f4, (yysemantic_stack_[(2) - (2)].args).f5, (yysemantic_stack_[(2) - (2)].args).f6, (int)(yysemantic_stack_[(2) - (2)].args).f7); } + break; + + case 47: + +/* Line 690 of lalr1.cc */ +#line 161 "easymesh/easymesh-parser.y" + { (yyval.args).f0 = (yysemantic_stack_[(1) - (1)].fval); } + break; + + case 48: + +/* Line 690 of lalr1.cc */ +#line 162 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f1 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 49: + +/* Line 690 of lalr1.cc */ +#line 163 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f2 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 50: + +/* Line 690 of lalr1.cc */ +#line 164 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f3 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 51: + +/* Line 690 of lalr1.cc */ +#line 165 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f4 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 52: + +/* Line 690 of lalr1.cc */ +#line 166 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f5 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 53: + +/* Line 690 of lalr1.cc */ +#line 167 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f6 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 54: + +/* Line 690 of lalr1.cc */ +#line 168 "easymesh/easymesh-parser.y" + { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f7 = (yysemantic_stack_[(2) - (2)].fval); } + break; + + case 55: + +/* Line 690 of lalr1.cc */ +#line 171 "easymesh/easymesh-parser.y" + { (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); } + break; + + case 56: + +/* Line 690 of lalr1.cc */ +#line 172 "easymesh/easymesh-parser.y" + { (yyval.fval) = -(yysemantic_stack_[(2) - (2)].fval); } + break; + + + +/* Line 690 of lalr1.cc */ +#line 797 "generated/easymesh-parser.cpp" + default: + break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action + invokes YYABORT, YYACCEPT, or YYERROR immediately after altering + yychar. In the case of YYABORT or YYACCEPT, an incorrect + destructor might then be invoked immediately. In the case of + YYERROR, subsequent parser actions might lead to an incorrect + destructor call or verbose syntax error message before the + lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); + + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + + yysemantic_stack_.push (yyval); + yylocation_stack_.push (yyloc); + + /* Shift the result of the reduction. */ + yyn = yyr1_[yyn]; + yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0]; + if (0 <= yystate && yystate <= yylast_ + && yycheck_[yystate] == yystate_stack_[0]) + yystate = yytable_[yystate]; + else + yystate = yydefgoto_[yyn - yyntokens_]; + goto yynewstate; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yytranslate_ (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus_) + { + ++yynerrs_; + if (yychar == yyempty_) + yytoken = yyempty_; + error (yylloc, yysyntax_error_ (yystate, yytoken)); + } + + yyerror_range[1] = yylloc; + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= yyeof_) + { + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + } + else + { + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (false) + goto yyerrorlab; + + yyerror_range[1] = yylocation_stack_[yylen - 1]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + yystate = yystate_stack_[0]; + goto yyerrlab1; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact_[yystate]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += yyterror_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystate_stack_.height () == 1) + YYABORT; + + yyerror_range[1] = yylocation_stack_[0]; + yydestruct_ ("Error: popping", + yystos_[yystate], + &yysemantic_stack_[0], &yylocation_stack_[0]); + yypop_ (); + yystate = yystate_stack_[0]; + YY_STACK_PRINT (); + } + + yyerror_range[2] = yylloc; + // Using YYLLOC is tempting, but would change the location of + // the lookahead. YYLOC is available though. + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yyloc); + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], + &yysemantic_stack_[0], &yylocation_stack_[0]); + + yystate = yyn; + goto yynewstate; + + /* Accept. */ + yyacceptlab: + yyresult = 0; + goto yyreturn; + + /* Abort. */ + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyreturn: + if (yychar != yyempty_) + { + /* Make sure we have latest lookahead translation. See comments + at user semantic actions for why this is necessary. */ + yytoken = yytranslate_ (yychar); + yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, + &yylloc); + } + + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + while (yystate_stack_.height () != 1) + { + yydestruct_ ("Cleanup: popping", + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); + } + + return yyresult; + } + + // Generate an error message. + std::string + EasyMeshParser::yysyntax_error_ (int yystate, int yytoken) + { + std::string yyres; + // Number of reported tokens (one for the "unexpected", one per + // "expected"). + size_t yycount = 0; + // Its maximum. + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + // Arguments of yyformat. + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yytoken) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is + a consistent state with a default action. There might have + been a previous inconsistent state, consistent state with a + non-default action, or user semantic action that manipulated + yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state + merging (from LALR or IELR) and default reductions corrupt the + expected token list. However, the list is correct for + canonical LR with one exception: it will still contain any + token that will not be accepted due to an error action in a + later state. + */ + if (yytoken != yyempty_) + { + yyarg[yycount++] = yytname_[yytoken]; + int yyn = yypact_[yystate]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + break; + } + else + yyarg[yycount++] = yytname_[yyx]; + } + } + } + + char const* yyformat = 0; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + // Argument number. + size_t yyi = 0; + for (char const* yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += yytnamerr_ (yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + } + + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + const signed char EasyMeshParser::yypact_ninf_ = -45; + const signed char + EasyMeshParser::yypact_[] = + { + 34, -29, 70, -6, -6, -6, -6, -45, -6, -6, + -6, -6, -45, -6, -6, -6, -6, -45, -6, -6, + -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, + -6, -6, -45, 12, 15, 34, 34, 69, -45, -45, + -45, -45, -45, -45, -6, -6, -6, -6, -45, -45, + -45, -45, -45, -45, -45, -45, -45, -45, -45, -45, + -45, -45, -45, -45, -45, -45, -45, -6, -6, -45, + -45, -45, -45, -45, -45, -45, -45, -45, -45, -6, + -6, -45, -45, -45, -45, -21, -45, -45, -45, -45, + -45, -45, -45, -45, -45, -45, -45 + }; + + /* YYDEFACT[S] -- default reduction number in state S. Performed when + YYTABLE doesn't specify something else to do. Zero means the + default is an error. */ + const unsigned char + EasyMeshParser::yydefact_[] = + { + 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, + 0, 0, 34, 0, 0, 0, 0, 35, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 3, 0, 5, 9, 11, + 12, 13, 55, 15, 0, 0, 0, 0, 14, 47, + 17, 16, 19, 23, 26, 29, 20, 24, 27, 30, + 21, 25, 28, 31, 22, 32, 18, 0, 0, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 0, + 0, 46, 1, 2, 4, 0, 10, 56, 48, 49, + 50, 51, 52, 53, 54, 8, 6 + }; + + /* YYPGOTO[NTERM-NUM]. */ + const signed char + EasyMeshParser::yypgoto_[] = + { + -45, -45, -4, -45, -45, -45, -45, -17, -45, -45, + -45, 5, 39, 98, 3, 8, -9, -45, -45, -44 + }; + + /* YYDEFGOTO[NTERM-NUM]. */ + const signed char + EasyMeshParser::yydefgoto_[] = + { + -1, 33, 34, 35, 36, 96, 37, 38, 39, 40, + 41, 45, 46, 47, 67, 68, 69, 80, 81, 49 + }; + + /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF_, syntax error. */ + const signed char EasyMeshParser::yytable_ninf_ = -1; + const unsigned char + EasyMeshParser::yytable_[] = + { + 87, 88, 89, 90, 48, 51, 42, 43, 52, 53, + 44, 55, 82, 56, 57, 83, 59, 95, 60, 61, + 86, 63, 79, 91, 92, 66, 71, 72, 73, 42, + 75, 84, 85, 44, 74, 93, 94, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 77, 78, + 0, 32, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 54, 0, 42, 50, 0, 58, 44, + 0, 0, 0, 62, 0, 0, 64, 65, 0, 0, + 70, 0, 0, 0, 0, 0, 76 + }; + + /* YYCHECK. */ + const signed char + EasyMeshParser::yycheck_[] = + { + 44, 45, 46, 47, 1, 2, 35, 36, 3, 4, + 39, 6, 0, 8, 9, 0, 11, 38, 13, 14, + 37, 16, 31, 67, 68, 20, 23, 24, 25, 35, + 27, 35, 36, 39, 26, 79, 80, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 29, 30, + -1, 37, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 5, -1, 35, 36, -1, 10, 39, + -1, -1, -1, 15, -1, -1, 18, 19, -1, -1, + 22, -1, -1, -1, -1, -1, 28 + }; + + /* STOS_[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ + const unsigned char + EasyMeshParser::yystos_[] = + { + 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 37, 41, 42, 43, 44, 46, 47, 48, + 49, 50, 35, 36, 39, 51, 52, 53, 54, 59, + 36, 54, 51, 51, 53, 51, 51, 51, 53, 51, + 51, 51, 53, 51, 53, 53, 51, 54, 55, 56, + 53, 54, 54, 54, 55, 54, 53, 52, 52, 56, + 57, 58, 0, 0, 42, 42, 47, 59, 59, 59, + 59, 59, 59, 59, 59, 38, 45 + }; + +#if YYDEBUG + /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding + to YYLEX-NUM. */ + const unsigned short int + EasyMeshParser::yytoken_number_[] = + { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 91, 93, 45 + }; +#endif + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ + const unsigned char + EasyMeshParser::yyr1_[] = + { + 0, 40, 41, 42, 42, 43, 43, 44, 45, 46, + 46, 47, 47, 47, 48, 48, 48, 48, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 59 + }; + + /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ + const unsigned char + EasyMeshParser::yyr2_[] = + { + 0, 2, 2, 1, 2, 1, 3, 1, 1, 1, + 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 1, 1, 1, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, + 2, 2, 2, 2, 2, 1, 2 + }; + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a yyntokens_, nonterminals. */ + const char* + const EasyMeshParser::yytname_[] = + { + "T_END", "error", "$undefined", "T_COLOR", "T_BGCOLOR", "T_TRANSLATEX", + "T_ROTATEX", "T_TAPERX", "T_SCALEX", "T_MIRRORX", "T_TRANSLATEY", + "T_ROTATEY", "T_TAPERY", "T_SCALEY", "T_MIRRORY", "T_TRANSLATEZ", + "T_ROTATEZ", "T_TAPERZ", "T_SCALEZ", "T_MIRRORZ", "T_TRANSLATE", + "T_SCALE", "T_CHAMFER", "T_CYLINDER", "T_BOX", "T_SMOOTHCHAMFBOX", + "T_FLATCHAMFBOX", "T_SPHERE", "T_STAR", "T_EXPANDEDSTAR", "T_DISC", + "T_TRIANGLE", "T_QUAD", "T_COG", "T_ERROR", "NUMBER", "COLOR", "'['", + "']'", "'-'", "$accept", "mesh_description", "mesh_expression_list", + "mesh_expression", "mesh_open", "mesh_close", "mesh_command_list", + "mesh_command", "color_command", "transform_command", + "primitive_command", "args1", "args2", "args3", "args4", "args5", + "args6", "args7", "args8", "number", 0 + }; +#endif + +#if YYDEBUG + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ + const EasyMeshParser::rhs_number_type + EasyMeshParser::yyrhs_[] = + { + 41, 0, -1, 42, 0, -1, 43, -1, 43, 42, + -1, 46, -1, 44, 42, 45, -1, 37, -1, 38, + -1, 47, -1, 46, 47, -1, 48, -1, 49, -1, + 50, -1, 3, 54, -1, 3, 36, -1, 4, 54, + -1, 4, 36, -1, 22, 51, -1, 5, 51, -1, + 10, 51, -1, 15, 51, -1, 20, 53, -1, 6, + 51, -1, 11, 51, -1, 16, 51, -1, 7, 53, + -1, 12, 53, -1, 17, 53, -1, 8, 51, -1, + 13, 51, -1, 18, 51, -1, 21, 53, -1, 9, + -1, 14, -1, 19, -1, 23, 56, -1, 24, 53, + -1, 25, 54, -1, 26, 54, -1, 27, 54, -1, + 28, 55, -1, 29, 54, -1, 30, 53, -1, 31, + 52, -1, 32, 52, -1, 33, 58, -1, 59, -1, + 51, 59, -1, 52, 59, -1, 53, 59, -1, 54, + 59, -1, 55, 59, -1, 56, 59, -1, 57, 59, + -1, 35, -1, 39, 59, -1 + }; + + /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ + const unsigned char + EasyMeshParser::yyprhs_[] = + { + 0, 0, 3, 6, 8, 11, 13, 17, 19, 21, + 23, 26, 28, 30, 32, 35, 38, 41, 44, 47, + 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, + 80, 83, 86, 89, 91, 93, 95, 98, 101, 104, + 107, 110, 113, 116, 119, 122, 125, 128, 130, 133, + 136, 139, 142, 145, 148, 151, 153 + }; + + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + const unsigned char + EasyMeshParser::yyrline_[] = + { + 0, 75, 75, 79, 80, 84, 85, 89, 93, 97, + 98, 102, 103, 104, 108, 109, 112, 113, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 131, 132, 133, 134, 135, 136, 140, 143, 144, 146, + 148, 150, 152, 154, 155, 156, 157, 161, 162, 163, + 164, 165, 166, 167, 168, 171, 172 + }; + + // Print the state stack on the debug stream. + void + EasyMeshParser::yystack_print_ () + { + *yycdebug_ << "Stack now"; + for (state_stack_type::const_iterator i = yystate_stack_.begin (); + i != yystate_stack_.end (); ++i) + *yycdebug_ << ' ' << *i; + *yycdebug_ << std::endl; + } + + // Report on the debug stream that the rule \a yyrule is going to be reduced. + void + EasyMeshParser::yy_reduce_print_ (int yyrule) + { + unsigned int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 + << " (line " << yylno << "):" << std::endl; + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + yyrhs_[yyprhs_[yyrule] + yyi], + &(yysemantic_stack_[(yynrhs) - (yyi + 1)]), + &(yylocation_stack_[(yynrhs) - (yyi + 1)])); + } +#endif // YYDEBUG + + /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + EasyMeshParser::token_number_type + EasyMeshParser::yytranslate_ (int t) + { + static + const token_number_type + translate_table[] = + { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 39, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 37, 2, 38, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36 + }; + if ((unsigned int) t <= yyuser_token_number_max_) + return translate_table[t]; + else + return yyundef_token_; + } + + const int EasyMeshParser::yyeof_ = 0; + const int EasyMeshParser::yylast_ = 126; + const int EasyMeshParser::yynnts_ = 20; + const int EasyMeshParser::yyempty_ = -2; + const int EasyMeshParser::yyfinal_ = 82; + const int EasyMeshParser::yyterror_ = 1; + const int EasyMeshParser::yyerrcode_ = 256; + const int EasyMeshParser::yyntokens_ = 40; + + const unsigned int EasyMeshParser::yyuser_token_number_max_ = 291; + const EasyMeshParser::token_number_type EasyMeshParser::yyundef_token_ = 2; + + +} // lol + +/* Line 1136 of lalr1.cc */ +#line 1375 "generated/easymesh-parser.cpp" + + +/* Line 1138 of lalr1.cc */ +#line 175 "easymesh/easymesh-parser.y" + + +void lol::EasyMeshParser::error(const EasyMeshParser::location_type& l, + const std::string& m) +{ + mc.Error(l, m); +} + + diff --git a/src/generated/easymesh-parser.h b/src/generated/easymesh-parser.h new file mode 100644 index 00000000..4a5ab3c0 --- /dev/null +++ b/src/generated/easymesh-parser.h @@ -0,0 +1,319 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Skeleton interface for Bison LALR(1) parsers in C++ + + Copyright (C) 2002-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C++ LALR(1) parser skeleton written by Akim Demaille. */ + +#ifndef PARSER_HEADER_H +# define PARSER_HEADER_H + + + +#include +#include +#include "stack.hh" +#include "location.hh" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +namespace lol { + +/* Line 35 of lalr1.cc */ +#line 68 "generated/easymesh-parser.h" + + /// A Bison parser. + class EasyMeshParser + { + public: + /// Symbol semantic values. +#ifndef YYSTYPE + union semantic_type + { + +/* Line 35 of lalr1.cc */ +#line 36 "easymesh/easymesh-parser.y" + + float fval; + /* Can't use uin32_t here for some reason */ + unsigned u32val; + struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args; + + + +/* Line 35 of lalr1.cc */ +#line 90 "generated/easymesh-parser.h" + }; +#else + typedef YYSTYPE semantic_type; +#endif + /// Symbol locations. + typedef location location_type; + /// Tokens. + struct token + { + /* Tokens. */ + enum yytokentype { + T_END = 0, + T_COLOR = 258, + T_BGCOLOR = 259, + T_TRANSLATEX = 260, + T_ROTATEX = 261, + T_TAPERX = 262, + T_SCALEX = 263, + T_MIRRORX = 264, + T_TRANSLATEY = 265, + T_ROTATEY = 266, + T_TAPERY = 267, + T_SCALEY = 268, + T_MIRRORY = 269, + T_TRANSLATEZ = 270, + T_ROTATEZ = 271, + T_TAPERZ = 272, + T_SCALEZ = 273, + T_MIRRORZ = 274, + T_TRANSLATE = 275, + T_SCALE = 276, + T_CHAMFER = 277, + T_CYLINDER = 278, + T_BOX = 279, + T_SMOOTHCHAMFBOX = 280, + T_FLATCHAMFBOX = 281, + T_SPHERE = 282, + T_STAR = 283, + T_EXPANDEDSTAR = 284, + T_DISC = 285, + T_TRIANGLE = 286, + T_QUAD = 287, + T_COG = 288, + T_ERROR = 289, + NUMBER = 290, + COLOR = 291 + }; + + }; + /// Token type. + typedef token::yytokentype token_type; + + /// Build a parser object. + EasyMeshParser (class EasyMeshCompiler& mc_yyarg); + virtual ~EasyMeshParser (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if YYDEBUG + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + private: + /// Report a syntax error. + /// \param loc where the syntax error is found. + /// \param msg a description of the syntax error. + virtual void error (const location_type& loc, const std::string& msg); + + /// Generate an error message. + /// \param state the state where the error occurred. + /// \param tok the lookahead token. + virtual std::string yysyntax_error_ (int yystate, int tok); + +#if YYDEBUG + /// \brief Report a symbol value on the debug stream. + /// \param yytype The token type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + virtual void yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); + /// \brief Report a symbol on the debug stream. + /// \param yytype The token type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + virtual void yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, + const location_type* yylocationp); +#endif + + + /// State numbers. + typedef int state_type; + /// State stack type. + typedef stack state_stack_type; + /// Semantic value stack type. + typedef stack semantic_stack_type; + /// location stack type. + typedef stack location_stack_type; + + /// The state stack. + state_stack_type yystate_stack_; + /// The semantic value stack. + semantic_stack_type yysemantic_stack_; + /// The location stack. + location_stack_type yylocation_stack_; + + /// Whether the given \c yypact_ value indicates a defaulted state. + /// \param yyvalue the value to check + static bool yy_pact_value_is_default_ (int yyvalue); + + /// Whether the given \c yytable_ value indicates a syntax error. + /// \param yyvalue the value to check + static bool yy_table_value_is_error_ (int yyvalue); + + /// Internal symbol numbers. + typedef unsigned char token_number_type; + /* Tables. */ + /// For a state, the index in \a yytable_ of its portion. + static const signed char yypact_[]; + static const signed char yypact_ninf_; + + /// For a state, default reduction number. + /// Unless\a yytable_ specifies something else to do. + /// Zero means the default is an error. + static const unsigned char yydefact_[]; + + static const signed char yypgoto_[]; + static const signed char yydefgoto_[]; + + /// What to do in a state. + /// \a yytable_[yypact_[s]]: what to do in state \a s. + /// - if positive, shift that token. + /// - if negative, reduce the rule which number is the opposite. + /// - if zero, do what YYDEFACT says. + static const unsigned char yytable_[]; + static const signed char yytable_ninf_; + + static const signed char yycheck_[]; + + /// For a state, its accessing symbol. + static const unsigned char yystos_[]; + + /// For a rule, its LHS. + static const unsigned char yyr1_[]; + /// For a rule, its RHS length. + static const unsigned char yyr2_[]; + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif + + /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *n); + +#if YYDEBUG + /// A type to store symbol numbers and -1. + typedef signed char rhs_number_type; + /// A `-1'-separated list of the rules' RHS. + static const rhs_number_type yyrhs_[]; + /// For each rule, the index of the first RHS symbol in \a yyrhs_. + static const unsigned char yyprhs_[]; + /// For each rule, its source line number. + static const unsigned char yyrline_[]; + /// For each scanner token number, its symbol number. + static const unsigned short int yytoken_number_[]; + /// Report on the debug stream that the rule \a r is going to be reduced. + virtual void yy_reduce_print_ (int r); + /// Print the state stack on the debug stream. + virtual void yystack_print_ (); + + /* Debugging. */ + int yydebug_; + std::ostream* yycdebug_; +#endif + + /// Convert a scanner token number \a t to a symbol number. + token_number_type yytranslate_ (int t); + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// \param yytype The symbol type. + /// \param yyvaluep Its semantic value. + /// \param yylocationp Its location. + inline void yydestruct_ (const char* yymsg, + int yytype, + semantic_type* yyvaluep, + location_type* yylocationp); + + /// Pop \a n symbols the three stacks. + inline void yypop_ (unsigned int n = 1); + + /* Constants. */ + static const int yyeof_; + /* LAST_ -- Last index in TABLE_. */ + static const int yylast_; + static const int yynnts_; + static const int yyempty_; + static const int yyfinal_; + static const int yyterror_; + static const int yyerrcode_; + static const int yyntokens_; + static const unsigned int yyuser_token_number_max_; + static const token_number_type yyundef_token_; + + /* User arguments. */ + class EasyMeshCompiler& mc; + }; + +} // lol + +/* Line 35 of lalr1.cc */ +#line 316 "generated/easymesh-parser.h" + + + +#endif /* ! defined PARSER_HEADER_H */ diff --git a/src/generated/easymesh-scanner.cpp b/src/generated/easymesh-scanner.cpp new file mode 100644 index 00000000..063f7aae --- /dev/null +++ b/src/generated/easymesh-scanner.cpp @@ -0,0 +1,1855 @@ +#line 2 "generated/easymesh-scanner.cpp" + +#line 4 "generated/easymesh-scanner.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + + /* The c++ scanner is a mess. The FlexLexer.h header file relies on the + * following macro. This is required in order to pass the c++-multiple-scanners + * test in the regression suite. We get reports that it breaks inheritance. + * We will address this in a future release of flex, or omit the C++ scanner + * altogether. + */ + #define yyFlexLexer EasyMeshFlexLexer + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ +#include +#include +#include +#include +#include +/* end standard C++ headers. */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + + std::istream* yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +void *EasyMeshalloc (yy_size_t ); +void *EasyMeshrealloc (void *,yy_size_t ); +void EasyMeshfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +#define yytext_ptr yytext + +#include + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 43 +#define YY_END_OF_BUFFER 44 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[70] = + { 0, + 0, 0, 44, 42, 41, 40, 42, 42, 37, 42, + 36, 38, 39, 42, 42, 42, 42, 17, 7, 0, + 0, 36, 36, 0, 22, 21, 28, 0, 0, 30, + 26, 29, 3, 18, 19, 20, 8, 9, 10, 1, + 14, 15, 16, 0, 4, 5, 6, 0, 0, 36, + 31, 27, 0, 0, 0, 2, 11, 12, 13, 32, + 24, 23, 25, 33, 0, 34, 0, 35, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 1, 1, 4, 1, 1, 1, 1, 1, + 1, 1, 5, 3, 6, 7, 1, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 10, 1, 11, 1, 1, 1, 12, 13, 14, 15, + + 16, 17, 18, 19, 1, 1, 1, 1, 20, 1, + 1, 21, 22, 23, 24, 25, 1, 1, 1, 26, + 27, 28, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[29] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, + 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[78] = + { 0, + 0, 0, 94, 95, 95, 95, 0, 22, 24, 85, + 26, 95, 95, 30, 73, 10, 13, 34, 37, 0, + 83, 50, 59, 45, 95, 72, 95, 65, 74, 95, + 55, 95, 95, 95, 95, 95, 95, 95, 95, 74, + 95, 95, 95, 44, 95, 95, 95, 0, 78, 77, + 95, 95, 71, 70, 63, 95, 95, 95, 95, 0, + 95, 95, 95, 0, 0, 0, 0, 95, 95, 79, + 78, 77, 76, 75, 72, 71, 54 + } ; + +static yyconst flex_int16_t yy_def[78] = + { 0, + 69, 1, 69, 69, 69, 69, 70, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 71, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 72, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 73, + 69, 69, 69, 74, 75, 76, 77, 69, 0, 69, + 69, 69, 69, 69, 69, 69, 69 + } ; + +static yyconst flex_int16_t yy_nxt[124] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 4, 12, + 13, 14, 4, 15, 4, 4, 4, 4, 4, 16, + 4, 4, 17, 18, 19, 4, 4, 4, 21, 22, + 21, 22, 21, 22, 24, 34, 35, 36, 37, 38, + 39, 24, 25, 26, 27, 28, 29, 40, 44, 49, + 49, 30, 50, 31, 32, 68, 21, 22, 24, 41, + 42, 43, 45, 46, 47, 24, 23, 24, 54, 57, + 58, 59, 67, 66, 24, 55, 65, 64, 60, 48, + 20, 63, 62, 61, 50, 50, 56, 53, 52, 51, + 23, 33, 23, 69, 3, 69, 69, 69, 69, 69, + + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69 + } ; + +static yyconst flex_int16_t yy_chk[124] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, + 9, 9, 11, 11, 11, 16, 16, 16, 17, 17, + 17, 11, 14, 14, 14, 14, 14, 18, 19, 24, + 24, 14, 24, 14, 14, 77, 22, 22, 22, 18, + 18, 18, 19, 19, 19, 22, 23, 23, 31, 44, + 44, 44, 76, 75, 23, 31, 74, 73, 72, 71, + 70, 55, 54, 53, 50, 49, 40, 29, 28, 26, + 21, 15, 10, 3, 69, 69, 69, 69, 69, 69, + + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 69, 69 + } ; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 "easymesh/easymesh-scanner.l" +#line 2 "easymesh/easymesh-scanner.l" +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// (c) 2009-2012 Cédric Lecacheur +// (c) 2009-2012 Benjamin Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "easymesh/easymesh-compiler.h" + +typedef lol::EasyMeshParser::token token; +typedef lol::EasyMeshParser::token_type token_type; + +#ifndef YY_DECL +# define YY_DECL lol::EasyMeshParser::token_type \ + lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \ + lol::EasyMeshParser::location_type* yylloc) +#endif + +#define yyterminate() return token::T_END +#define YY_NO_UNISTD_H +#define YY_USER_ACTION yylloc->columns(yyleng); +#line 493 "generated/easymesh-scanner.cpp" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +#define ECHO LexerOutput( yytext, yyleng ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ +\ + if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) LexerError( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 +#define YY_DECL int yyFlexLexer::yylex() +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 38 "easymesh/easymesh-scanner.l" + + + + /* reset location at the beginning of yylex() */ + yylloc->step(); + + +#line 606 "generated/easymesh-scanner.cpp" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = & std::cin; + + if ( ! yyout ) + yyout = & std::cout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 70 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 69 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 45 "easymesh/easymesh-scanner.l" +{ return token::T_COLOR; } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 46 "easymesh/easymesh-scanner.l" +{ return token::T_BGCOLOR; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 48 "easymesh/easymesh-scanner.l" +{ return token::T_CHAMFER; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 49 "easymesh/easymesh-scanner.l" +{ return token::T_TRANSLATEX; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 50 "easymesh/easymesh-scanner.l" +{ return token::T_TRANSLATEY; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 51 "easymesh/easymesh-scanner.l" +{ return token::T_TRANSLATEZ; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 52 "easymesh/easymesh-scanner.l" +{ return token::T_TRANSLATE; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 53 "easymesh/easymesh-scanner.l" +{ return token::T_ROTATEX; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 54 "easymesh/easymesh-scanner.l" +{ return token::T_ROTATEY; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 55 "easymesh/easymesh-scanner.l" +{ return token::T_ROTATEZ; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 56 "easymesh/easymesh-scanner.l" +{ return token::T_TAPERX; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 57 "easymesh/easymesh-scanner.l" +{ return token::T_TAPERY; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 58 "easymesh/easymesh-scanner.l" +{ return token::T_TAPERZ; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 59 "easymesh/easymesh-scanner.l" +{ return token::T_SCALEX; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 60 "easymesh/easymesh-scanner.l" +{ return token::T_SCALEY; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 61 "easymesh/easymesh-scanner.l" +{ return token::T_SCALEZ; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 62 "easymesh/easymesh-scanner.l" +{ return token::T_SCALE; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 63 "easymesh/easymesh-scanner.l" +{ return token::T_MIRRORX; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 64 "easymesh/easymesh-scanner.l" +{ return token::T_MIRRORY; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 65 "easymesh/easymesh-scanner.l" +{ return token::T_MIRRORZ; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 67 "easymesh/easymesh-scanner.l" +{ return token::T_CYLINDER; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 68 "easymesh/easymesh-scanner.l" +{ return token::T_BOX; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 69 "easymesh/easymesh-scanner.l" +{ return token::T_SMOOTHCHAMFBOX; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 70 "easymesh/easymesh-scanner.l" +{ return token::T_FLATCHAMFBOX; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 71 "easymesh/easymesh-scanner.l" +{ return token::T_SPHERE; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 72 "easymesh/easymesh-scanner.l" +{ return token::T_STAR; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 73 "easymesh/easymesh-scanner.l" +{ return token::T_EXPANDEDSTAR; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 74 "easymesh/easymesh-scanner.l" +{ return token::T_DISC; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 75 "easymesh/easymesh-scanner.l" +{ return token::T_TRIANGLE; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 76 "easymesh/easymesh-scanner.l" +{ return token::T_QUAD; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 77 "easymesh/easymesh-scanner.l" +{ return token::T_COG; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 79 "easymesh/easymesh-scanner.l" +{ + uint32_t tmp = strtol(yytext + 1, NULL, 16); + yylval->u32val = 0x11000000u * (tmp >> 8) + | 0x00110000u * ((tmp >> 4) & 0xf) + | 0x00001100u * (tmp & 0xf) + | 0x000000ffu; + return token::COLOR; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 86 "easymesh/easymesh-scanner.l" +{ + uint32_t tmp = strtol(yytext + 1, NULL, 16); + yylval->u32val = 0x11000000u * (tmp >> 12) + | 0x00110000u * ((tmp >> 8) & 0xf) + | 0x00001100u * ((tmp >> 4) & 0xf) + | 0x00000011u * (tmp & 0xf); + return token::COLOR; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 93 "easymesh/easymesh-scanner.l" +{ + yylval->u32val = 0xffu + | 0x100u * (uint32_t)strtol(yytext + 1, NULL, 16); + return token::COLOR; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 97 "easymesh/easymesh-scanner.l" +{ + yylval->u32val = (uint32_t)strtol(yytext + 1, NULL, 16); + return token::COLOR; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 100 "easymesh/easymesh-scanner.l" +{ + yylval->fval = atof(yytext); return token::NUMBER; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 102 "easymesh/easymesh-scanner.l" +{ return token_type('-'); } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 103 "easymesh/easymesh-scanner.l" +{ return token_type('['); } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 104 "easymesh/easymesh-scanner.l" +{ return token_type(']'); } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 105 "easymesh/easymesh-scanner.l" +{ /* ignore this */ } + YY_BREAK +case 41: +/* rule 41 can match eol */ +YY_RULE_SETUP +#line 106 "easymesh/easymesh-scanner.l" +{ /* ignore this */ } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 107 "easymesh/easymesh-scanner.l" +{ return token::T_ERROR; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 109 "easymesh/easymesh-scanner.l" +ECHO; + YY_BREAK +#line 919 "generated/easymesh-scanner.cpp" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout ) +{ + yyin = arg_yyin; + yyout = arg_yyout; + yy_c_buf_p = 0; + yy_init = 0; + yy_start = 0; + yy_flex_debug = 0; + yylineno = 1; // this will only get updated if %option yylineno + + yy_did_buffer_switch_on_eof = 0; + + yy_looking_for_trail_begin = 0; + yy_more_flag = 0; + yy_more_len = 0; + yy_more_offset = yy_prev_more_offset = 0; + + yy_start_stack_ptr = yy_start_stack_depth = 0; + yy_start_stack = NULL; + + yy_buffer_stack = 0; + yy_buffer_stack_top = 0; + yy_buffer_stack_max = 0; + + yy_state_buf = 0; + +} + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +yyFlexLexer::~yyFlexLexer() +{ + delete [] yy_state_buf; + EasyMeshfree(yy_start_stack ); + yy_delete_buffer( YY_CURRENT_BUFFER ); + EasyMeshfree(yy_buffer_stack ); +} + +/* The contents of this function are C++ specific, so the () macro is not used. + */ +void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out ) +{ + if ( new_in ) + { + yy_delete_buffer( YY_CURRENT_BUFFER ); + yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); + } + + if ( new_out ) + yyout = new_out; +} + +#ifdef YY_INTERACTIVE +int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) +#else +int yyFlexLexer::LexerInput( char* buf, int max_size ) +#endif +{ + if ( yyin->eof() || yyin->fail() ) + return 0; + +#ifdef YY_INTERACTIVE + yyin->get( buf[0] ); + + if ( yyin->eof() ) + return 0; + + if ( yyin->bad() ) + return -1; + + return 1; + +#else + (void) yyin->read( buf, max_size ); + + if ( yyin->bad() ) + return -1; + else + return yyin->gcount(); +#endif +} + +void yyFlexLexer::LexerOutput( const char* buf, int size ) +{ + (void) yyout->write( buf, size ); +} + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +int yyFlexLexer::yy_get_next_buffer() +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + EasyMeshrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) EasyMeshrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + yy_state_type yyFlexLexer::yy_get_previous_state() +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 70 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 70 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 69); + + return yy_is_jam ? 0 : yy_current_state; +} + + void yyFlexLexer::yyunput( int c, register char* yy_bp) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + + int yyFlexLexer::yyinput() +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyFlexLexer::yyrestart( std::istream* input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + + void yyFlexLexer::yy_load_buffer_state() +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) EasyMeshalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) EasyMeshalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + EasyMeshfree((void *) b->yy_ch_buf ); + + EasyMeshfree((void *) b ); +} + +extern "C" int isatty (int ); + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yyFlexLexer::yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +void yyFlexLexer::yyensure_buffer_stack(void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)EasyMeshalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)EasyMeshrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + + void yyFlexLexer::yy_push_state( int new_state ) +{ + if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) + { + yy_size_t new_size; + + (yy_start_stack_depth) += YY_START_STACK_INCR; + new_size = (yy_start_stack_depth) * sizeof( int ); + + if ( ! (yy_start_stack) ) + (yy_start_stack) = (int *) EasyMeshalloc(new_size ); + + else + (yy_start_stack) = (int *) EasyMeshrealloc((void *) (yy_start_stack),new_size ); + + if ( ! (yy_start_stack) ) + YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); + } + + (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; + + BEGIN(new_state); +} + + void yyFlexLexer::yy_pop_state() +{ + if ( --(yy_start_stack_ptr) < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); +} + + int yyFlexLexer::yy_top_state() +{ + return (yy_start_stack)[(yy_start_stack_ptr) - 1]; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +void yyFlexLexer::LexerError( yyconst char msg[] ) +{ + std::cerr << msg << std::endl; + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *EasyMeshalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *EasyMeshrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void EasyMeshfree (void * ptr ) +{ + free( (char *) ptr ); /* see EasyMeshrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 109 "easymesh/easymesh-scanner.l" + + + +lol::EasyMeshScanner::EasyMeshScanner(char const *command) + : EasyMeshFlexLexer(0, 0), + m_input(command) +{ +} + +lol::EasyMeshScanner::~EasyMeshScanner() +{ +} + +int lol::EasyMeshScanner::LexerInput(char* buf, int max_size) +{ + buf[0] = m_input[0]; + if (buf[0]) + ++m_input; + return buf[0] ? 1 : 0; +} + +#ifdef yylex +#undef yylex +#endif +int EasyMeshFlexLexer::yylex() +{ + std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl; + return 0; +} + +int EasyMeshFlexLexer::yywrap() +{ + return 1; +} + + diff --git a/src/generated/location.hh b/src/generated/location.hh new file mode 100644 index 00000000..76061106 --- /dev/null +++ b/src/generated/location.hh @@ -0,0 +1,164 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Locations for Bison parsers in C++ + + Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/** + ** \file location.hh + ** Define the lol::location class. + */ + +#ifndef BISON_LOCATION_HH +# define BISON_LOCATION_HH + +# include +# include +# include "position.hh" + + +namespace lol { + +/* Line 162 of location.cc */ +#line 50 "generated/location.hh" + + /// Abstract a location. + class location + { + public: + + /// Construct a location. + location () + : begin (), end () + { + } + + + /// Initialization. + inline void initialize (std::string* fn) + { + begin.initialize (fn); + end = begin; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// Reset initial location to final location. + inline void step () + { + begin = end; + } + + /// Extend the current location to the COUNT next columns. + inline void columns (unsigned int count = 1) + { + end += count; + } + + /// Extend the current location to the COUNT next lines. + inline void lines (unsigned int count = 1) + { + end.lines (count); + } + /** \} */ + + + public: + /// Beginning of the located region. + position begin; + /// End of the located region. + position end; + }; + + /// Join two location objects to create a location. + inline const location operator+ (const location& begin, const location& end) + { + location res = begin; + res.end = end.end; + return res; + } + + /// Add two location objects. + inline const location operator+ (const location& begin, unsigned int width) + { + location res = begin; + res.columns (width); + return res; + } + + /// Add and assign a location. + inline location& operator+= (location& res, unsigned int width) + { + res.columns (width); + return res; + } + + /// Compare two location objects. + inline bool + operator== (const location& loc1, const location& loc2) + { + return loc1.begin == loc2.begin && loc1.end == loc2.end; + } + + /// Compare two location objects. + inline bool + operator!= (const location& loc1, const location& loc2) + { + return !(loc1 == loc2); + } + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param loc a reference to the location to redirect + ** + ** Avoid duplicate information. + */ + inline std::ostream& operator<< (std::ostream& ostr, const location& loc) + { + position last = loc.end - 1; + ostr << loc.begin; + if (last.filename + && (!loc.begin.filename + || *loc.begin.filename != *last.filename)) + ostr << '-' << last; + else if (loc.begin.line != last.line) + ostr << '-' << last.line << '.' << last.column; + else if (loc.begin.column != last.column) + ostr << '-' << last.column; + return ostr; + } + + +} // lol + +/* Line 271 of location.cc */ +#line 163 "generated/location.hh" + +#endif // not BISON_LOCATION_HH diff --git a/src/generated/position.hh b/src/generated/position.hh new file mode 100644 index 00000000..5a706fc4 --- /dev/null +++ b/src/generated/position.hh @@ -0,0 +1,161 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Positions for Bison parsers in C++ + + Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/** + ** \file position.hh + ** Define the lol::position class. + */ + +#ifndef BISON_POSITION_HH +# define BISON_POSITION_HH + +# include +# include +# include + + +namespace lol { + +/* Line 37 of location.cc */ +#line 50 "generated/position.hh" + /// Abstract a position. + class position + { + public: + + /// Construct a position. + position () + : filename (0), line (1), column (1) + { + } + + + /// Initialization. + inline void initialize (std::string* fn) + { + filename = fn; + line = 1; + column = 1; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// (line related) Advance to the COUNT next lines. + inline void lines (int count = 1) + { + column = 1; + line += count; + } + + /// (column related) Advance to the COUNT next columns. + inline void columns (int count = 1) + { + column = std::max (1u, column + count); + } + /** \} */ + + public: + /// File name to which this position refers. + std::string* filename; + /// Current line number. + unsigned int line; + /// Current column number. + unsigned int column; + }; + + /// Add and assign a position. + inline const position& + operator+= (position& res, const int width) + { + res.columns (width); + return res; + } + + /// Add two position objects. + inline const position + operator+ (const position& begin, const int width) + { + position res = begin; + return res += width; + } + + /// Add and assign a position. + inline const position& + operator-= (position& res, const int width) + { + return res += -width; + } + + /// Add two position objects. + inline const position + operator- (const position& begin, const int width) + { + return begin + -width; + } + + /// Compare two position objects. + inline bool + operator== (const position& pos1, const position& pos2) + { + return (pos1.line == pos2.line + && pos1.column == pos2.column + && (pos1.filename == pos2.filename + || (pos1.filename && pos2.filename + && *pos1.filename == *pos2.filename))); + } + + /// Compare two position objects. + inline bool + operator!= (const position& pos1, const position& pos2) + { + return !(pos1 == pos2); + } + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param pos a reference to the position to redirect + */ + inline std::ostream& + operator<< (std::ostream& ostr, const position& pos) + { + if (pos.filename) + ostr << *pos.filename << ':'; + return ostr << pos.line << '.' << pos.column; + } + + +} // lol + +/* Line 144 of location.cc */ +#line 161 "generated/position.hh" +#endif // not BISON_POSITION_HH diff --git a/src/generated/stack.hh b/src/generated/stack.hh new file mode 100644 index 00000000..e5d1f9cf --- /dev/null +++ b/src/generated/stack.hh @@ -0,0 +1,135 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Stack handling for Bison parsers in C++ + + Copyright (C) 2002-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef BISON_STACK_HH +# define BISON_STACK_HH + +#include + + +namespace lol { + +/* Line 1149 of lalr1.cc */ +#line 43 "generated/stack.hh" + template > + class stack + { + public: + + // Hide our reversed order. + typedef typename S::reverse_iterator iterator; + typedef typename S::const_reverse_iterator const_iterator; + + stack () : seq_ () + { + } + + stack (unsigned int n) : seq_ (n) + { + } + + inline + T& + operator [] (unsigned int i) + { + return seq_[i]; + } + + inline + const T& + operator [] (unsigned int i) const + { + return seq_[i]; + } + + inline + void + push (const T& t) + { + seq_.push_front (t); + } + + inline + void + pop (unsigned int n = 1) + { + for (; n; --n) + seq_.pop_front (); + } + + inline + unsigned int + height () const + { + return seq_.size (); + } + + inline const_iterator begin () const { return seq_.rbegin (); } + inline const_iterator end () const { return seq_.rend (); } + + private: + + S seq_; + }; + + /// Present a slice of the top of a stack. + template > + class slice + { + public: + + slice (const S& stack, + unsigned int range) : stack_ (stack), + range_ (range) + { + } + + inline + const T& + operator [] (unsigned int i) const + { + return stack_[range_ - i]; + } + + private: + + const S& stack_; + unsigned int range_; + }; + +} // lol + +/* Line 1235 of lalr1.cc */ +#line 133 "generated/stack.hh" + +#endif // not BISON_STACK_HH[]dnl + diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index 3479f139..230af155 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -81,11 +81,15 @@ + + + + @@ -141,11 +145,17 @@ + + + + + + @@ -193,10 +203,15 @@ + + + + + diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index 92680997..b0ebca0f 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -50,6 +50,12 @@ {3592ed6a-59d7-4a6d-be5a-c05cb5dab730} + + {8d536fa6-9ef8-4bdb-b945-48fe4549e8ec} + + + {07117029-d79d-4d59-beec-691b00a97c8f} + @@ -217,6 +223,18 @@ src\gpu + + src\easymesh + + + src\easymesh + + + src\generated + + + src\generated + @@ -405,6 +423,24 @@ src\gpu + + src\generated + + + src\generated + + + src\generated + + + src\easymesh + + + src\easymesh + + + src\generated + @@ -416,5 +452,16 @@ src\gpu + + src\easymesh + + + + + src\easymesh + + + src\easymesh + \ No newline at end of file