diff --git a/src/easymesh/easymesh-scanner.l b/src/easymesh/easymesh-scanner.l index 1c80d9b1..4bbd51a4 100644 --- a/src/easymesh/easymesh-scanner.l +++ b/src/easymesh/easymesh-scanner.l @@ -109,7 +109,7 @@ typedef lol::EasyMeshParser::token_type token_type; (aq|addquad) { return token::T_QUAD; } (acg|addcog) { return token::T_COG; } -%{ /* ======= BASE DATA TYPES ========================================= */ %} +%{ /* ======= BASE COLOR TYPES ========================================= */ %} %{ /* COLOR */ %} #[0-9a-fA-F]{3} { uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); diff --git a/test/generated/location.hh b/test/generated/location.hh new file mode 100644 index 00000000..0b3d1b94 --- /dev/null +++ b/test/generated/location.hh @@ -0,0 +1,164 @@ +/* A Bison parser, made by GNU Bison 2.4.2. */ + +/* Locations for Bison parsers in C++ + + Copyright (C) 2002-2007, 2009-2010 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/test/generated/position.hh b/test/generated/position.hh new file mode 100644 index 00000000..984c21a6 --- /dev/null +++ b/test/generated/position.hh @@ -0,0 +1,161 @@ +/* A Bison parser, made by GNU Bison 2.4.2. */ + +/* Positions for Bison parsers in C++ + + Copyright (C) 2002-2007, 2009-2010 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/test/generated/scenesetup-parser.cpp b/test/generated/scenesetup-parser.cpp new file mode 100644 index 00000000..84e0e433 --- /dev/null +++ b/test/generated/scenesetup-parser.cpp @@ -0,0 +1,1082 @@ +/* A Bison parser, made by GNU Bison 2.4.2. */ + +/* Skeleton implementation for Bison LALR(1) parsers in C++ + + Copyright (C) 2002-2010 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 310 of lalr1.cc */ +#line 1 "scenesetup-parser.y" + +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "../scenesetup.h" + + + +/* Line 310 of lalr1.cc */ +#line 63 "generated/scenesetup-parser.cpp" + + +#include "scenesetup-parser.h" + +/* User implementation prologue. */ + +/* Line 316 of lalr1.cc */ +#line 75 "scenesetup-parser.y" + +#include "../scenesetup-compiler.h" + +#undef yylex +#define yylex uc.m_lexer->lex + +/* HACK: workaround for Bison who insists on using exceptions */ +#define try if (true) +#define catch(...) if (false) +#define throw (void)0 + + +/* Line 316 of lalr1.cc */ +#line 85 "generated/scenesetup-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 + +/* 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 379 of lalr1.cc */ +#line 151 "generated/scenesetup-parser.cpp" +#if YYERROR_VERBOSE + + /* 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 + SceneSetupParser::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; + } + +#endif + + /// Build a parser object. + SceneSetupParser::SceneSetupParser (class SceneSetupCompiler& uc_yyarg) + : +#if YYDEBUG + yydebug_ (false), + yycdebug_ (&std::cerr), +#endif + uc (uc_yyarg) + { + } + + SceneSetupParser::~SceneSetupParser () + { + } + +#if YYDEBUG + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + inline void + SceneSetupParser::yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yyvaluep); + switch (yytype) + { + default: + break; + } + } + + + void + SceneSetupParser::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 + SceneSetupParser::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 + SceneSetupParser::yypop_ (unsigned int n) + { + yystate_stack_.pop (n); + yysemantic_stack_.pop (n); + yylocation_stack_.pop (n); + } + +#if YYDEBUG + std::ostream& + SceneSetupParser::debug_stream () const + { + return *yycdebug_; + } + + void + SceneSetupParser::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + SceneSetupParser::debug_level_type + SceneSetupParser::debug_level () const + { + return yydebug_; + } + + void + SceneSetupParser::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } +#endif + + int + SceneSetupParser::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[2]; + + /// $$. + 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 (yyn == yypact_ninf_) + 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 (yyn == 0 || yyn == yytable_ninf_) + 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 11: + +/* Line 677 of lalr1.cc */ +#line 114 "scenesetup-parser.y" + { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; } + break; + + case 12: + +/* Line 677 of lalr1.cc */ +#line 115 "scenesetup-parser.y" + { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; + uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, (yysemantic_stack_[(2) - (2)].fval))); } + break; + + case 13: + +/* Line 677 of lalr1.cc */ +#line 120 "scenesetup-parser.y" + { if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); } + break; + + case 14: + +/* Line 677 of lalr1.cc */ +#line 122 "scenesetup-parser.y" + { if (uc.m_last_cmd == "ADDLIGHT") + { /* */ } } + break; + + case 15: + +/* Line 677 of lalr1.cc */ +#line 124 "scenesetup-parser.y" + { if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetColor(vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3])); } + break; + + case 16: + +/* Line 677 of lalr1.cc */ +#line 126 "scenesetup-parser.y" + { uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); + ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + vec4 vv = vec4(v) * (1.f / 255.f); + if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetColor(vv); } + break; + + case 17: + +/* Line 677 of lalr1.cc */ +#line 134 "scenesetup-parser.y" + { uc.m_sstp.m_custom_cmd.Push((yysemantic_stack_[(3) - (2)].svval), (yysemantic_stack_[(3) - (3)].sval)); } + break; + + case 18: + +/* Line 677 of lalr1.cc */ +#line 140 "scenesetup-parser.y" + { (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); } + break; + + case 19: + +/* Line 677 of lalr1.cc */ +#line 141 "scenesetup-parser.y" + { (yyval.fval) = -(yysemantic_stack_[(2) - (2)].fval); } + break; + + case 20: + +/* Line 677 of lalr1.cc */ +#line 142 "scenesetup-parser.y" + { (yyval.fval) = (float)(yysemantic_stack_[(1) - (1)].ival); } + break; + + case 21: + +/* Line 677 of lalr1.cc */ +#line 143 "scenesetup-parser.y" + { (yyval.fval) = -(float)(yysemantic_stack_[(2) - (2)].ival); } + break; + + case 22: + +/* Line 677 of lalr1.cc */ +#line 147 "scenesetup-parser.y" + { (yyval.ival) = (yysemantic_stack_[(1) - (1)].ival); } + break; + + case 23: + +/* Line 677 of lalr1.cc */ +#line 148 "scenesetup-parser.y" + { (yyval.ival) = -(yysemantic_stack_[(2) - (2)].ival); } + break; + + case 24: + +/* Line 677 of lalr1.cc */ +#line 149 "scenesetup-parser.y" + { (yyval.ival) = (int)(yysemantic_stack_[(1) - (1)].fval); } + break; + + case 25: + +/* Line 677 of lalr1.cc */ +#line 150 "scenesetup-parser.y" + { (yyval.ival) = -(int)(yysemantic_stack_[(2) - (2)].fval); } + break; + + case 26: + +/* Line 677 of lalr1.cc */ +#line 155 "scenesetup-parser.y" + { (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); } + break; + + case 27: + +/* Line 677 of lalr1.cc */ +#line 156 "scenesetup-parser.y" + { (yyval.vval)[0] = (yysemantic_stack_[(5) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(5) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(5) - (4)].fval); } + break; + + case 28: + +/* Line 677 of lalr1.cc */ +#line 165 "scenesetup-parser.y" + { (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[3] = (yysemantic_stack_[(3) - (2)].fval); } + break; + + case 29: + +/* Line 677 of lalr1.cc */ +#line 166 "scenesetup-parser.y" + { (yyval.vval)[0] = (yysemantic_stack_[(6) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(6) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(6) - (4)].fval); (yyval.vval)[3] = (yysemantic_stack_[(6) - (5)].fval); } + break; + + case 30: + +/* Line 677 of lalr1.cc */ +#line 177 "scenesetup-parser.y" + { (yyval.svval) = (yysemantic_stack_[(1) - (1)].svval); } + break; + + case 31: + +/* Line 677 of lalr1.cc */ +#line 181 "scenesetup-parser.y" + { String t = (yysemantic_stack_[(1) - (1)].sval); + t.Replace('"', ' ', true); + free((yysemantic_stack_[(1) - (1)].sval)); + (yyval.sval) = strdup((const char *)t.C()); } + break; + + case 32: + +/* Line 677 of lalr1.cc */ +#line 185 "scenesetup-parser.y" + { String t = (yysemantic_stack_[(2) - (1)].sval); + t += (yysemantic_stack_[(2) - (2)].sval); + t.Replace('"', ' ', true); + free((yysemantic_stack_[(2) - (1)].sval)); + free((yysemantic_stack_[(2) - (2)].sval)); + (yyval.sval) = strdup((const char *)t.C()); } + break; + + + +/* Line 677 of lalr1.cc */ +#line 612 "generated/scenesetup-parser.cpp" + default: + break; + } + 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: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus_) + { + ++yynerrs_; + error (yylloc, yysyntax_error_ (yystate, yytoken)); + } + + yyerror_range[0] = 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[0] = 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 (yyn != yypact_ninf_) + { + 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[0] = yylocation_stack_[0]; + yydestruct_ ("Error: popping", + yystos_[yystate], + &yysemantic_stack_[0], &yylocation_stack_[0]); + yypop_ (); + yystate = yystate_stack_[0]; + YY_STACK_PRINT (); + } + + yyerror_range[1] = yylloc; + // Using YYLLOC is tempting, but would change the location of + // the lookahead. YYLOC is available though. + YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 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_) + 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 + SceneSetupParser::yysyntax_error_ (int yystate, int tok) + { + std::string res; + YYUSE (yystate); +#if YYERROR_VERBOSE + int yyn = yypact_[yystate]; + if (yypact_ninf_ < yyn && yyn <= yylast_) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + 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_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + ++count; + + // FIXME: This method of building the message is not compatible + // with internationalization. It should work like yacc.c does it. + // That is, first build a string that looks like this: + // "syntax error, unexpected %s or %s or %s" + // Then, invoke YY_ on this string. + // Finally, use the string as a format to output + // yytname_[tok], etc. + // Until this gets fixed, this message appears in English only. + res = "syntax error, unexpected "; + res += yytnamerr_ (yytname_[tok]); + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + { + res += (!count++) ? ", expecting " : " or "; + res += yytnamerr_ (yytname_[x]); + } + } + } + else +#endif + res = YY_("syntax error"); + return res; + } + + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + const signed char SceneSetupParser::yypact_ninf_ = -17; + const signed char + SceneSetupParser::yypact_[] = + { + 28, 7, -12, -12, -5, 1, 24, 25, 28, 28, + -17, -17, -17, -17, -17, -17, 11, -17, 7, -17, + -17, -17, 7, -17, -17, -11, -17, -17, -17, -17, + -17, -17, 11, -17, -17, -7, -3, -11, -17, -17, + -17, -17, 7, -17, 7, -17, 12, 7, -17, 19, + -17 + }; + + /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE + doesn't specify something else to do. Zero means the default is an + error. */ + const unsigned char + SceneSetupParser::yydefact_[] = + { + 0, 11, 0, 0, 0, 0, 0, 0, 3, 5, + 6, 8, 9, 10, 18, 20, 0, 12, 0, 13, + 14, 16, 0, 15, 30, 0, 1, 2, 4, 7, + 18, 20, 0, 19, 21, 0, 0, 31, 17, 19, + 21, 26, 0, 28, 0, 32, 0, 0, 27, 0, + 29 + }; + + /* YYPGOTO[NTERM-NUM]. */ + const signed char + SceneSetupParser::yypgoto_[] = + { + -17, -17, 21, -17, -17, 29, -17, -17, -17, -16, + 8, 36, -17, -17, 4 + }; + + /* YYDEFGOTO[NTERM-NUM]. */ + const signed char + SceneSetupParser::yydefgoto_[] = + { + -1, 6, 7, 8, 9, 10, 11, 12, 13, 17, + 34, 19, 23, 25, 38 + }; + + /* 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 zero, do what YYDEFACT says. */ + const signed char SceneSetupParser::yytable_ninf_ = -1; + const unsigned char + SceneSetupParser::yytable_[] = + { + 33, 37, 35, 14, 15, 18, 36, 14, 15, 16, + 21, 41, 22, 16, 24, 43, 39, 14, 15, 42, + 44, 30, 31, 16, 26, 27, 46, 32, 47, 28, + 48, 49, 1, 2, 3, 4, 5, 50, 29, 20, + 40, 45 + }; + + /* YYCHECK. */ + const unsigned char + SceneSetupParser::yycheck_[] = + { + 16, 12, 18, 10, 11, 17, 22, 10, 11, 16, + 15, 18, 17, 16, 13, 18, 32, 10, 11, 35, + 36, 10, 11, 16, 0, 0, 42, 16, 44, 8, + 18, 47, 4, 5, 6, 7, 8, 18, 9, 3, + 32, 37 + }; + + /* STOS_[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ + const unsigned char + SceneSetupParser::yystos_[] = + { + 0, 4, 5, 6, 7, 8, 20, 21, 22, 23, + 24, 25, 26, 27, 10, 11, 16, 28, 17, 30, + 30, 15, 17, 31, 13, 32, 0, 0, 21, 24, + 10, 11, 16, 28, 29, 28, 28, 12, 33, 28, + 29, 18, 28, 18, 28, 33, 28, 28, 18, 28, + 18 + }; + +#if YYDEBUG + /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding + to YYLEX-NUM. */ + const unsigned short int + SceneSetupParser::yytoken_number_[] = + { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 45, 40, 41 + }; +#endif + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ + const unsigned char + SceneSetupParser::yyr1_[] = + { + 0, 19, 20, 21, 21, 22, 23, 23, 24, 24, + 24, 25, 25, 26, 26, 26, 26, 27, 28, 28, + 28, 28, 29, 29, 29, 29, 30, 30, 31, 31, + 32, 33, 33 + }; + + /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ + const unsigned char + SceneSetupParser::yyr2_[] = + { + 0, 2, 2, 1, 2, 1, 1, 2, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 3, 1, 2, + 1, 2, 1, 2, 1, 2, 3, 5, 3, 6, + 1, 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 SceneSetupParser::yytname_[] = + { + "T_END", "error", "$undefined", "T_COLOR", "T_ADDLIGHT", + "T_OBJPOSITION", "T_OBJLOOKAT", "T_OBJCOLOR", "T_CUSTOMCMD", "T_ERROR", + "F_NUMBER", "I_NUMBER", "STRING", "STRING_VAR", "BOOLEAN", "COLOR", + "'-'", "'('", "')'", "$accept", "sstp_description", + "sstp_expression_list", "sstp_expression", "sstp_command_list", + "sstp_command", "light_command", "setup_command", "custom_command", "fv", + "iv", "v3", "v4", "svv", "sv", 0 + }; +#endif + +#if YYDEBUG + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ + const SceneSetupParser::rhs_number_type + SceneSetupParser::yyrhs_[] = + { + 20, 0, -1, 21, 0, -1, 22, -1, 22, 21, + -1, 23, -1, 24, -1, 23, 24, -1, 25, -1, + 26, -1, 27, -1, 4, -1, 4, 28, -1, 5, + 30, -1, 6, 30, -1, 7, 31, -1, 7, 15, + -1, 8, 32, 33, -1, 10, -1, 16, 28, -1, + 11, -1, 16, 29, -1, 11, -1, 16, 29, -1, + 10, -1, 16, 28, -1, 17, 28, 18, -1, 17, + 28, 28, 28, 18, -1, 17, 28, 18, -1, 17, + 28, 28, 28, 28, 18, -1, 13, -1, 12, -1, + 12, 33, -1 + }; + + /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ + const unsigned char + SceneSetupParser::yyprhs_[] = + { + 0, 0, 3, 6, 8, 11, 13, 15, 18, 20, + 22, 24, 26, 29, 32, 35, 38, 41, 45, 47, + 50, 52, 55, 57, 60, 62, 65, 69, 75, 79, + 86, 88, 90 + }; + + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + const unsigned char + SceneSetupParser::yyrline_[] = + { + 0, 90, 90, 94, 95, 99, 103, 104, 108, 109, + 110, 114, 115, 120, 122, 124, 126, 134, 140, 141, + 142, 143, 147, 148, 149, 150, 155, 156, 165, 166, + 177, 181, 185 + }; + + // Print the state stack on the debug stream. + void + SceneSetupParser::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 + SceneSetupParser::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. */ + SceneSetupParser::token_number_type + SceneSetupParser::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, + 17, 18, 2, 2, 2, 16, 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, 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 + }; + if ((unsigned int) t <= yyuser_token_number_max_) + return translate_table[t]; + else + return yyundef_token_; + } + + const int SceneSetupParser::yyeof_ = 0; + const int SceneSetupParser::yylast_ = 41; + const int SceneSetupParser::yynnts_ = 15; + const int SceneSetupParser::yyempty_ = -2; + const int SceneSetupParser::yyfinal_ = 26; + const int SceneSetupParser::yyterror_ = 1; + const int SceneSetupParser::yyerrcode_ = 256; + const int SceneSetupParser::yyntokens_ = 19; + + const unsigned int SceneSetupParser::yyuser_token_number_max_ = 270; + const SceneSetupParser::token_number_type SceneSetupParser::yyundef_token_ = 2; + + +} // lol + +/* Line 1053 of lalr1.cc */ +#line 1070 "generated/scenesetup-parser.cpp" + + +/* Line 1055 of lalr1.cc */ +#line 193 "scenesetup-parser.y" + + +void lol::SceneSetupParser::error(const SceneSetupParser::location_type& l, + const std::string& m) +{ + uc.Error(l, m); +} + + diff --git a/test/generated/scenesetup-parser.h b/test/generated/scenesetup-parser.h new file mode 100644 index 00000000..447871b8 --- /dev/null +++ b/test/generated/scenesetup-parser.h @@ -0,0 +1,330 @@ +/* A Bison parser, made by GNU Bison 2.4.2. */ + +/* Skeleton interface for Bison LALR(1) parsers in C++ + + Copyright (C) 2002-2010 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" + + +namespace lol { + +/* Line 34 of lalr1.cc */ +#line 49 "generated/scenesetup-parser.h" + class position; + class location; + +} // lol + +/* Line 34 of lalr1.cc */ +#line 56 "generated/scenesetup-parser.h" + +#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 + +/* 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). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ +do { \ + if (N) \ + { \ + (Current).begin = (Rhs)[1].begin; \ + (Current).end = (Rhs)[N].end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = (Rhs)[0].end; \ + } \ +} while (false) +#endif + + +namespace lol { + +/* Line 34 of lalr1.cc */ +#line 101 "generated/scenesetup-parser.h" + + /// A Bison parser. + class SceneSetupParser + { + public: + /// Symbol semantic values. +#ifndef YYSTYPE + union semantic_type + { + +/* Line 34 of lalr1.cc */ +#line 33 "scenesetup-parser.y" + + float fval; + int ival; + bool bval; + float vval[4]; + int ivval[4]; + char* sval; + char* svval; + /* Can't use uin32_t here for some reason */ + unsigned u32val; + + + +/* Line 34 of lalr1.cc */ +#line 128 "generated/scenesetup-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_ADDLIGHT = 259, + T_OBJPOSITION = 260, + T_OBJLOOKAT = 261, + T_OBJCOLOR = 262, + T_CUSTOMCMD = 263, + T_ERROR = 264, + F_NUMBER = 265, + I_NUMBER = 266, + STRING = 267, + STRING_VAR = 268, + BOOLEAN = 269, + COLOR = 270 + }; + + }; + /// Token type. + typedef token::yytokentype token_type; + + /// Build a parser object. + SceneSetupParser (class SceneSetupCompiler& uc_yyarg); + virtual ~SceneSetupParser (); + + /// 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_; + + /// 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 rule to reduce. + /// 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 unsigned 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 + +#if YYERROR_VERBOSE + /// Convert the symbol name \a n to a form suitable for a diagnostic. + virtual std::string yytnamerr_ (const char *n); +#endif + +#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 SceneSetupCompiler& uc; + }; + +} // lol + +/* Line 34 of lalr1.cc */ +#line 327 "generated/scenesetup-parser.h" + + + +#endif /* ! defined PARSER_HEADER_H */ diff --git a/test/generated/scenesetup-parser.output b/test/generated/scenesetup-parser.output new file mode 100644 index 00000000..663e5e09 --- /dev/null +++ b/test/generated/scenesetup-parser.output @@ -0,0 +1,700 @@ +Nonterminals useless in grammar + + iv3 + bv + + +Terminals unused in grammar + + T_COLOR + T_ERROR + BOOLEAN + + +Rules useless in grammar + + 32 iv3: '(' iv ')' + 33 | '(' iv iv iv ')' + + 34 bv: BOOLEAN + 35 | I_NUMBER + 36 | F_NUMBER + + +Rules useless in parser due to conflicts + + 21 iv: I_NUMBER + 22 | '-' iv + 23 | F_NUMBER + 24 | '-' fv + + +State 9 conflicts: 5 shift/reduce +State 30 conflicts: 10 reduce/reduce +State 31 conflicts: 10 reduce/reduce +State 39 conflicts: 10 reduce/reduce +State 40 conflicts: 10 reduce/reduce + + +Grammar + + 0 $accept: sstp_description T_END + + 1 sstp_description: sstp_expression_list T_END + + 2 sstp_expression_list: sstp_expression + 3 | sstp_expression sstp_expression_list + + 4 sstp_expression: sstp_command_list + + 5 sstp_command_list: sstp_command + 6 | sstp_command_list sstp_command + + 7 sstp_command: light_command + 8 | setup_command + 9 | custom_command + + 10 light_command: T_ADDLIGHT + 11 | T_ADDLIGHT fv + + 12 setup_command: T_OBJPOSITION v3 + 13 | T_OBJLOOKAT v3 + 14 | T_OBJCOLOR v4 + 15 | T_OBJCOLOR COLOR + + 16 custom_command: T_CUSTOMCMD svv sv + + 17 fv: F_NUMBER + 18 | '-' fv + 19 | I_NUMBER + 20 | '-' iv + + 21 iv: I_NUMBER + 22 | '-' iv + 23 | F_NUMBER + 24 | '-' fv + + 25 v3: '(' fv ')' + 26 | '(' fv fv fv ')' + + 27 v4: '(' fv ')' + 28 | '(' fv fv fv fv ')' + + 29 svv: STRING_VAR + + 30 sv: STRING + 31 | STRING sv + + +Terminals, with rules where they appear + +T_END (0) 0 1 +'(' (40) 25 26 27 28 +')' (41) 25 26 27 28 +'-' (45) 18 20 22 24 +error (256) +T_COLOR (258) +T_ADDLIGHT (259) 10 11 +T_OBJPOSITION (260) 12 +T_OBJLOOKAT (261) 13 +T_OBJCOLOR (262) 14 15 +T_CUSTOMCMD (263) 16 +T_ERROR (264) +F_NUMBER (265) 17 23 +I_NUMBER (266) 19 21 +STRING (267) 30 31 +STRING_VAR (268) 29 +BOOLEAN (269) +COLOR (270) 15 + + +Nonterminals, with rules where they appear + +$accept (19) + on left: 0 +sstp_description (20) + on left: 1, on right: 0 +sstp_expression_list (21) + on left: 2 3, on right: 1 3 +sstp_expression (22) + on left: 4, on right: 2 3 +sstp_command_list (23) + on left: 5 6, on right: 4 6 +sstp_command (24) + on left: 7 8 9, on right: 5 6 +light_command (25) + on left: 10 11, on right: 7 +setup_command (26) + on left: 12 13 14 15, on right: 8 +custom_command (27) + on left: 16, on right: 9 +fv (28) + on left: 17 18 19 20, on right: 11 18 24 25 26 27 28 +iv (29) + on left: 21 22 23 24, on right: 20 22 +v3 (30) + on left: 25 26, on right: 12 13 +v4 (31) + on left: 27 28, on right: 14 +svv (32) + on left: 29, on right: 16 +sv (33) + on left: 30 31, on right: 16 31 + + +state 0 + + 0 $accept: . sstp_description T_END + + T_ADDLIGHT shift, and go to state 1 + T_OBJPOSITION shift, and go to state 2 + T_OBJLOOKAT shift, and go to state 3 + T_OBJCOLOR shift, and go to state 4 + T_CUSTOMCMD shift, and go to state 5 + + sstp_description go to state 6 + sstp_expression_list go to state 7 + sstp_expression go to state 8 + sstp_command_list go to state 9 + sstp_command go to state 10 + light_command go to state 11 + setup_command go to state 12 + custom_command go to state 13 + + +state 1 + + 10 light_command: T_ADDLIGHT . + 11 | T_ADDLIGHT . fv + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + $default reduce using rule 10 (light_command) + + fv go to state 17 + + +state 2 + + 12 setup_command: T_OBJPOSITION . v3 + + '(' shift, and go to state 18 + + v3 go to state 19 + + +state 3 + + 13 setup_command: T_OBJLOOKAT . v3 + + '(' shift, and go to state 18 + + v3 go to state 20 + + +state 4 + + 14 setup_command: T_OBJCOLOR . v4 + 15 | T_OBJCOLOR . COLOR + + COLOR shift, and go to state 21 + '(' shift, and go to state 22 + + v4 go to state 23 + + +state 5 + + 16 custom_command: T_CUSTOMCMD . svv sv + + STRING_VAR shift, and go to state 24 + + svv go to state 25 + + +state 6 + + 0 $accept: sstp_description . T_END + + T_END shift, and go to state 26 + + +state 7 + + 1 sstp_description: sstp_expression_list . T_END + + T_END shift, and go to state 27 + + +state 8 + + 2 sstp_expression_list: sstp_expression . + 3 | sstp_expression . sstp_expression_list + + T_ADDLIGHT shift, and go to state 1 + T_OBJPOSITION shift, and go to state 2 + T_OBJLOOKAT shift, and go to state 3 + T_OBJCOLOR shift, and go to state 4 + T_CUSTOMCMD shift, and go to state 5 + + $default reduce using rule 2 (sstp_expression_list) + + sstp_expression_list go to state 28 + sstp_expression go to state 8 + sstp_command_list go to state 9 + sstp_command go to state 10 + light_command go to state 11 + setup_command go to state 12 + custom_command go to state 13 + + +state 9 + + 4 sstp_expression: sstp_command_list . + 6 sstp_command_list: sstp_command_list . sstp_command + + T_ADDLIGHT shift, and go to state 1 + T_OBJPOSITION shift, and go to state 2 + T_OBJLOOKAT shift, and go to state 3 + T_OBJCOLOR shift, and go to state 4 + T_CUSTOMCMD shift, and go to state 5 + + T_ADDLIGHT [reduce using rule 4 (sstp_expression)] + T_OBJPOSITION [reduce using rule 4 (sstp_expression)] + T_OBJLOOKAT [reduce using rule 4 (sstp_expression)] + T_OBJCOLOR [reduce using rule 4 (sstp_expression)] + T_CUSTOMCMD [reduce using rule 4 (sstp_expression)] + $default reduce using rule 4 (sstp_expression) + + sstp_command go to state 29 + light_command go to state 11 + setup_command go to state 12 + custom_command go to state 13 + + +state 10 + + 5 sstp_command_list: sstp_command . + + $default reduce using rule 5 (sstp_command_list) + + +state 11 + + 7 sstp_command: light_command . + + $default reduce using rule 7 (sstp_command) + + +state 12 + + 8 sstp_command: setup_command . + + $default reduce using rule 8 (sstp_command) + + +state 13 + + 9 sstp_command: custom_command . + + $default reduce using rule 9 (sstp_command) + + +state 14 + + 17 fv: F_NUMBER . + + $default reduce using rule 17 (fv) + + +state 15 + + 19 fv: I_NUMBER . + + $default reduce using rule 19 (fv) + + +state 16 + + 18 fv: '-' . fv + 20 | '-' . iv + + F_NUMBER shift, and go to state 30 + I_NUMBER shift, and go to state 31 + '-' shift, and go to state 32 + + fv go to state 33 + iv go to state 34 + + +state 17 + + 11 light_command: T_ADDLIGHT fv . + + $default reduce using rule 11 (light_command) + + +state 18 + + 25 v3: '(' . fv ')' + 26 | '(' . fv fv fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + fv go to state 35 + + +state 19 + + 12 setup_command: T_OBJPOSITION v3 . + + $default reduce using rule 12 (setup_command) + + +state 20 + + 13 setup_command: T_OBJLOOKAT v3 . + + $default reduce using rule 13 (setup_command) + + +state 21 + + 15 setup_command: T_OBJCOLOR COLOR . + + $default reduce using rule 15 (setup_command) + + +state 22 + + 27 v4: '(' . fv ')' + 28 | '(' . fv fv fv fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + fv go to state 36 + + +state 23 + + 14 setup_command: T_OBJCOLOR v4 . + + $default reduce using rule 14 (setup_command) + + +state 24 + + 29 svv: STRING_VAR . + + $default reduce using rule 29 (svv) + + +state 25 + + 16 custom_command: T_CUSTOMCMD svv . sv + + STRING shift, and go to state 37 + + sv go to state 38 + + +state 26 + + 0 $accept: sstp_description T_END . + + $default accept + + +state 27 + + 1 sstp_description: sstp_expression_list T_END . + + $default reduce using rule 1 (sstp_description) + + +state 28 + + 3 sstp_expression_list: sstp_expression sstp_expression_list . + + $default reduce using rule 3 (sstp_expression_list) + + +state 29 + + 6 sstp_command_list: sstp_command_list sstp_command . + + $default reduce using rule 6 (sstp_command_list) + + +state 30 + + 17 fv: F_NUMBER . + 23 iv: F_NUMBER . + + T_END reduce using rule 17 (fv) + T_END [reduce using rule 23 (iv)] + T_ADDLIGHT reduce using rule 17 (fv) + T_ADDLIGHT [reduce using rule 23 (iv)] + T_OBJPOSITION reduce using rule 17 (fv) + T_OBJPOSITION [reduce using rule 23 (iv)] + T_OBJLOOKAT reduce using rule 17 (fv) + T_OBJLOOKAT [reduce using rule 23 (iv)] + T_OBJCOLOR reduce using rule 17 (fv) + T_OBJCOLOR [reduce using rule 23 (iv)] + T_CUSTOMCMD reduce using rule 17 (fv) + T_CUSTOMCMD [reduce using rule 23 (iv)] + F_NUMBER reduce using rule 17 (fv) + F_NUMBER [reduce using rule 23 (iv)] + I_NUMBER reduce using rule 17 (fv) + I_NUMBER [reduce using rule 23 (iv)] + '-' reduce using rule 17 (fv) + '-' [reduce using rule 23 (iv)] + ')' reduce using rule 17 (fv) + ')' [reduce using rule 23 (iv)] + $default reduce using rule 17 (fv) + + +state 31 + + 19 fv: I_NUMBER . + 21 iv: I_NUMBER . + + T_END reduce using rule 19 (fv) + T_END [reduce using rule 21 (iv)] + T_ADDLIGHT reduce using rule 19 (fv) + T_ADDLIGHT [reduce using rule 21 (iv)] + T_OBJPOSITION reduce using rule 19 (fv) + T_OBJPOSITION [reduce using rule 21 (iv)] + T_OBJLOOKAT reduce using rule 19 (fv) + T_OBJLOOKAT [reduce using rule 21 (iv)] + T_OBJCOLOR reduce using rule 19 (fv) + T_OBJCOLOR [reduce using rule 21 (iv)] + T_CUSTOMCMD reduce using rule 19 (fv) + T_CUSTOMCMD [reduce using rule 21 (iv)] + F_NUMBER reduce using rule 19 (fv) + F_NUMBER [reduce using rule 21 (iv)] + I_NUMBER reduce using rule 19 (fv) + I_NUMBER [reduce using rule 21 (iv)] + '-' reduce using rule 19 (fv) + '-' [reduce using rule 21 (iv)] + ')' reduce using rule 19 (fv) + ')' [reduce using rule 21 (iv)] + $default reduce using rule 19 (fv) + + +state 32 + + 18 fv: '-' . fv + 20 | '-' . iv + 22 iv: '-' . iv + 24 | '-' . fv + + F_NUMBER shift, and go to state 30 + I_NUMBER shift, and go to state 31 + '-' shift, and go to state 32 + + fv go to state 39 + iv go to state 40 + + +state 33 + + 18 fv: '-' fv . + + $default reduce using rule 18 (fv) + + +state 34 + + 20 fv: '-' iv . + + $default reduce using rule 20 (fv) + + +state 35 + + 25 v3: '(' fv . ')' + 26 | '(' fv . fv fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + ')' shift, and go to state 41 + + fv go to state 42 + + +state 36 + + 27 v4: '(' fv . ')' + 28 | '(' fv . fv fv fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + ')' shift, and go to state 43 + + fv go to state 44 + + +state 37 + + 30 sv: STRING . + 31 | STRING . sv + + STRING shift, and go to state 37 + + $default reduce using rule 30 (sv) + + sv go to state 45 + + +state 38 + + 16 custom_command: T_CUSTOMCMD svv sv . + + $default reduce using rule 16 (custom_command) + + +state 39 + + 18 fv: '-' fv . + 24 iv: '-' fv . + + T_END reduce using rule 18 (fv) + T_END [reduce using rule 24 (iv)] + T_ADDLIGHT reduce using rule 18 (fv) + T_ADDLIGHT [reduce using rule 24 (iv)] + T_OBJPOSITION reduce using rule 18 (fv) + T_OBJPOSITION [reduce using rule 24 (iv)] + T_OBJLOOKAT reduce using rule 18 (fv) + T_OBJLOOKAT [reduce using rule 24 (iv)] + T_OBJCOLOR reduce using rule 18 (fv) + T_OBJCOLOR [reduce using rule 24 (iv)] + T_CUSTOMCMD reduce using rule 18 (fv) + T_CUSTOMCMD [reduce using rule 24 (iv)] + F_NUMBER reduce using rule 18 (fv) + F_NUMBER [reduce using rule 24 (iv)] + I_NUMBER reduce using rule 18 (fv) + I_NUMBER [reduce using rule 24 (iv)] + '-' reduce using rule 18 (fv) + '-' [reduce using rule 24 (iv)] + ')' reduce using rule 18 (fv) + ')' [reduce using rule 24 (iv)] + $default reduce using rule 18 (fv) + + +state 40 + + 20 fv: '-' iv . + 22 iv: '-' iv . + + T_END reduce using rule 20 (fv) + T_END [reduce using rule 22 (iv)] + T_ADDLIGHT reduce using rule 20 (fv) + T_ADDLIGHT [reduce using rule 22 (iv)] + T_OBJPOSITION reduce using rule 20 (fv) + T_OBJPOSITION [reduce using rule 22 (iv)] + T_OBJLOOKAT reduce using rule 20 (fv) + T_OBJLOOKAT [reduce using rule 22 (iv)] + T_OBJCOLOR reduce using rule 20 (fv) + T_OBJCOLOR [reduce using rule 22 (iv)] + T_CUSTOMCMD reduce using rule 20 (fv) + T_CUSTOMCMD [reduce using rule 22 (iv)] + F_NUMBER reduce using rule 20 (fv) + F_NUMBER [reduce using rule 22 (iv)] + I_NUMBER reduce using rule 20 (fv) + I_NUMBER [reduce using rule 22 (iv)] + '-' reduce using rule 20 (fv) + '-' [reduce using rule 22 (iv)] + ')' reduce using rule 20 (fv) + ')' [reduce using rule 22 (iv)] + $default reduce using rule 20 (fv) + + +state 41 + + 25 v3: '(' fv ')' . + + $default reduce using rule 25 (v3) + + +state 42 + + 26 v3: '(' fv fv . fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + fv go to state 46 + + +state 43 + + 27 v4: '(' fv ')' . + + $default reduce using rule 27 (v4) + + +state 44 + + 28 v4: '(' fv fv . fv fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + fv go to state 47 + + +state 45 + + 31 sv: STRING sv . + + $default reduce using rule 31 (sv) + + +state 46 + + 26 v3: '(' fv fv fv . ')' + + ')' shift, and go to state 48 + + +state 47 + + 28 v4: '(' fv fv fv . fv ')' + + F_NUMBER shift, and go to state 14 + I_NUMBER shift, and go to state 15 + '-' shift, and go to state 16 + + fv go to state 49 + + +state 48 + + 26 v3: '(' fv fv fv ')' . + + $default reduce using rule 26 (v3) + + +state 49 + + 28 v4: '(' fv fv fv fv . ')' + + ')' shift, and go to state 50 + + +state 50 + + 28 v4: '(' fv fv fv fv ')' . + + $default reduce using rule 28 (v4) diff --git a/test/generated/scenesetup-scanner.cpp b/test/generated/scenesetup-scanner.cpp new file mode 100644 index 00000000..e5b6b99f --- /dev/null +++ b/test/generated/scenesetup-scanner.cpp @@ -0,0 +1,1787 @@ +#line 2 "generated/scenesetup-scanner.cpp" + +#line 4 "generated/scenesetup-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 SceneSetupFlexLexer + +/* 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 *SceneSetupalloc (yy_size_t ); +void *SceneSetuprealloc (void *,yy_size_t ); +void SceneSetupfree (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 23 +#define YY_END_OF_BUFFER 24 +/* 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[79] = + { 0, + 0, 0, 24, 22, 21, 20, 22, 22, 18, 19, + 22, 17, 22, 22, 13, 22, 22, 22, 22, 22, + 22, 22, 0, 14, 0, 0, 13, 12, 0, 15, + 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, + 16, 15, 15, 15, 15, 15, 15, 15, 6, 0, + 12, 15, 15, 15, 15, 15, 15, 10, 7, 15, + 4, 15, 11, 15, 15, 0, 15, 5, 3, 15, + 8, 15, 15, 0, 1, 2, 9, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 1, 5, 6, 1, 1, 1, 1, 7, + 8, 1, 9, 4, 10, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 1, 1, 1, + 1, 1, 1, 1, 14, 14, 14, 14, 15, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 1, 1, 1, 1, 17, 1, 18, 14, 19, 20, + + 21, 22, 23, 24, 25, 16, 26, 27, 28, 29, + 30, 31, 16, 32, 33, 34, 35, 16, 16, 16, + 16, 16, 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[36] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 3, 4, 4, 2, 2, 4, 4, 4, + 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2 + } ; + +static yyconst flex_int16_t yy_base[90] = + { 0, + 0, 0, 122, 123, 123, 123, 116, 0, 123, 123, + 25, 26, 107, 107, 29, 0, 98, 11, 99, 86, + 85, 82, 108, 123, 0, 99, 32, 34, 48, 0, + 91, 83, 76, 81, 77, 73, 70, 0, 43, 55, + 123, 77, 73, 68, 68, 74, 74, 77, 0, 84, + 83, 70, 62, 63, 71, 73, 56, 0, 0, 66, + 0, 60, 0, 53, 61, 0, 42, 0, 0, 24, + 0, 14, 15, 0, 0, 0, 123, 123, 58, 60, + 63, 65, 69, 71, 73, 75, 77, 79, 81 + } ; + +static yyconst flex_int16_t yy_def[90] = + { 0, + 78, 1, 78, 78, 78, 78, 79, 80, 78, 78, + 78, 78, 78, 78, 78, 81, 81, 81, 81, 81, + 81, 81, 79, 78, 82, 78, 78, 78, 83, 81, + 81, 81, 81, 81, 81, 81, 81, 84, 78, 83, + 78, 81, 81, 81, 81, 81, 81, 81, 85, 78, + 78, 81, 81, 81, 81, 81, 81, 81, 86, 81, + 81, 81, 81, 81, 81, 87, 81, 81, 81, 81, + 88, 81, 81, 89, 81, 81, 78, 0, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78 + } ; + +static yyconst flex_int16_t yy_nxt[159] = + { 0, + 4, 5, 4, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 16, 16, 4, 17, 18, 16, + 16, 19, 16, 16, 16, 16, 20, 16, 16, 16, + 21, 16, 16, 22, 16, 26, 26, 27, 27, 26, + 32, 27, 26, 76, 27, 33, 28, 75, 39, 41, + 41, 50, 50, 73, 39, 51, 41, 41, 23, 23, + 23, 23, 25, 25, 30, 72, 30, 38, 38, 40, + 40, 40, 40, 49, 49, 59, 59, 66, 66, 71, + 71, 74, 74, 77, 77, 70, 69, 68, 67, 65, + 64, 63, 62, 61, 60, 51, 51, 58, 57, 56, + + 55, 54, 53, 52, 48, 47, 46, 45, 44, 43, + 42, 28, 24, 37, 36, 35, 34, 31, 29, 28, + 24, 78, 3, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78 + } ; + +static yyconst flex_int16_t yy_chk[159] = + { 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, 1, 1, + 1, 1, 1, 1, 1, 11, 12, 11, 12, 15, + 18, 15, 27, 73, 27, 18, 28, 72, 28, 29, + 29, 39, 39, 70, 28, 39, 40, 40, 79, 79, + 79, 79, 80, 80, 81, 67, 81, 82, 82, 83, + 83, 83, 83, 84, 84, 85, 85, 86, 86, 87, + 87, 88, 88, 89, 89, 65, 64, 62, 60, 57, + 56, 55, 54, 53, 52, 51, 50, 48, 47, 46, + + 45, 44, 43, 42, 37, 36, 35, 34, 33, 32, + 31, 26, 23, 22, 21, 20, 19, 17, 14, 13, + 7, 3, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78 + } ; + +/* 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 "scenesetup-scanner.l" +#line 2 "scenesetup-scanner.l" +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include +using std::exit; +using std::malloc; +using std::realloc; +using std::free; + +#include "core.h" +#include "../scenesetup.h" +#include "../scenesetup-compiler.h" + +typedef lol::SceneSetupParser::token token; +typedef lol::SceneSetupParser::token_type token_type; + +#ifndef YY_DECL +# define YY_DECL lol::SceneSetupParser::token_type \ + lol::SceneSetupScanner::lex(lol::SceneSetupParser::semantic_type* yylval, \ + lol::SceneSetupParser::location_type* yylloc) +#endif + +#define yyterminate() return token::T_END +#define YY_NO_UNISTD_H +#define YY_USER_ACTION yylloc->columns(yyleng); +#line 509 "generated/scenesetup-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 44 "scenesetup-scanner.l" + + + /* reset location at the beginning of yylex() */ + yylloc->step(); + + +#line 621 "generated/scenesetup-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 >= 79 ) + 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 != 78 ); + 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 50 "scenesetup-scanner.l" +{ return token::T_ADDLIGHT; } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 51 "scenesetup-scanner.l" +{ return token::T_OBJPOSITION; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 52 "scenesetup-scanner.l" +{ return token::T_OBJLOOKAT; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 53 "scenesetup-scanner.l" +{ return token::T_OBJCOLOR; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 55 "scenesetup-scanner.l" +{ return token::T_CUSTOMCMD; } + YY_BREAK + /* ======= BASE COLOR TYPES ========================================= */ + /* COLOR */ +case 6: +YY_RULE_SETUP +#line 59 "scenesetup-scanner.l" +{ + uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); + yylval->u32val = 0x11000000u * (tmp >> 8) + | 0x00110000u * ((tmp >> 4) & 0xf) + | 0x00001100u * (tmp & 0xf) + | 0x000000ffu; + return token::COLOR; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 66 "scenesetup-scanner.l" +{ + uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); + yylval->u32val = 0x11000000u * (tmp >> 12) + | 0x00110000u * ((tmp >> 8) & 0xf) + | 0x00001100u * ((tmp >> 4) & 0xf) + | 0x00000011u * (tmp & 0xf); + return token::COLOR; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 73 "scenesetup-scanner.l" +{ + yylval->u32val = 0xffu + | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16); + return token::COLOR; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 77 "scenesetup-scanner.l" +{ + yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16); + return token::COLOR; } + YY_BREAK + /* ======= BASE DATA TYPES ========================================= */ + /* BOOL */ +case 10: +YY_RULE_SETUP +#line 83 "scenesetup-scanner.l" +{ yylval->bval = true; return token::BOOLEAN; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 84 "scenesetup-scanner.l" +{ yylval->bval = false; return token::BOOLEAN; } + YY_BREAK + /* FLOAT */ +case 12: +YY_RULE_SETUP +#line 86 "scenesetup-scanner.l" +{ + yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; } + YY_BREAK + /* INT */ +case 13: +YY_RULE_SETUP +#line 89 "scenesetup-scanner.l" +{ + yylval->ival = std::atoi(yytext); return token::I_NUMBER; } + YY_BREAK + /* STRING */ +case 14: +/* rule 14 can match eol */ +YY_RULE_SETUP +#line 92 "scenesetup-scanner.l" +{ + yylval->sval = strdup(yytext); return token::STRING; } + YY_BREAK + /* STRING VAR */ +case 15: +YY_RULE_SETUP +#line 95 "scenesetup-scanner.l" +{ + yylval->svval = strdup(yytext); return token::STRING_VAR; } + YY_BREAK + /* ======= COMMENTS ======= */ +case 16: +/* rule 16 can match eol */ +YY_RULE_SETUP +#line 99 "scenesetup-scanner.l" +{ /* ignore this */ } + YY_BREAK + /* Semantics tokens */ +case 17: +YY_RULE_SETUP +#line 102 "scenesetup-scanner.l" +{ return token_type('-'); } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 103 "scenesetup-scanner.l" +{ return token_type('('); } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 104 "scenesetup-scanner.l" +{ return token_type(')'); } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 105 "scenesetup-scanner.l" +{ /* ignore this */ } + YY_BREAK +case 21: +/* rule 21 can match eol */ +YY_RULE_SETUP +#line 106 "scenesetup-scanner.l" +{ /* ignore this */ } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 107 "scenesetup-scanner.l" +{ return token::T_ERROR; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 109 "scenesetup-scanner.l" +ECHO; + YY_BREAK +#line 849 "generated/scenesetup-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; + SceneSetupfree(yy_start_stack ); + yy_delete_buffer( YY_CURRENT_BUFFER ); + SceneSetupfree(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. */ + SceneSetuprealloc((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 *) SceneSetuprealloc((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 >= 79 ) + 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 >= 79 ) + 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 == 78); + + 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) SceneSetupalloc(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 *) SceneSetupalloc(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 ) + SceneSetupfree((void *) b->yy_ch_buf ); + + SceneSetupfree((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**)SceneSetupalloc + (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**)SceneSetuprealloc + ((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 *) SceneSetupalloc(new_size ); + + else + (yy_start_stack) = (int *) SceneSetuprealloc((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 *SceneSetupalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *SceneSetuprealloc (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 SceneSetupfree (void * ptr ) +{ + free( (char *) ptr ); /* see SceneSetuprealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 109 "scenesetup-scanner.l" + + + +lol::SceneSetupScanner::SceneSetupScanner(char const *command) + : SceneSetupFlexLexer(0, 0), + m_input(command) +{ +} + +lol::SceneSetupScanner::~SceneSetupScanner() +{ +} + +int lol::SceneSetupScanner::LexerInput(char* buf, int max_size) +{ + (void)max_size; /* unused for now */ + + buf[0] = m_input[0]; + if (buf[0]) + ++m_input; + return buf[0] ? 1 : 0; +} + +#ifdef yylex +#undef yylex +#endif +int SceneSetupFlexLexer::yylex() +{ + std::cerr << "in SceneSetupFlexLexer::yylex() !" << std::endl; + return 0; +} + +int SceneSetupFlexLexer::yywrap() +{ + return 1; +} + + diff --git a/test/generated/stack.hh b/test/generated/stack.hh new file mode 100644 index 00000000..cf73da80 --- /dev/null +++ b/test/generated/stack.hh @@ -0,0 +1,135 @@ +/* A Bison parser, made by GNU Bison 2.4.2. */ + +/* Stack handling for Bison parsers in C++ + + Copyright (C) 2002-2010 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 1066 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 1152 of lalr1.cc */ +#line 133 "generated/stack.hh" + +#endif // not BISON_STACK_HH[]dnl + diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 1fa869e4..8f1c0b51 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -17,6 +17,7 @@ #include /* for FLT_MAX */ #include "core.h" +#include "scenesetup.h" using namespace std; using namespace lol; @@ -129,9 +130,12 @@ public: { if (m_camera) g_scene->PopCamera(m_camera); - for (int i = 0; i < m_lights.Count(); ++i) - Ticker::Unref(m_lights[i]); + if (m_ssetup) + delete(m_ssetup); MessageService::Destroy(); + + m_ssetup = nullptr; + m_camera = nullptr; } bool KeyReleased(MVKeyboardList index) { return (HAS_KBOARD && m_controller->GetKey(index).IsReleased()); } @@ -228,15 +232,11 @@ public: g_scene->PushCamera(m_camera); //Lights setup - m_lights << new Light(); - m_lights.Last()->SetPosition(vec4(4.f, -1.f, -4.f, 0.f)); - m_lights.Last()->SetColor(vec4(.0f, .2f, .5f, 1.f)); - Ticker::Ref(m_lights.Last()); - - m_lights << new Light(); - m_lights.Last()->SetPosition(vec4(8.f, 2.f, 6.f, 0.f)); - m_lights.Last()->SetColor(vec4(1.f, 1.f, 1.f, 1.f)); - Ticker::Ref(m_lights.Last()); + m_ssetup = new SceneSetup(); + m_ssetup->Compile(" addlight 0.0 position (4 -1 -4) color (.0 .2 .5 1)" + " addlight 0.0 position (8 2 6) color #ffff" + " custom setmesh \"sc#fff ab 1\""); + m_ssetup->Startup(); //stream update m_stream_update_time = 2.0f; @@ -433,14 +433,30 @@ public: int o = 1; while (o-- > 0) { - if (m_mesh_id == m_meshes.Count() - 1) - m_mesh_id++; - //Create a new mesh - EasyMesh* em = new EasyMesh(); - if (em->Compile(mesh.C())) - m_meshes.Push(em); - else - delete(em); + SceneSetup* new_ssetup = new SceneSetup(); + if (new_ssetup->Compile(mesh.C())) + { + delete(m_ssetup); + m_ssetup = new_ssetup; + m_ssetup->Startup(); + for (int i = 0; i < m_ssetup->m_custom_cmd.Count(); ++i) + { + if (m_ssetup->m_custom_cmd[i].m1 == "setmesh") + { + //Create a new mesh + EasyMesh* em = new EasyMesh(); + if (em->Compile(m_ssetup->m_custom_cmd[i].m2.C())) + { + if (m_mesh_id == m_meshes.Count() - 1) + m_mesh_id++; + m_meshes.Push(em); + } + else + delete(em); + } + } + m_ssetup->m_custom_cmd.Empty(); + } } } @@ -448,7 +464,7 @@ public: if (m_stream_update_time > .0f) { m_stream_update_time = -1.f; - MessageService::Send(MessageBucket::AppIn, "[sc#f8f ab 1]"); +// MessageService::Send(MessageBucket::AppIn, "[sc#f8f ab 1]"); // MessageService::Send(MessageBucket::AppIn, "[sc#f8f ab 1 splt 4 twy 90]"); // MessageService::Send(MessageBucket::AppIn, "[sc#8ff afcb 1 1 1 0]"); // MessageService::Send(MessageBucket::AppIn, "[sc#ff8 afcb 1 1 1 0]"); @@ -467,30 +483,13 @@ public: String cmd = f.ReadString(); f.Close(); - /* - for (int i = 0; i < cmd.Count() - 1; i++) - { - if (cmd[i] == '/' && cmd[i + 1] == '/') - { - int j = i; - for (; j < cmd.Count(); j++) - { - if (cmd[j] == '\r' || cmd[j] == '\n') - break; - } - String new_cmd = cmd.Sub(0, i); - if (j < cmd.Count()) - new_cmd += cmd.Sub(j, cmd.Count() - j); - cmd = new_cmd; - i--; - } - } - */ - if (cmd.Count() && (!m_cmdlist.Count() || cmd != m_cmdlist.Last())) { m_cmdlist << cmd; + cmd = String(" addlight 0.0 position (4 -1 -4) color (.0 .2 .5 1) \ + addlight 0.0 position (8 2 6) color #ffff \ + custom setmesh \"") + cmd + "\""; MessageService::Send(MessageBucket::AppIn, cmd); } } @@ -582,7 +581,7 @@ public: } private: - Array m_lights; + SceneSetup* m_ssetup; byte m_input_usage; Controller* m_controller; mat4 m_mat; @@ -620,8 +619,6 @@ private: float m_stream_update_time; float m_stream_update_timer; - Shader * m_test_shader; - //misc datas Shader * m_texture_shader; TileSet * m_default_texture; diff --git a/test/meshviewer.vcxproj b/test/meshviewer.vcxproj index b2575a55..edc4db5f 100644 --- a/test/meshviewer.vcxproj +++ b/test/meshviewer.vcxproj @@ -43,7 +43,11 @@ + + + + @@ -63,6 +67,10 @@ true + + + + true @@ -76,6 +84,8 @@ true + + true @@ -84,6 +94,11 @@ + + + + + {7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E} Application diff --git a/test/meshviewer_index.html b/test/meshviewer_index.html index fac0bc4c..edfe9374 100644 --- a/test/meshviewer_index.html +++ b/test/meshviewer_index.html @@ -104,6 +104,9 @@ progress::-webkit-progress-value //This is the module pointer : can be either the NaCl or Em one depending on the context. g_embed_module = null; + g_mesh_code_base = "//This is a comment\nsc#f8f afcb 1 1 1 0"; + g_scene_code_base = "//This is a comment\naddlight 0.0 position (4 -1 -4) color (.0 .2 .5 1) addlight 0.0 position (8 2 6) color #ffff"; + function machinchose() { return 'test machin '; } function GetTextAreaCodeSrc() { return g_txtarea_code_src; } function GetDivProgress() { return g_div_progress; } @@ -157,7 +160,7 @@ function machinchose() { return 'test machin '; } //Put here any cookie update if (!g_txtarea_code_src.value) - g_txtarea_code_src.value = "//This is a comment\nsc#f8f afcb 1 1 1 0"; + g_txtarea_code_src.value = g_mesh_code_base; //Fill the TOC if (!g_div_alphabet.innerHTML) @@ -215,7 +218,7 @@ function machinchose() { return 'test machin '; } function SendMessageToModule() { if (g_embed_module) - g_embed_module.SendMessage(GetTextAreaCodeSrc().value); + g_embed_module.SendMessage(g_scene_code_base + ' ' + GetTextAreaCodeSrc().value); else alert("Module not loaded !"); } diff --git a/test/scenesetup-compiler.cpp b/test/scenesetup-compiler.cpp new file mode 100644 index 00000000..4c460cc2 --- /dev/null +++ b/test/scenesetup-compiler.cpp @@ -0,0 +1,55 @@ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" +#include "scenesetup.h" +#include "scenesetup-compiler.h" + +namespace lol +{ + +SceneSetupCompiler::SceneSetupCompiler(SceneSetup &uro) + : m_sstp(uro), m_last_cmd("") +{ +} + +bool SceneSetupCompiler::ParseString(char const *command) +{ + SceneSetupScanner scanner(command); + m_lexer = &scanner; + SceneSetupParser parser(*this); + if (parser.parse() != 0) + { + Log::Debug("Uro source: %s\n", command); + return false; + } + return true; +} + +void SceneSetupCompiler::Error(const class location& l, const std::string& m) +{ + Log::Error("SceneSetup syntax error line %d column %d: %s\n", + l.begin.line, l.begin.column, m.c_str()); +} + +void SceneSetupCompiler::Error(const std::string& m) +{ + Log::Error("SceneSetup syntax error: %s\n", m.c_str()); +} + +} /* namespace lol */ + diff --git a/test/scenesetup-compiler.h b/test/scenesetup-compiler.h new file mode 100644 index 00000000..0ff0ac9c --- /dev/null +++ b/test/scenesetup-compiler.h @@ -0,0 +1,63 @@ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#ifndef __SCENESETUP_COMPILER_H__ +#define __SCENESETUP_COMPILER_H__ + +#include + +#ifndef __FLEX_LEXER_H +# define yyFlexLexer SceneSetupFlexLexer +# include "FlexLexer.h" +# undef yyFlexLexer +#endif + +#include "generated/scenesetup-parser.h" + +class SceneSetup; + +namespace lol +{ + +//---- +class SceneSetupScanner : public SceneSetupFlexLexer +{ +public: + SceneSetupScanner(char const *command); + virtual ~SceneSetupScanner(); + virtual int LexerInput(char* buf, int max_size); + virtual SceneSetupParser::token_type lex(SceneSetupParser::semantic_type* yylval, + SceneSetupParser::location_type* yylloc); + +private: + char const *m_input; +}; + +//---- +class SceneSetupCompiler +{ +public: + SceneSetupCompiler(class SceneSetup &uro); + + bool ParseString(char const *command); + + void Error(const class location& l, const std::string& m); + void Error(const std::string& m); + + class SceneSetupScanner* m_lexer; + class SceneSetup& m_sstp; + String m_last_cmd; +}; + +} /* namespace lol */ + +#endif /* __SCENESETUP_COMPILER_H__ */ + diff --git a/test/scenesetup-parser.y b/test/scenesetup-parser.y new file mode 100644 index 00000000..7d25f02e --- /dev/null +++ b/test/scenesetup-parser.y @@ -0,0 +1,200 @@ +%{ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "../scenesetup.h" + +%} + +%require "2.3" +%debug +%defines +%skeleton "lalr1.cc" +%name-prefix="lol" +%define parser_class_name "SceneSetupParser" +%locations +%parse-param { class SceneSetupCompiler& uc } +%error-verbose + +%union +{ + float fval; + int ival; + bool bval; + float vval[4]; + int ivval[4]; + char* sval; + char* svval; + /* Can't use uin32_t here for some reason */ + unsigned u32val; +} + +%start sstp_description + +%token T_COLOR + +%token T_ADDLIGHT T_OBJPOSITION T_OBJLOOKAT T_OBJCOLOR +%token T_CUSTOMCMD + +%token T_END 0 +%token T_ERROR + +%token F_NUMBER +%token I_NUMBER +%token STRING +%token STRING_VAR +%token BOOLEAN +%token COLOR + +/* Base Number types */ +%type fv +%type iv +/* Vector types */ +%type v3 +%type iv3 +%type v4 +/* Special types */ +%type bv +%type sv +%type svv + + +%{ +#include "../scenesetup-compiler.h" + +#undef yylex +#define yylex uc.m_lexer->lex + +/* HACK: workaround for Bison who insists on using exceptions */ +#define try if (true) +#define catch(...) if (false) +#define throw (void)0 +%} + +%% + +sstp_description: + sstp_expression_list T_END + ; + +sstp_expression_list: + sstp_expression + | sstp_expression sstp_expression_list + ; + +sstp_expression: + sstp_command_list + ; + +sstp_command_list: + sstp_command + | sstp_command_list sstp_command + ; + +sstp_command: + light_command + | setup_command + | custom_command + ; + +light_command: + T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; } + | T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; + uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, $2)); } + ; + +setup_command: + T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3($2[0], $2[1], $2[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); } + | T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT") + { /* */ } } + | T_OBJCOLOR v4 { if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetColor(vec4($2[0], $2[1], $2[2], $2[3])); } + | T_OBJCOLOR COLOR { uint32_t x = $2; + ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); + vec4 vv = vec4(v) * (1.f / 255.f); + if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetColor(vv); } + ; + +custom_command: + T_CUSTOMCMD svv sv { uc.m_sstp.m_custom_cmd.Push($2, $3); } + ; + + +/* Base Number types */ +fv: + F_NUMBER { $$ = $1; } + | '-' fv { $$ = -$2; } + | I_NUMBER { $$ = (float)$1; } + | '-' iv { $$ = -(float)$2; } + ; + +iv: + I_NUMBER { $$ = $1; } + | '-' iv { $$ = -$2; } + | F_NUMBER { $$ = (int)$1; } + | '-' fv { $$ = -(int)$2; } + ; + +/* Vector types */ +v3: + '('fv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; } + | '('fv fv fv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; } + ; + +iv3: + '('iv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; } + | '('iv iv iv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; } + ; + +v4: + '('fv')' { $$[0] = $2; $$[1] = $2; $$[2] = $2; $$[3] = $2; } + | '('fv fv fv fv')' { $$[0] = $2; $$[1] = $3; $$[2] = $4; $$[3] = $5; } + ; + +/* Special types */ +bv: + BOOLEAN { $$ = $1; } + | I_NUMBER { $$ = !!$1; } + | F_NUMBER { $$ = !!$1; } + ; + +svv: + STRING_VAR { $$ = $1; } + ; + +sv: + STRING { String t = $1; + t.Replace('"', ' ', true); + free($1); + $$ = strdup((const char *)t.C()); } + | STRING sv { String t = $1; + t += $2; + t.Replace('"', ' ', true); + free($1); + free($2); + $$ = strdup((const char *)t.C()); } + ; + +%% + +void lol::SceneSetupParser::error(const SceneSetupParser::location_type& l, + const std::string& m) +{ + uc.Error(l, m); +} + diff --git a/test/scenesetup-scanner.l b/test/scenesetup-scanner.l new file mode 100644 index 00000000..88882c37 --- /dev/null +++ b/test/scenesetup-scanner.l @@ -0,0 +1,144 @@ +%{ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include +using std::exit; +using std::malloc; +using std::realloc; +using std::free; + +#include "core.h" +#include "../scenesetup.h" +#include "../scenesetup-compiler.h" + +typedef lol::SceneSetupParser::token token; +typedef lol::SceneSetupParser::token_type token_type; + +#ifndef YY_DECL +# define YY_DECL lol::SceneSetupParser::token_type \ + lol::SceneSetupScanner::lex(lol::SceneSetupParser::semantic_type* yylval, \ + lol::SceneSetupParser::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="SceneSetup" +%option batch yywrap nounput stack + +%% + +%{ /* reset location at the beginning of yylex() */ + yylloc->step(); +%} + +addlight { return token::T_ADDLIGHT; } +position { return token::T_OBJPOSITION; } +lookat { return token::T_OBJLOOKAT; } +color { return token::T_OBJCOLOR; } + +custom { return token::T_CUSTOMCMD; } + +%{ /* ======= BASE COLOR TYPES ========================================= */ %} +%{ /* COLOR */ %} +#[0-9a-fA-F]{3} { + uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); + yylval->u32val = 0x11000000u * (tmp >> 8) + | 0x00110000u * ((tmp >> 4) & 0xf) + | 0x00001100u * (tmp & 0xf) + | 0x000000ffu; + return token::COLOR; } +#[0-9a-fA-F]{4} { + uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); + yylval->u32val = 0x11000000u * (tmp >> 12) + | 0x00110000u * ((tmp >> 8) & 0xf) + | 0x00001100u * ((tmp >> 4) & 0xf) + | 0x00000011u * (tmp & 0xf); + return token::COLOR; } +#[0-9a-fA-F]{6} { + yylval->u32val = 0xffu + | 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16); + return token::COLOR; } +#[0-9a-fA-F]{8} { + yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16); + return token::COLOR; } + +%{ /* ======= BASE DATA TYPES ========================================= */ %} +%{ /* BOOL */ %} +true { yylval->bval = true; return token::BOOLEAN; } +false { yylval->bval = false; return token::BOOLEAN; } +%{ /* FLOAT */ %} +[-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)? { + yylval->fval = (float)std::atof(yytext); return token::F_NUMBER; } +%{ /* INT */ %} +[-+]?[0-9]+ { + yylval->ival = std::atoi(yytext); return token::I_NUMBER; } +%{ /* STRING */ %} +[\"][^\"]*[\"] { + yylval->sval = strdup(yytext); return token::STRING; } +%{ /* STRING VAR */ %} +[a-zA-Z][a-zA-Z_\-]+ { + yylval->svval = strdup(yytext); return token::STRING_VAR; } + +%{ /* ======= COMMENTS ======= */ %} +"//"[^\n\r]*[\n\r] { /* ignore this */ } + +%{ /* Semantics tokens */ %} +"-" { return token_type('-'); } +"(" { return token_type('('); } +")" { return token_type(')'); } +[ ,] { /* ignore this */ } +[\n] { /* ignore this */ } +. { return token::T_ERROR; } + +%% + +lol::SceneSetupScanner::SceneSetupScanner(char const *command) + : SceneSetupFlexLexer(0, 0), + m_input(command) +{ +} + +lol::SceneSetupScanner::~SceneSetupScanner() +{ +} + +int lol::SceneSetupScanner::LexerInput(char* buf, int max_size) +{ + (void)max_size; /* unused for now */ + + buf[0] = m_input[0]; + if (buf[0]) + ++m_input; + return buf[0] ? 1 : 0; +} + +#ifdef yylex +#undef yylex +#endif +int SceneSetupFlexLexer::yylex() +{ + std::cerr << "in SceneSetupFlexLexer::yylex() !" << std::endl; + return 0; +} + +int SceneSetupFlexLexer::yywrap() +{ + return 1; +} + diff --git a/test/scenesetup.cpp b/test/scenesetup.cpp new file mode 100644 index 00000000..94703521 --- /dev/null +++ b/test/scenesetup.cpp @@ -0,0 +1,61 @@ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "scenesetup.h" +#include "scenesetup-compiler.h" + +namespace lol +{ + +//----------------------------------------------------------------------------- +//CTor/DTor +SceneSetup::SceneSetup() +{ +} + +//---- +SceneSetup::~SceneSetup() +{ + Shutdown(true); +} + +//----------------------------------------------------------------------------- +bool SceneSetup::Compile(char const *command) +{ + SceneSetupCompiler mc(*this); + return mc.ParseString(command); +} + +//----------------------------------------------------------------------------- +bool SceneSetup::Startup() +{ + for (int i = 0; i < m_lights.Count(); i++) + Ticker::Ref(m_lights[i]); + return true; +} + +//----------------------------------------------------------------------------- +bool SceneSetup::Shutdown(bool destroy) +{ + for (int i = 0; i < m_lights.Count(); i++) + Ticker::Unref(m_lights[i]); + + if (destroy) + m_lights.Empty(); + return true; +} + +} /* namespace lol */ diff --git a/test/scenesetup.h b/test/scenesetup.h new file mode 100644 index 00000000..97f1149f --- /dev/null +++ b/test/scenesetup.h @@ -0,0 +1,48 @@ +// +// Lol Engine +// +// Copyright: (c) 2013 Benjamin "Touky" Huet +// (c) 2013 Sam Hocevar +// 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://www.wtfpl.net/ for more details. +// + +// +// The Scene setup class +// ---------------- +// + +#if !defined __SCENESETUP_H__ +#define __SCENESETUP_H__ + +namespace lol +{ + +class SceneSetup +{ + friend class SceneSetupParser; + +public: + //CTor/DTor + SceneSetup(); + ~SceneSetup(); + + static char const *GetName() { return ""; } + + //-- + bool Compile(char const *command); + + //-- + bool Startup(); + bool Shutdown(bool destroy=false); + +//private: + Array m_lights; + Array m_custom_cmd; +}; + +} /* namespace lol */ + +#endif /* __SCENESETUP_H__ */