From 42953929067c30dcb7a72c1d4c7b26d85d626384 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Sun, 4 May 2008 15:09:23 +0000 Subject: Added new Parser class, which will gradually grow to include all parsing code from the engine class. svn-id: r31865 --- engines/parallaction/parser_ns.cpp | 47 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'engines/parallaction/parser_ns.cpp') diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 5e4bdf25cf..f955f44c8c 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -112,7 +112,7 @@ DECLARE_ANIM_PARSER(type) { _locParseCtxt.a->_flags |= 0x1000000; - popParserTables(); + _locationParser->popTables(); } @@ -176,7 +176,7 @@ DECLARE_ANIM_PARSER(endanimation) { _locParseCtxt.a->_flags |= 0x1000000; - popParserTables(); + _locationParser->popTables(); } void Parallaction_ns::parseAnimation(Script& script, AnimationList &list, char *name) { @@ -191,7 +191,7 @@ void Parallaction_ns::parseAnimation(Script& script, AnimationList &list, char * _locParseCtxt.a = a; _locParseCtxt.script = &script; - pushParserTables(&_locationAnimParsers, _locationAnimStmt); + _locationParser->pushTables(&_locationAnimParsers, _locationAnimStmt); } void Parallaction_ns::parseInstruction(ProgramPtr program) { @@ -469,7 +469,7 @@ void Parallaction_ns::parseLValue(ScriptVar &v, const char *str) { DECLARE_COMMAND_PARSER(flags) { debugC(7, kDebugParser, "COMMAND_PARSER(flags) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); if (_globalTable->lookup(_tokens[1]) == Table::notFound) { do { @@ -496,7 +496,7 @@ DECLARE_COMMAND_PARSER(flags) { DECLARE_COMMAND_PARSER(zone) { debugC(7, kDebugParser, "COMMAND_PARSER(zone) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); _locParseCtxt.cmd->u._zone = findZone(_tokens[_locParseCtxt.nextToken]); if (!_locParseCtxt.cmd->u._zone) { @@ -512,7 +512,7 @@ DECLARE_COMMAND_PARSER(zone) { DECLARE_COMMAND_PARSER(location) { debugC(7, kDebugParser, "COMMAND_PARSER(location) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); _locParseCtxt.cmd->u._string = strdup(_tokens[_locParseCtxt.nextToken]); _locParseCtxt.nextToken++; @@ -525,7 +525,7 @@ DECLARE_COMMAND_PARSER(location) { DECLARE_COMMAND_PARSER(drop) { debugC(7, kDebugParser, "COMMAND_PARSER(drop) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); _locParseCtxt.cmd->u._object = 4 + _objectsNames->lookup(_tokens[_locParseCtxt.nextToken]); _locParseCtxt.nextToken++; @@ -538,7 +538,7 @@ DECLARE_COMMAND_PARSER(drop) { DECLARE_COMMAND_PARSER(call) { debugC(7, kDebugParser, "COMMAND_PARSER(call) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); _locParseCtxt.cmd->u._callable = _callableNames->lookup(_tokens[_locParseCtxt.nextToken]) - 1; _locParseCtxt.nextToken++; @@ -551,7 +551,7 @@ DECLARE_COMMAND_PARSER(call) { DECLARE_COMMAND_PARSER(simple) { debugC(7, kDebugParser, "COMMAND_PARSER(simple) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); addCommand(); } @@ -559,7 +559,7 @@ DECLARE_COMMAND_PARSER(simple) { DECLARE_COMMAND_PARSER(move) { debugC(7, kDebugParser, "COMMAND_PARSER(move) "); - createCommand(_lookup); + createCommand(_locationParser->_lookup); _locParseCtxt.cmd->u._move.x = atoi(_tokens[_locParseCtxt.nextToken]); _locParseCtxt.nextToken++; @@ -573,7 +573,7 @@ DECLARE_COMMAND_PARSER(move) { DECLARE_COMMAND_PARSER(endcommands) { debugC(7, kDebugParser, "COMMAND_PARSER(endcommands) "); - popParserTables(); + _locationParser->popTables(); // temporary trick to handle dialogue commands _locParseCtxt.endcommands = true; @@ -679,7 +679,7 @@ void Parallaction_ns::parseCommands(Script &script, CommandList& list) { _locParseCtxt.endcommands = false; _locParseCtxt.script = &script; - pushParserTables(&_commandParsers, _commandsNames); + _locationParser->pushTables(&_commandParsers, _commandsNames); } Dialogue *Parallaction_ns::parseDialogue(Script &script) { @@ -779,8 +779,7 @@ Answer *Parallaction_ns::parseAnswer(Script &script) { parseCommands(script, answer->_commands); _locParseCtxt.endcommands = false; do { - script.readLineToken(true); - parseStatement(); + _locationParser->parseStatement(); } while (!_locParseCtxt.endcommands); script.readLineToken(true); @@ -980,6 +979,7 @@ void Parallaction_ns::parseLocation(const char *filename) { _numForwardedCommands = 0; Script *script = _disk->loadLocation(filename); + _locationParser->bind(script); // TODO: the following two lines are specific to Nippon Safes // and should be moved into something like 'initializeParsing()' @@ -989,12 +989,12 @@ void Parallaction_ns::parseLocation(const char *filename) { _locParseCtxt.script = script; _locParseCtxt.filename = filename; - pushParserTables(&_locationParsers, _locationStmt); + _locationParser->pushTables(&_locationParsers, _locationStmt); do { - script->readLineToken(true); - parseStatement(); + _locationParser->parseStatement(); } while (!_locParseCtxt.end); - popParserTables(); + _locationParser->popTables(); + _locationParser->unbind(); delete script; @@ -1048,6 +1048,8 @@ typedef OpcodeImpl OpcodeV1; void Parallaction_ns::initParsers() { + _locationParser = new Parser; + static const OpcodeV1 op0[] = { INSTRUCTION_PARSER(defLocal), // invalid opcode -> local definition INSTRUCTION_PARSER(animation), // on @@ -1153,9 +1155,6 @@ void Parallaction_ns::initParsers() { for (i = 0; i < ARRAYSIZE(op6); i++) _locationAnimParsers.push_back(&op6[i]); - _currentOpcodes = 0; - _currentStatements = 0; - } // @@ -1193,7 +1192,7 @@ DECLARE_ZONE_PARSER(null) { DECLARE_ZONE_PARSER(endzone) { debugC(7, kDebugParser, "ZONE_PARSER(endzone) "); - popParserTables(); + _locationParser->popTables(); } DECLARE_ZONE_PARSER(limits) { @@ -1226,7 +1225,7 @@ DECLARE_ZONE_PARSER(type) { parseZoneTypeBlock(*_locParseCtxt.script, _locParseCtxt.z); } - popParserTables(); + _locationParser->popTables(); } @@ -1274,7 +1273,7 @@ void Parallaction_ns::parseZone(Script &script, ZoneList &list, char *name) { list.push_front(z); - pushParserTables(&_locationZoneParsers, _locationZoneStmt); + _locationParser->pushTables(&_locationZoneParsers, _locationZoneStmt); return; } -- cgit v1.2.3