summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2012-05-02 22:14:30 -0400
committerAdrian Thurston <thurston@complang.org>2012-05-04 22:09:00 -0400
commitf370c2102bc0e01b316e971069e1b1af946b8262 (patch)
tree070d6bee8b8e5c640c2c73ad8af7d67200944871
parent07a25c1523caed17bc26a586ffe85e785393f23e (diff)
downloadcolm-f370c2102bc0e01b316e971069e1b1af946b8262.tar.gz
Testing out a shadow tree.
The existing parse tree retains current functionality. It contains the shadow, which is the data tree and will be exported by the parse. Testing method: when the tree is submitted for parsing a copy into the shadow is done. When shifting and reducing we need to manage the shadow tree's pointers. Basics works. No ignore tokens.
-rw-r--r--colm/pdarun.c48
-rw-r--r--colm/tree.h2
2 files changed, 46 insertions, 4 deletions
diff --git a/colm/pdarun.c b/colm/pdarun.c
index f1793bc7..826ff4de 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -1164,6 +1164,14 @@ case PcrGeneration:
if ( pdaRun->parseInput != 0 )
transferReverseCode( pdaRun, pdaRun->parseInput->tree );
+ if ( pdaRun->parseInput != 0 ) {
+ Kid *oldNextDown = 0, *newNextDown = 0;
+ Tree *newTree = copyTree( prg, pdaRun->parseInput->tree, oldNextDown, &newNextDown );
+ treeUpref( newTree );
+ pt(pdaRun->parseInput->tree)->shadow = treeAllocate( prg );
+ pt(pdaRun->parseInput->tree)->shadow->tree = newTree;
+ }
+
long pcr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, PcrStart );
while ( pcr != PcrDone ) {
@@ -1232,10 +1240,15 @@ Tree *getParsedRoot( PdaRun *pdaRun, int stop )
{
if ( pdaRun->parseError )
return 0;
- else if ( stop )
- return pdaRun->stackTop->tree;
- else
- return pdaRun->stackTop->next->tree;
+ else if ( stop ) {
+ if ( pt(pdaRun->stackTop->tree)->shadow != 0 )
+ return pt(pdaRun->stackTop->tree)->shadow->tree;
+ }
+ else {
+ if ( pt(pdaRun->stackTop->next->tree)->shadow != 0 )
+ return pt(pdaRun->stackTop->next->tree)->shadow->tree;
+ }
+ return 0;
}
void clearPdaRun( Program *prg, Tree **sp, PdaRun *pdaRun )
@@ -1646,9 +1659,14 @@ again:
pdaRun->parseInput = pdaRun->parseInput->next;
pt(pdaRun->lel->tree)->state = pdaRun->curState;
+
+ if ( pt(pdaRun->lel->tree)->shadow != 0 && pt(pdaRun->stackTop->tree)->shadow != 0 )
+ pt(pdaRun->lel->tree)->shadow->next = pt(pdaRun->stackTop->tree)->shadow;
+
pdaRun->lel->next = pdaRun->stackTop;
pdaRun->stackTop = pdaRun->lel;
+
/* If its a token then attach ignores and record it in the token list
* of the next ignore attachment to use. */
if ( pdaRun->lel->tree->id < prg->rtd->firstNonTermId ) {
@@ -1719,6 +1737,13 @@ again:
pt(pdaRun->redLel->tree)->retryUpper = pt(pdaRun->lel->tree)->retryLower;
pt(pdaRun->lel->tree)->retryLower = 0;
+ pt(pdaRun->redLel->tree)->shadow = kidAllocate( prg );
+ pt(pdaRun->redLel->tree)->shadow->tree = (Tree*)parseTreeAllocate( prg );
+ pt(pdaRun->redLel->tree)->shadow->tree->flags |= AF_PARSE_TREE;
+ pt(pdaRun->redLel->tree)->shadow->tree->refs = 1;
+ pt(pdaRun->redLel->tree)->shadow->tree->id = prg->rtd->prodInfo[pdaRun->reduction].lhsId;
+ pt(pdaRun->redLel->tree)->shadow->tree->prodNum = prg->rtd->prodInfo[pdaRun->reduction].prodNum;
+
/* Allocate the attributes. */
objectLength = prg->rtd->lelInfo[pdaRun->redLel->tree->id].objectLength;
attrs = allocAttrs( prg, objectLength );
@@ -1747,6 +1772,21 @@ again:
pdaRun->redLel->tree->child = kidListConcat( attrs, child );
+ /* SHADOW */
+ Kid *l = 0;
+ Kid *c = pdaRun->redLel->tree->child;
+ if ( c != 0 ) {
+ pt(pdaRun->redLel->tree)->shadow->tree->child = pt(c->tree)->shadow;
+ l = c;
+ c = c->next;
+ while ( c != 0 ) {
+ pt(l->tree)->shadow->next = pt(c->tree)->shadow;
+ l = c;
+ c = c->next;
+ }
+ pt(l->tree)->shadow->next = 0;
+ }
+
debug( REALM_PARSE, "reduced: %s rhsLen %d\n",
prg->rtd->prodInfo[pdaRun->reduction].name, rhsLen );
if ( action[1] == 0 )
diff --git a/colm/tree.h b/colm/tree.h
index b4e5eb19..ece3845d 100644
--- a/colm/tree.h
+++ b/colm/tree.h
@@ -123,6 +123,8 @@ typedef struct _ParseTree
/* FIXME: unify probably. */
char retryLower;
char retryUpper;
+
+ Kid *shadow;
} ParseTree;
typedef struct _Int