aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2010-01-23 17:55:54 +0000
committerFilippos Karapetis2010-01-23 17:55:54 +0000
commitdf149e1509d972b2d5bfe903531d9670c2fe83c7 (patch)
treed0012ab2d2fde14a0fbcaf74ff43e3a4e19ec929 /engines
parent4fcc82e7a625a0b27927491ca03c41a9f3dca35b (diff)
downloadscummvm-rg350-df149e1509d972b2d5bfe903531d9670c2fe83c7.tar.gz
scummvm-rg350-df149e1509d972b2d5bfe903531d9670c2fe83c7.tar.bz2
scummvm-rg350-df149e1509d972b2d5bfe903531d9670c2fe83c7.zip
Separated the parser code
svn-id: r47480
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/console.cpp4
-rw-r--r--engines/sci/engine/kernel.h1
-rw-r--r--engines/sci/engine/kparse.cpp210
-rw-r--r--engines/sci/engine/kstring.cpp176
-rw-r--r--engines/sci/engine/state.h4
-rw-r--r--engines/sci/module.mk6
-rw-r--r--engines/sci/parser/grammar.cpp (renamed from engines/sci/engine/grammar.cpp)2
-rw-r--r--engines/sci/parser/said.cpp (renamed from engines/sci/engine/said.cpp)0
-rw-r--r--engines/sci/parser/said.y (renamed from engines/sci/engine/said.y)0
-rw-r--r--engines/sci/parser/vocabulary.cpp (renamed from engines/sci/vocabulary.cpp)2
-rw-r--r--engines/sci/parser/vocabulary.h (renamed from engines/sci/vocabulary.h)0
-rw-r--r--engines/sci/resource.cpp2
12 files changed, 222 insertions, 185 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 2a1adb3fcf..1e472839af 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -30,7 +30,6 @@
#include "sci/debug.h"
#include "sci/event.h"
#include "sci/resource.h"
-#include "sci/vocabulary.h"
#include "sci/engine/savegame.h"
#include "sci/engine/state.h"
#include "sci/engine/gc.h"
@@ -42,10 +41,11 @@
#include "sci/sound/music.h"
#endif
#include "sci/sound/drivers/mididriver.h"
-#include "sci/vocabulary.h"
#include "sci/graphics/gui.h"
#include "sci/graphics/cursor.h"
+#include "sci/parser/vocabulary.h"
+
#include "graphics/video/avi_decoder.h"
#include "sci/video/seq_decoder.h"
#ifdef ENABLE_SCI32
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index abf090eab6..9ba33aff97 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -31,7 +31,6 @@
#include "common/rect.h"
#include "sci/sci.h" // for USE_OLD_MUSIC_FUNCTIONS
-#include "sci/vocabulary.h"
#include "sci/engine/vm_types.h" // for reg_t
#include "sci/engine/vm.h"
diff --git a/engines/sci/engine/kparse.cpp b/engines/sci/engine/kparse.cpp
new file mode 100644
index 0000000000..5cb24f4fac
--- /dev/null
+++ b/engines/sci/engine/kparse.cpp
@@ -0,0 +1,210 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/* String and parser handling */
+
+#include "sci/resource.h"
+#include "sci/engine/state.h"
+#include "sci/engine/message.h"
+#include "sci/engine/kernel.h"
+
+namespace Sci {
+
+/*************************************************************/
+/* Parser */
+/**********/
+
+
+reg_t kSaid(EngineState *s, int argc, reg_t *argv) {
+ reg_t heap_said_block = argv[0];
+ byte *said_block;
+ int new_lastmatch;
+#ifdef DEBUG_PARSER
+ const int debug_parser = 1;
+#else
+ const int debug_parser = 0;
+#endif
+
+ if (!heap_said_block.segment)
+ return NULL_REG;
+
+ said_block = (byte *)s->_segMan->derefBulkPtr(heap_said_block, 0);
+
+ if (!said_block) {
+ warning("Said on non-string, pointer %04x:%04x", PRINT_REG(heap_said_block));
+ return NULL_REG;
+ }
+
+#ifdef DEBUG_PARSER
+ debugC(2, kDebugLevelParser, "Said block:", 0);
+ s->_voc->decipherSaidBlock(said_block);
+#endif
+
+ if (s->parser_event.isNull() || (GET_SEL32V(s->_segMan, s->parser_event, claimed))) {
+ return NULL_REG;
+ }
+
+ new_lastmatch = said(s, said_block, debug_parser);
+ if (new_lastmatch != SAID_NO_MATCH) { /* Build and possibly display a parse tree */
+
+#ifdef DEBUG_PARSER
+ printf("kSaid: Match.\n");
+#endif
+
+ s->r_acc = make_reg(0, 1);
+
+ if (new_lastmatch != SAID_PARTIAL_MATCH)
+ PUT_SEL32V(s->_segMan, s->parser_event, claimed, 1);
+
+ } else {
+ return NULL_REG;
+ }
+ return s->r_acc;
+}
+
+
+reg_t kSetSynonyms(EngineState *s, int argc, reg_t *argv) {
+ SegManager *segMan = s->_segMan;
+ reg_t object = argv[0];
+ List *list;
+ Node *node;
+ int script;
+ int numSynonyms = 0;
+
+ s->_voc->clearSynonyms();
+
+ list = s->_segMan->lookupList(GET_SEL32(segMan, object, elements));
+ node = s->_segMan->lookupNode(list->first);
+
+ while (node) {
+ reg_t objpos = node->value;
+ int seg;
+
+ script = GET_SEL32V(segMan, objpos, number);
+ seg = s->_segMan->getScriptSegment(script);
+
+ if (seg > 0)
+ numSynonyms = s->_segMan->getScript(seg)->getSynonymsNr();
+
+ if (numSynonyms) {
+ byte *synonyms = s->_segMan->getScript(seg)->getSynonyms();
+
+ if (synonyms) {
+ debugC(2, kDebugLevelParser, "Setting %d synonyms for script.%d\n",
+ numSynonyms, script);
+
+ if (numSynonyms > 16384) {
+ error("Segtable corruption: script.%03d has %d synonyms",
+ script, numSynonyms);
+ /* We used to reset the corrupted value here. I really don't think it's appropriate.
+ * Lars */
+ } else
+ for (int i = 0; i < numSynonyms; i++) {
+ synonym_t tmp;
+ tmp.replaceant = (int16)READ_LE_UINT16(synonyms + i * 4);
+ tmp.replacement = (int16)READ_LE_UINT16(synonyms + i * 4 + 2);
+ s->_voc->addSynonym(tmp);
+ }
+ } else
+ warning("Synonyms of script.%03d were requested, but script is not available", script);
+
+ }
+
+ node = s->_segMan->lookupNode(node->succ);
+ }
+
+ debugC(2, kDebugLevelParser, "A total of %d synonyms are active now.\n", numSynonyms);
+
+ return s->r_acc;
+}
+
+
+
+reg_t kParse(EngineState *s, int argc, reg_t *argv) {
+ SegManager *segMan = s->_segMan;
+ reg_t stringpos = argv[0];
+ Common::String string = s->_segMan->getString(stringpos);
+ char *error;
+ ResultWordList words;
+ reg_t event = argv[1];
+ Vocabulary *voc = s->_voc;
+
+ s->parser_event = event;
+
+ bool res = voc->tokenizeString(words, string.c_str(), &error);
+ s->parserIsValid = false; /* not valid */
+
+ if (res && !words.empty()) {
+ s->_voc->synonymizeTokens(words);
+
+ s->r_acc = make_reg(0, 1);
+
+#ifdef DEBUG_PARSER
+ debugC(2, kDebugLevelParser, "Parsed to the following blocks:\n", 0);
+
+ for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
+ debugC(2, kDebugLevelParser, " Type[%04x] Group[%04x]\n", i->_class, i->_group);
+#endif
+
+ int syntax_fail = voc->parseGNF(words);
+
+ if (syntax_fail) {
+ s->r_acc = make_reg(0, 1);
+ PUT_SEL32V(segMan, event, claimed, 1);
+
+ invoke_selector(INV_SEL(s->_gameObj, syntaxFail, kStopOnInvalidSelector), 2, s->parser_base, stringpos);
+ /* Issue warning */
+
+ debugC(2, kDebugLevelParser, "Tree building failed\n");
+
+ } else {
+ s->parserIsValid = true;
+ PUT_SEL32V(segMan, event, claimed, 0);
+
+#ifdef DEBUG_PARSER
+ s->_voc->dumpParseTree();
+#endif
+ }
+
+ } else {
+
+ s->r_acc = make_reg(0, 0);
+ PUT_SEL32V(segMan, event, claimed, 1);
+ if (error) {
+ s->_segMan->strcpy(s->parser_base, error);
+ debugC(2, kDebugLevelParser, "Word unknown: %s\n", error);
+ /* Issue warning: */
+
+ invoke_selector(INV_SEL(s->_gameObj, wordFail, kStopOnInvalidSelector), 2, s->parser_base, stringpos);
+ free(error);
+ return make_reg(0, 1); /* Tell them that it didn't work */
+ }
+ }
+
+ return s->r_acc;
+}
+
+
+} // End of namespace Sci
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 19c3f1540f..2e4ecce802 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -66,182 +66,6 @@ Common::String kernel_lookup_text(EngineState *s, reg_t address, int index) {
}
}
-
-/*************************************************************/
-/* Parser */
-/**********/
-
-
-reg_t kSaid(EngineState *s, int argc, reg_t *argv) {
- reg_t heap_said_block = argv[0];
- byte *said_block;
- int new_lastmatch;
-#ifdef DEBUG_PARSER
- const int debug_parser = 1;
-#else
- const int debug_parser = 0;
-#endif
-
- if (!heap_said_block.segment)
- return NULL_REG;
-
- said_block = (byte *)s->_segMan->derefBulkPtr(heap_said_block, 0);
-
- if (!said_block) {
- warning("Said on non-string, pointer %04x:%04x", PRINT_REG(heap_said_block));
- return NULL_REG;
- }
-
-#ifdef DEBUG_PARSER
- debugC(2, kDebugLevelParser, "Said block:", 0);
- s->_voc->decipherSaidBlock(said_block);
-#endif
-
- if (s->parser_event.isNull() || (GET_SEL32V(s->_segMan, s->parser_event, claimed))) {
- return NULL_REG;
- }
-
- new_lastmatch = said(s, said_block, debug_parser);
- if (new_lastmatch != SAID_NO_MATCH) { /* Build and possibly display a parse tree */
-
-#ifdef DEBUG_PARSER
- printf("kSaid: Match.\n");
-#endif
-
- s->r_acc = make_reg(0, 1);
-
- if (new_lastmatch != SAID_PARTIAL_MATCH)
- PUT_SEL32V(s->_segMan, s->parser_event, claimed, 1);
-
- } else {
- return NULL_REG;
- }
- return s->r_acc;
-}
-
-
-reg_t kSetSynonyms(EngineState *s, int argc, reg_t *argv) {
- SegManager *segMan = s->_segMan;
- reg_t object = argv[0];
- List *list;
- Node *node;
- int script;
- int numSynonyms = 0;
-
- s->_voc->clearSynonyms();
-
- list = s->_segMan->lookupList(GET_SEL32(segMan, object, elements));
- node = s->_segMan->lookupNode(list->first);
-
- while (node) {
- reg_t objpos = node->value;
- int seg;
-
- script = GET_SEL32V(segMan, objpos, number);
- seg = s->_segMan->getScriptSegment(script);
-
- if (seg > 0)
- numSynonyms = s->_segMan->getScript(seg)->getSynonymsNr();
-
- if (numSynonyms) {
- byte *synonyms = s->_segMan->getScript(seg)->getSynonyms();
-
- if (synonyms) {
- debugC(2, kDebugLevelParser, "Setting %d synonyms for script.%d\n",
- numSynonyms, script);
-
- if (numSynonyms > 16384) {
- error("Segtable corruption: script.%03d has %d synonyms",
- script, numSynonyms);
- /* We used to reset the corrupted value here. I really don't think it's appropriate.
- * Lars */
- } else
- for (int i = 0; i < numSynonyms; i++) {
- synonym_t tmp;
- tmp.replaceant = (int16)READ_LE_UINT16(synonyms + i * 4);
- tmp.replacement = (int16)READ_LE_UINT16(synonyms + i * 4 + 2);
- s->_voc->addSynonym(tmp);
- }
- } else
- warning("Synonyms of script.%03d were requested, but script is not available", script);
-
- }
-
- node = s->_segMan->lookupNode(node->succ);
- }
-
- debugC(2, kDebugLevelParser, "A total of %d synonyms are active now.\n", numSynonyms);
-
- return s->r_acc;
-}
-
-
-
-reg_t kParse(EngineState *s, int argc, reg_t *argv) {
- SegManager *segMan = s->_segMan;
- reg_t stringpos = argv[0];
- Common::String string = s->_segMan->getString(stringpos);
- char *error;
- ResultWordList words;
- reg_t event = argv[1];
- Vocabulary *voc = s->_voc;
-
- s->parser_event = event;
-
- bool res = voc->tokenizeString(words, string.c_str(), &error);
- s->parserIsValid = false; /* not valid */
-
- if (res && !words.empty()) {
- s->_voc->synonymizeTokens(words);
-
- s->r_acc = make_reg(0, 1);
-
-#ifdef DEBUG_PARSER
- debugC(2, kDebugLevelParser, "Parsed to the following blocks:\n", 0);
-
- for (ResultWordList::const_iterator i = words.begin(); i != words.end(); ++i)
- debugC(2, kDebugLevelParser, " Type[%04x] Group[%04x]\n", i->_class, i->_group);
-#endif
-
- int syntax_fail = voc->parseGNF(words);
-
- if (syntax_fail) {
- s->r_acc = make_reg(0, 1);
- PUT_SEL32V(segMan, event, claimed, 1);
-
- invoke_selector(INV_SEL(s->_gameObj, syntaxFail, kStopOnInvalidSelector), 2, s->parser_base, stringpos);
- /* Issue warning */
-
- debugC(2, kDebugLevelParser, "Tree building failed\n");
-
- } else {
- s->parserIsValid = true;
- PUT_SEL32V(segMan, event, claimed, 0);
-
-#ifdef DEBUG_PARSER
- s->_voc->dumpParseTree();
-#endif
- }
-
- } else {
-
- s->r_acc = make_reg(0, 0);
- PUT_SEL32V(segMan, event, claimed, 1);
- if (error) {
- s->_segMan->strcpy(s->parser_base, error);
- debugC(2, kDebugLevelParser, "Word unknown: %s\n", error);
- /* Issue warning: */
-
- invoke_selector(INV_SEL(s->_gameObj, wordFail, kStopOnInvalidSelector), 2, s->parser_base, stringpos);
- free(error);
- return make_reg(0, 1); /* Tell them that it dind't work */
- }
- }
-
- return s->r_acc;
-}
-
-
reg_t kStrEnd(EngineState *s, int argc, reg_t *argv) {
reg_t address = argv[0];
address.offset += s->_segMan->strlen(address);
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index ace1f019aa..17b635f8b9 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -36,11 +36,13 @@ namespace Common {
}
#include "sci/sci.h"
-#include "sci/vocabulary.h"
#include "sci/resource.h"
#include "sci/engine/kernel.h" // for kfunct_sig_pair_t
#include "sci/engine/script.h"
#include "sci/engine/seg_manager.h"
+
+#include "sci/parser/vocabulary.h"
+
#include "sci/sound/audio.h"
#ifdef USE_OLD_MUSIC_FUNCTIONS
#include "sci/sound/iterator/core.h"
diff --git a/engines/sci/module.mk b/engines/sci/module.mk
index 10dc73818d..599f86d425 100644
--- a/engines/sci/module.mk
+++ b/engines/sci/module.mk
@@ -7,10 +7,8 @@ MODULE_OBJS := \
event.o \
resource.o \
sci.o \
- vocabulary.o \
engine/game.o \
engine/gc.o \
- engine/grammar.o \
engine/kernel.o \
engine/kevent.o \
engine/kfile.o \
@@ -20,6 +18,7 @@ MODULE_OBJS := \
engine/kmenu.o \
engine/kmisc.o \
engine/kmovement.o \
+ engine/kparse.o \
engine/kpathing.o \
engine/kscripts.o \
engine/ksound.o \
@@ -51,6 +50,9 @@ MODULE_OBJS := \
graphics/transitions.o \
graphics/view.o \
graphics/windowmgr.o \
+ parser/grammar.o \
+ parser/said.o \
+ parser/vocabulary.o \
sound/audio.o \
sound/midiparser_sci.o \
sound/music.o \
diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/parser/grammar.cpp
index 8c6c93e583..9ee3b8aeaa 100644
--- a/engines/sci/engine/grammar.cpp
+++ b/engines/sci/parser/grammar.cpp
@@ -28,7 +28,7 @@
* that grammar, writing an appropriate node tree if successful.
*/
-#include "sci/vocabulary.h"
+#include "sci/parser/vocabulary.h"
#include "sci/console.h"
#include "common/array.h"
diff --git a/engines/sci/engine/said.cpp b/engines/sci/parser/said.cpp
index 32bd1fcf8d..32bd1fcf8d 100644
--- a/engines/sci/engine/said.cpp
+++ b/engines/sci/parser/said.cpp
diff --git a/engines/sci/engine/said.y b/engines/sci/parser/said.y
index 1a3b2f52c8..1a3b2f52c8 100644
--- a/engines/sci/engine/said.y
+++ b/engines/sci/parser/said.y
diff --git a/engines/sci/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp
index 384530fb3e..5ecea03899 100644
--- a/engines/sci/vocabulary.cpp
+++ b/engines/sci/parser/vocabulary.cpp
@@ -25,7 +25,7 @@
// Main vocabulary support functions and word lookup
-#include "sci/vocabulary.h"
+#include "sci/parser/vocabulary.h"
#include "sci/resource.h"
#include "sci/engine/state.h"
#include "sci/engine/kernel.h"
diff --git a/engines/sci/vocabulary.h b/engines/sci/parser/vocabulary.h
index 00b8780d1c..00b8780d1c 100644
--- a/engines/sci/vocabulary.h
+++ b/engines/sci/parser/vocabulary.h
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 7a09041287..e4cd9b7d70 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -32,7 +32,7 @@
#include "sci/engine/state.h"
#include "sci/engine/kernel.h"
#include "sci/resource.h"
-#include "sci/vocabulary.h"
+#include "sci/parser/vocabulary.h"
#include "sci/decompressor.h"
namespace Sci {