diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-01-04 00:06:07 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-01-04 00:06:07 -0700 |
| commit | d8f0276ec9d3b538a5ef8918a3072e3528a480d5 (patch) | |
| tree | 41c8cb65f07053e6a0a4d15a0b0a5f5e1c56bb33 /src | |
| parent | 3a0f68b527cc85bd9847127085415739af784eca (diff) | |
| download | stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.gz stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.bz2 stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.tar.xz stage-d8f0276ec9d3b538a5ef8918a3072e3528a480d5.zip | |
Parse moved to GameBuilder.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gamebuilder.cpp | 22 | ||||
| -rw-r--r-- | src/gamebuilder.h | 2 | ||||
| -rw-r--r-- | src/main.cpp | 23 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp index 3cf2e1f..83cbe79 100644 --- a/src/gamebuilder.cpp +++ b/src/gamebuilder.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "astfunction.h" | 8 | #include "astfunction.h" |
| 9 | #include "command.h" | 9 | #include "command.h" |
| 10 | #include "situation.h" | 10 | #include "situation.h" |
| 11 | #include "parser.tab.h" | ||
| 11 | 12 | ||
| 12 | using namespace Bu; | 13 | using namespace Bu; |
| 13 | 14 | ||
| @@ -27,6 +28,27 @@ GameBuilder::~GameBuilder() | |||
| 27 | { | 28 | { |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 31 | typedef void *yyscan_t; | ||
| 32 | void yylex_init( yyscan_t * ); | ||
| 33 | void yylex_destroy( yyscan_t ); | ||
| 34 | void yyparse( yyscan_t, GameBuilder &bld ); | ||
| 35 | void yyset_in( FILE *, yyscan_t ); | ||
| 36 | |||
| 37 | void GameBuilder::parse( const Bu::String &sFile ) | ||
| 38 | { | ||
| 39 | yyscan_t scanner; | ||
| 40 | |||
| 41 | yylex_init( &scanner ); | ||
| 42 | |||
| 43 | FILE *in = fopen( sFile.getStr(), "rb" ); | ||
| 44 | yyset_in( in, scanner ); | ||
| 45 | |||
| 46 | yyparse( scanner, *this ); | ||
| 47 | yylex_destroy( scanner ); | ||
| 48 | |||
| 49 | fclose( in ); | ||
| 50 | } | ||
| 51 | |||
| 30 | void GameBuilder::setLiteral( const Variable &v ) | 52 | void GameBuilder::setLiteral( const Variable &v ) |
| 31 | { | 53 | { |
| 32 | vLiteral = v; | 54 | vLiteral = v; |
diff --git a/src/gamebuilder.h b/src/gamebuilder.h index b1e4d49..f3e3a1f 100644 --- a/src/gamebuilder.h +++ b/src/gamebuilder.h | |||
| @@ -13,6 +13,8 @@ public: | |||
| 13 | GameBuilder(); | 13 | GameBuilder(); |
| 14 | virtual ~GameBuilder(); | 14 | virtual ~GameBuilder(); |
| 15 | 15 | ||
| 16 | void parse( const Bu::String &sFile ); | ||
| 17 | |||
| 16 | class Game *getGame() { return pGame; } | 18 | class Game *getGame() { return pGame; } |
| 17 | 19 | ||
| 18 | void setLiteral( const Variable &v ); | 20 | void setLiteral( const Variable &v ); |
diff --git a/src/main.cpp b/src/main.cpp index 5b91861..6646d79 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #include "gamebuilder.h" | 1 | #include "gamebuilder.h" |
| 2 | #include "game.h" | 2 | #include "game.h" |
| 3 | #include "gamestate.h" | 3 | #include "gamestate.h" |
| 4 | #include "parser.tab.h" | ||
| 5 | 4 | ||
| 6 | #include <stdlib.h> | 5 | #include <stdlib.h> |
| 7 | #include <time.h> | 6 | #include <time.h> |
| @@ -13,30 +12,12 @@ | |||
| 13 | #include <bu/sio.h> | 12 | #include <bu/sio.h> |
| 14 | using namespace Bu; | 13 | using namespace Bu; |
| 15 | 14 | ||
| 16 | typedef void *yyscan_t; | ||
| 17 | void yylex_init( yyscan_t * ); | ||
| 18 | void yylex_destroy( yyscan_t ); | ||
| 19 | void yyparse( yyscan_t, GameBuilder &bld ); | ||
| 20 | void yyset_in( FILE *, yyscan_t ); | ||
| 21 | |||
| 22 | int main( int argc, char *argv[] ) | 15 | int main( int argc, char *argv[] ) |
| 23 | { | 16 | { |
| 24 | yyscan_t scanner; | ||
| 25 | |||
| 26 | GameBuilder bld; | ||
| 27 | |||
| 28 | yylex_init( &scanner ); | ||
| 29 | |||
| 30 | FILE *in = fopen( argv[1], "rb" ); | ||
| 31 | yyset_in( in, scanner ); | ||
| 32 | |||
| 33 | yyparse( scanner, bld ); | ||
| 34 | yylex_destroy( scanner ); | ||
| 35 | |||
| 36 | fclose( in ); | ||
| 37 | |||
| 38 | srandom( time( NULL ) ); | 17 | srandom( time( NULL ) ); |
| 39 | 18 | ||
| 19 | GameBuilder bld; | ||
| 20 | bld.parse( argv[1] ); | ||
| 40 | Game *pGame = bld.getGame(); | 21 | Game *pGame = bld.getGame(); |
| 41 | 22 | ||
| 42 | GameState gs( pGame ); | 23 | GameState gs( pGame ); |
