From d8f0276ec9d3b538a5ef8918a3072e3528a480d5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 4 Jan 2012 00:06:07 -0700 Subject: Parse moved to GameBuilder. --- src/gamebuilder.cpp | 22 ++++++++++++++++++++++ src/gamebuilder.h | 2 ++ src/main.cpp | 23 ++--------------------- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'src') 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 @@ #include "astfunction.h" #include "command.h" #include "situation.h" +#include "parser.tab.h" using namespace Bu; @@ -27,6 +28,27 @@ GameBuilder::~GameBuilder() { } +typedef void *yyscan_t; +void yylex_init( yyscan_t * ); +void yylex_destroy( yyscan_t ); +void yyparse( yyscan_t, GameBuilder &bld ); +void yyset_in( FILE *, yyscan_t ); + +void GameBuilder::parse( const Bu::String &sFile ) +{ + yyscan_t scanner; + + yylex_init( &scanner ); + + FILE *in = fopen( sFile.getStr(), "rb" ); + yyset_in( in, scanner ); + + yyparse( scanner, *this ); + yylex_destroy( scanner ); + + fclose( in ); +} + void GameBuilder::setLiteral( const Variable &v ) { 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: GameBuilder(); virtual ~GameBuilder(); + void parse( const Bu::String &sFile ); + class Game *getGame() { return pGame; } 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 @@ #include "gamebuilder.h" #include "game.h" #include "gamestate.h" -#include "parser.tab.h" #include #include @@ -13,30 +12,12 @@ #include using namespace Bu; -typedef void *yyscan_t; -void yylex_init( yyscan_t * ); -void yylex_destroy( yyscan_t ); -void yyparse( yyscan_t, GameBuilder &bld ); -void yyset_in( FILE *, yyscan_t ); - int main( int argc, char *argv[] ) { - yyscan_t scanner; - - GameBuilder bld; - - yylex_init( &scanner ); - - FILE *in = fopen( argv[1], "rb" ); - yyset_in( in, scanner ); - - yyparse( scanner, bld ); - yylex_destroy( scanner ); - - fclose( in ); - srandom( time( NULL ) ); + GameBuilder bld; + bld.parse( argv[1] ); Game *pGame = bld.getGame(); GameState gs( pGame ); -- cgit v1.2.3