Explorar el Código

Added SceneSetup and its Parser/Compiler

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> hace 11 años
padre
commit
1e7d3ee21a
Se han modificado 17 ficheros con 4991 adiciones y 46 borrados
  1. +1
    -1
      src/easymesh/easymesh-scanner.l
  2. +164
    -0
      test/generated/location.hh
  3. +161
    -0
      test/generated/position.hh
  4. +1082
    -0
      test/generated/scenesetup-parser.cpp
  5. +330
    -0
      test/generated/scenesetup-parser.h
  6. +700
    -0
      test/generated/scenesetup-parser.output
  7. +1787
    -0
      test/generated/scenesetup-scanner.cpp
  8. +135
    -0
      test/generated/stack.hh
  9. +40
    -43
      test/meshviewer.cpp
  10. +15
    -0
      test/meshviewer.vcxproj
  11. +5
    -2
      test/meshviewer_index.html
  12. +55
    -0
      test/scenesetup-compiler.cpp
  13. +63
    -0
      test/scenesetup-compiler.h
  14. +200
    -0
      test/scenesetup-parser.y
  15. +144
    -0
      test/scenesetup-scanner.l
  16. +61
    -0
      test/scenesetup.cpp
  17. +48
    -0
      test/scenesetup.h

+ 1
- 1
src/easymesh/easymesh-scanner.l Ver fichero

@@ -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);


+ 164
- 0
test/generated/location.hh Ver fichero

@@ -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 <http://www.gnu.org/licenses/>. */

/* 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 <iostream>
# include <string>
# 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

+ 161
- 0
test/generated/position.hh Ver fichero

@@ -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 <http://www.gnu.org/licenses/>. */

/* 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 <iostream>
# include <string>
# include <algorithm>


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

+ 1082
- 0
test/generated/scenesetup-parser.cpp
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 330
- 0
test/generated/scenesetup-parser.h Ver fichero

@@ -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 <http://www.gnu.org/licenses/>. */

/* 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 <string>
#include <iostream>
#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_type> state_stack_type;
/// Semantic value stack type.
typedef stack<semantic_type> semantic_stack_type;
/// location stack type.
typedef stack<location_type> 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 */

+ 700
- 0
test/generated/scenesetup-parser.output Ver fichero

@@ -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)

+ 1787
- 0
test/generated/scenesetup-scanner.cpp
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 135
- 0
test/generated/stack.hh Ver fichero

@@ -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 <http://www.gnu.org/licenses/>. */

/* 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 <deque>


namespace lol {

/* Line 1066 of lalr1.cc */
#line 43 "generated/stack.hh"
template <class T, class S = std::deque<T> >
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 T, class S = stack<T> >
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


+ 40
- 43
test/meshviewer.cpp Ver fichero

@@ -17,6 +17,7 @@
#include <cfloat> /* 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<Light *> 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;


+ 15
- 0
test/meshviewer.vcxproj Ver fichero

@@ -43,7 +43,11 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="generated\scenesetup-parser.cpp" />
<ClCompile Include="generated\scenesetup-scanner.cpp" />
<ClCompile Include="meshviewer.cpp" />
<ClCompile Include="scenesetup-compiler.cpp" />
<ClCompile Include="scenesetup.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\..\src\lolcore.vcxproj">
@@ -63,6 +67,10 @@
<None Include="easy_mesh_dictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="generated\location.hh" />
<None Include="generated\position.hh" />
<None Include="generated\scenesetup-parser.output" />
<None Include="generated\stack.hh" />
<None Include="meshviewer_index.html">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
@@ -76,6 +84,8 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
<None Include="progress_status.js" />
<None Include="scenesetup-parser.y" />
<None Include="scenesetup-scanner.l" />
<None Include="type_dictionnary.js">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</None>
@@ -84,6 +94,11 @@
<LolFxCompile Include="shinyfur.lolfx" />
<LolFxCompile Include="shinymvtexture.lolfx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="generated\scenesetup-parser.h" />
<ClInclude Include="scenesetup-compiler.h" />
<ClInclude Include="scenesetup.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E}</ProjectGuid>
<ConfigurationType>Application</ConfigurationType>


+ 5
- 2
test/meshviewer_index.html Ver fichero

@@ -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 !");
}


+ 55
- 0
test/scenesetup-compiler.cpp Ver fichero

@@ -0,0 +1,55 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// 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 <string>

#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 */


+ 63
- 0
test/scenesetup-compiler.h Ver fichero

@@ -0,0 +1,63 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// 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 <string>

#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__ */


+ 200
- 0
test/scenesetup-parser.y Ver fichero

@@ -0,0 +1,200 @@
%{
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// 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 <fval> F_NUMBER
%token <ival> I_NUMBER
%token <sval> STRING
%token <svval> STRING_VAR
%token <bval> BOOLEAN
%token <u32val> COLOR

/* Base Number types */
%type <fval> fv
%type <ival> iv
/* Vector types */
%type <vval> v3
%type <ivval> iv3
%type <vval> v4
/* Special types */
%type <bval> bv
%type <sval> sv
%type <svval> 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);
}


+ 144
- 0
test/scenesetup-scanner.l Ver fichero

@@ -0,0 +1,144 @@
%{
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// 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 <cstdlib>
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;
}


+ 61
- 0
test/scenesetup.cpp Ver fichero

@@ -0,0 +1,61 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// 2013 Sam Hocevar <sam@hocevar.net>
// 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 */

+ 48
- 0
test/scenesetup.h Ver fichero

@@ -0,0 +1,48 @@
//
// Lol Engine
//
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2013 Sam Hocevar <sam@hocevar.net>
// 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 "<scenesetup>"; }

//--
bool Compile(char const *command);

//--
bool Startup();
bool Shutdown(bool destroy=false);

//private:
Array<Light *> m_lights;
Array<String, String> m_custom_cmd;
};

} /* namespace lol */

#endif /* __SCENESETUP_H__ */

Cargando…
Cancelar
Guardar