summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2008-11-22 22:41:46 +0000
committerAdrian Thurston <thurston@complang.org>2008-11-22 22:41:46 +0000
commit9913736da5dbcd240f0f605ee1b73833e01bd5f8 (patch)
tree771da95dce6cebf66c039f9332f0140b88eec785
parent0960b48b7404eefc4d4bb1e14a38572aa095b43e (diff)
downloadcolm-9913736da5dbcd240f0f605ee1b73833e01bd5f8.tar.gz
Removed the parse algorithm data from the Tree structure. Not sending ignore
tokens as parse trees. After a reduction action make sure the lhs is a full parse tree, as must be done in the send function. All entry points into the parsing algorithm must be protected in this way.
-rw-r--r--colm/bytecode.cpp16
-rw-r--r--colm/bytecode.h3
-rw-r--r--colm/fsmrun.cpp3
-rw-r--r--colm/pdarun.cpp1
-rw-r--r--colm/pdarun.h10
-rw-r--r--colm/tree.cpp21
6 files changed, 34 insertions, 20 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp
index ea5c7cb7..28766f39 100644
--- a/colm/bytecode.cpp
+++ b/colm/bytecode.cpp
@@ -77,21 +77,25 @@ using std::endl;
i |= ((Word) *instr++) << 8; \
} while(0)
-/* Type conversions. */
-
-void send( Tree **root, Program *prg, PdaRun *parser, Tree *tree, bool ignore )
+Tree *prep_parse_tree( Program *prg, Tree *tree )
{
/* If the tree was produced by a parsing function then we need to send a
* copy of it because the parsing that we are about to do requires fresh
* parsing algorithm data. */
- if ( tree->flags & AF_PARSED ) {
+ if ( !(tree->flags & AF_PARSE_TREE) || tree->flags & AF_PARSED ) {
#ifdef COLM_LOG_BYTECODE
- cerr << "copying tree in send because alg is set" << endl;
+ cerr << "copying tree in send function" << endl;
#endif
Kid *unused = 0;
- tree = copy_real_tree( prg, tree, 0, unused );
+ tree = copy_real_tree( prg, tree, 0, unused, true );
tree_upref( tree );
}
+ return tree;
+}
+
+void send( Tree **root, Program *prg, PdaRun *parser, Tree *tree, bool ignore )
+{
+ tree = prep_parse_tree( prg, tree );
if ( tree->id >= prg->rtd->firstNonTermId )
tree->id = prg->rtd->lelInfo[tree->id].termDupId;
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 5a849da5..51bc9f5e 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -475,9 +475,10 @@ void ignore_data( Tree *tree, char *dest );
long ignore_length( Tree *tree );
Tree *split_tree( Program *prg, Tree *t );
Tree *copy_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown );
-Tree *copy_real_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown );
+Tree *copy_real_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown, bool parsed );
Tree *make_tree( Tree **root, Program *prg, long nargs );
Tree *make_token( Tree **root, Program *prg, long nargs );
+Tree *prep_parse_tree( Program *prg, Tree *tree );
void print_tree( Tree **&sp, Program *prg, Tree *tree );
void print_tree( ostream &out, Tree **&sp, Program *prg, Tree *tree );
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index e26d7541..10ae7dc0 100644
--- a/colm/fsmrun.cpp
+++ b/colm/fsmrun.cpp
@@ -624,8 +624,7 @@ void FsmRun::sendIgnore( long id )
update_position( this, tokstart, length );
tokstart = 0;
- Tree *tree = (Tree*)prg->parseTreePool.allocate();
- tree->flags |= AF_PARSE_TREE;
+ Tree *tree = prg->treePool.allocate();
tree->refs = 1;
tree->id = id;
tree->tokdata = ignoreStr;
diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp
index 450d962c..6d25883e 100644
--- a/colm/pdarun.cpp
+++ b/colm/pdarun.cpp
@@ -450,6 +450,7 @@ again:
/* Transfer the lhs from the environment to redLel. It is uprefed
* while in the environment. */
redLel->tree = execution.lhs;
+ redLel->tree = prep_parse_tree( prg, redLel->tree );
/* If the lhs was saved and it changed then we need to restore the
* original upon backtracking, otherwise downref since we took a
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 93fc80a6..f1a0b64a 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -64,11 +64,11 @@ struct Tree
Head *tokdata;
/* Parsing algorithm. */
- long state;
- long region;
- char causeReduce;
- char retry_lower;
- char retry_upper;
+// long state;
+// long region;
+// char causeReduce;
+// char retry_lower;
+// char retry_upper;
};
struct ParseTree
diff --git a/colm/tree.cpp b/colm/tree.cpp
index 7c624e2a..c9625fb5 100644
--- a/colm/tree.cpp
+++ b/colm/tree.cpp
@@ -621,13 +621,19 @@ void stream_free( Program *prg, Stream *s )
prg->mapElPool.free( (MapEl*)s );
}
-Tree *copy_real_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown )
+Tree *copy_real_tree( Program *prg, Tree *tree, Kid *oldNextDown,
+ Kid *&newNextDown, bool parseTree )
{
- assert( tree->refs >= 2 );
-
/* Need to keep a lookout for next down. If
* copying it, return the copy. */
- Tree *newTree = prg->treePool.allocate();
+ Tree *newTree;
+ if ( parseTree ) {
+ newTree = (Tree*) prg->parseTreePool.allocate();
+ newTree->flags |= AF_PARSE_TREE;
+ }
+ else {
+ newTree = prg->treePool.allocate();
+ }
newTree->id = tree->id;
newTree->tokdata = string_copy( prg, tree->tokdata );
@@ -735,6 +741,8 @@ Map *copy_map( Program *prg, Map *map, Kid *oldNextDown, Kid *&newNextDown )
Tree *copy_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown )
{
+ assert( tree->refs >= 2 );
+
LangElInfo *lelInfo = prg->rtd->lelInfo;
long genericId = lelInfo[tree->id].genericId;
if ( genericId > 0 ) {
@@ -754,8 +762,9 @@ Tree *copy_tree( Program *prg, Tree *tree, Kid *oldNextDown, Kid *&newNextDown )
assert(false);
else if ( tree->id == LEL_ID_STR )
assert(false);
- else
- tree = copy_real_tree( prg, tree, oldNextDown, newNextDown );
+ else {
+ tree = copy_real_tree( prg, tree, oldNextDown, newNextDown, false );
+ }
assert( tree->refs == 0 );
return tree;