From 91bc133319349d2b0a3978461140a6f65964922d Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sun, 13 Nov 2011 04:48:00 +0000 Subject: Factored out the PreEof blocks. There are actually no active test cases for this, that's okay, very similar to others. Can be fixed later if necessary. refs #332 --- colm/bytecode.c | 16 ++++++++++++++++ colm/fsmrun.c | 35 ++++++++++++++--------------------- colm/pdarun.h | 5 ++++- 3 files changed, 34 insertions(+), 22 deletions(-) (limited to 'colm') diff --git a/colm/bytecode.c b/colm/bytecode.c index eddac588..b759bc72 100644 --- a/colm/bytecode.c +++ b/colm/bytecode.c @@ -911,6 +911,22 @@ void callParseBlock( Code **pinstr, Tree ***psp, long pcr, Program *prg, /* Call execution. */ *pinstr = exec->code; } + else if ( pcr == PcrPreEof ) { + /* Execute the translation. */ + initGenerationExecution( &pdaRun->exec, prg, &pdaRun->rcodeCollect, pdaRun, fsmRun, + pdaRun->frameId, prg->rtd->frameInfo[pdaRun->frameId].codeWV, + 0, pdaRun->tokenId, 0, fsmRun->mark ); + + /* Push the instruction. */ + vm_push( (SW)*pinstr ); + + /* Push the LHS onto the stack. */ + vm_push( 0 ); + + /* Call execution. */ + *pinstr = exec->code; + } + *psp = sp; } diff --git a/colm/fsmrun.c b/colm/fsmrun.c index 84e7ea6c..1df42bd8 100644 --- a/colm/fsmrun.c +++ b/colm/fsmrun.c @@ -1030,35 +1030,28 @@ case PcrStart: if ( pdaRun->tokenId == SCAN_TRY_AGAIN_LATER ) break; - Kid *input = 0; + pdaRun->parseInput = 0; /* Check for EOF. */ if ( pdaRun->tokenId == SCAN_EOF ) { inputStream->eofSent = true; - input = sendEof( prg, sp, inputStream, fsmRun, pdaRun ); + pdaRun->parseInput = sendEof( prg, sp, inputStream, fsmRun, pdaRun ); - int ctxDepParsing = prg->ctxDepParsing; - long frameId = prg->rtd->regionInfo[fsmRun->region].eofFrameId; - if ( ctxDepParsing && frameId >= 0 ) { + pdaRun->frameId = prg->rtd->regionInfo[fsmRun->region].eofFrameId; + if ( prg->ctxDepParsing && pdaRun->frameId >= 0 ) { debug( REALM_PARSE, "HAVE PRE_EOF BLOCK\n" ); - /* Get the code for the pre-eof block. */ - Code *code = prg->rtd->frameInfo[frameId].codeWV; - - /* Execute the translation. */ - Execution exec; - initGenerationExecution( &exec, prg, &pdaRun->rcodeCollect, pdaRun, fsmRun, - frameId, code, 0, pdaRun->tokenId, 0, fsmRun->mark ); - generationExecution( &exec, sp ); +return PcrPreEof; +case PcrPreEof: /* * Need a no-token. */ - addNoToken( prg, sp, fsmRun, pdaRun, inputStream, frameId, pdaRun->tokenId, 0 ); + addNoToken( prg, sp, fsmRun, pdaRun, inputStream, pdaRun->frameId, pdaRun->tokenId, 0 ); } } else if ( pdaRun->tokenId == SCAN_UNDO ) { - /* Fall through with input = 0. FIXME: Do we need to send back ignore? */ + /* Fall through with parseInput = 0. FIXME: Do we need to send back ignore? */ } else if ( pdaRun->tokenId == SCAN_ERROR ) { /* Scanner error, maybe retry. */ @@ -1095,11 +1088,11 @@ case PcrStart: } else if ( pdaRun->tokenId == SCAN_LANG_EL ) { /* A named language element (parsing colm program). */ - input = sendNamedLangEl( prg, sp, pdaRun, fsmRun, inputStream ); + pdaRun->parseInput = sendNamedLangEl( prg, sp, pdaRun, fsmRun, inputStream ); } else if ( pdaRun->tokenId == SCAN_TREE ) { /* A tree already built. */ - input = sendTree( prg, sp, pdaRun, fsmRun, inputStream ); + pdaRun->parseInput = sendTree( prg, sp, pdaRun, fsmRun, inputStream ); } else if ( pdaRun->tokenId == SCAN_IGNORE ) { /* A tree to ignore. */ @@ -1143,16 +1136,16 @@ case PcrGeneration: } else { /* Is a plain token. */ - input = sendToken( prg, sp, inputStream, fsmRun, pdaRun, pdaRun->tokenId ); + pdaRun->parseInput = sendToken( prg, sp, inputStream, fsmRun, pdaRun, pdaRun->tokenId ); } - if ( input != 0 ) { + if ( pdaRun->parseInput != 0 ) { /* Send the token to the parser. */ - attachIgnore( prg, sp, pdaRun, input ); + attachIgnore( prg, sp, pdaRun, pdaRun->parseInput ); } assert( pdaRun->input == 0 ); - pdaRun->input = input; + pdaRun->input = pdaRun->parseInput; long ptr = parseToken( prg, sp, pdaRun, fsmRun, inputStream, PcrStart ); diff --git a/colm/pdarun.h b/colm/pdarun.h index 51c7a059..0a89bb7e 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -251,6 +251,8 @@ typedef struct _PdaRun /* Data we added when factoring out the token generation action. */ int tokenId; Head *tokdata; + int frameId; + Kid *parseInput; } PdaRun; void rtCodeVectReplace( RtCodeVect *vect, long pos, const Code *val, long len ); @@ -319,7 +321,8 @@ int pdaRunGetNextRegion( PdaRun *pdaRun, int offset ); #define PcrStart 1 #define PcrReduction 2 #define PcrGeneration 3 -#define PcrDone 4 +#define PcrPreEof 4 +#define PcrDone 5 long parseToken( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, long entry ); -- cgit v1.2.1