"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/parsetree.cc" between
ragel-7.0.0.9.tar.gz and ragel-7.0.0.10.tar.gz

About:

parsetree.cc  (ragel-7.0.0.9):parsetree.cc  (ragel-7.0.0.10)
/* /*
* Copyright 2001-2006 Adrian Thurston <thurston@complang.org> * Copyright 2001-2006 Adrian Thurston <thurston@colm.net>
*/
/* This file is part of Ragel.
* *
* Ragel is free software; you can redistribute it and/or modify * Permission is hereby granted, free of charge, to any person obtaining a copy
* it under the terms of the GNU General Public License as published by * of this software and associated documentation files (the "Software"), to
* the Free Software Foundation; either version 2 of the License, or * deal in the Software without restriction, including without limitation the
* (at your option) any later version. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* Ragel is distributed in the hope that it will be useful, * The above copyright notice and this permission notice shall be included in al
* but WITHOUT ANY WARRANTY; without even the implied warranty of l
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * copies or substantial portions of the Software.
* GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* along with Ragel; if not, write to the Free Software * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <inputdata.h> #include <inputdata.h>
skipping to change at line 1664 skipping to change at line 1665
FsmRes FactorWithRep::walk( ParseData *pd ) FsmRes FactorWithRep::walk( ParseData *pd )
{ {
switch ( type ) { switch ( type ) {
case StarType: { case StarType: {
/* Evaluate the FactorWithRep. */ /* Evaluate the FactorWithRep. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying kleene star to a machin e that " pd->id->warning(loc) << "applying kleene star to a machin e that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
factorTree.fsm->unsetFinState( factorTree.fsm->startState ); factorTree.fsm->unsetFinState( factorTree.fsm->startState );
} }
return FsmAp::starOp( factorTree.fsm ); return FsmAp::starOp( factorTree.fsm );
} }
case StarStarType: { case StarStarType: {
/* Evaluate the FactorWithRep. */ /* Evaluate the FactorWithRep. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying kleene star to a machin e that " pd->id->warning(loc) << "applying kleene star to a machin e that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
/* Set up the prior descs. All gets priority one, whereas leaving gets /* Set up the prior descs. All gets priority one, whereas leaving gets
* priority zero. Make a unique key so that these priorities don' t * priority zero. Make a unique key so that these priorities don' t
* interfere with any priorities set by the user. */ * interfere with any priorities set by the user. */
priorDescs[0].key = pd->fsmCtx->nextPriorKey++; priorDescs[0].key = pd->fsmCtx->nextPriorKey++;
priorDescs[0].priority = 1; priorDescs[0].priority = 1;
factorTree.fsm->allTransPrior( pd->fsmCtx->curPriorOrd++, &priorD escs[0] ); factorTree.fsm->allTransPrior( pd->fsmCtx->curPriorOrd++, &priorD escs[0] );
skipping to change at line 1719 skipping to change at line 1712
return FsmAp::questionOp( factorTree.fsm ); return FsmAp::questionOp( factorTree.fsm );
} }
case PlusType: { case PlusType: {
/* Evaluate the FactorWithRep. */ /* Evaluate the FactorWithRep. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying plus operator to a mach ine that " pd->id->warning(loc) << "applying plus operator to a mach ine that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
return FsmAp::plusOp( factorTree.fsm ); return FsmAp::plusOp( factorTree.fsm );
} }
case ExactType: { case ExactType: {
/* Evaluate the first FactorWithRep. */ /* Evaluate the first FactorWithRep. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
/* Get an int from the repetition amount. */ /* Get an int from the repetition amount. */
if ( lowerRep == 0 ) { if ( lowerRep == 0 ) {
/* No copies. Don't need to evaluate the factorWithRep. /* No copies. Don't need to evaluate the factorWithRep.
* This Defeats the purpose so give a warning. */ * This Defeats the purpose so give a warning. */
if ( pd->id->inLibRagel )
return FsmRes( FsmRes::RepetitionError() );
pd->id->warning(loc) << "exactly zero repetitions results " pd->id->warning(loc) << "exactly zero repetitions results "
"in the null machine" << endl; "in the null machine" << endl;
} }
else { else {
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError()
);
}
pd->id->warning(loc) << "applying repetition to a machine that " pd->id->warning(loc) << "applying repetition to a machine that "
"accepts zero length word" << end l; "accepts zero length word" << end l;
} }
} }
/* Handles the n == 0 case. */ /* Handles the n == 0 case. */
return FsmAp::exactRepeatOp( factorTree.fsm, lowerRep ); return FsmAp::exactRepeatOp( factorTree.fsm, lowerRep );
} }
case MaxType: { case MaxType: {
/* Evaluate the first FactorWithRep. */ /* Evaluate the first FactorWithRep. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
/* Get an int from the repetition amount. */ /* Get an int from the repetition amount. */
if ( upperRep == 0 ) { if ( upperRep == 0 ) {
/* No copies. Don't need to evaluate the factorWithRep. /* No copies. Don't need to evaluate the factorWithRep.
* This Defeats the purpose so give a warning. */ * This Defeats the purpose so give a warning. */
if ( pd->id->inLibRagel )
return FsmRes( FsmRes::RepetitionError() );
pd->id->warning(loc) << "max zero repetitions results " pd->id->warning(loc) << "max zero repetitions results "
"in the null machine" << endl; "in the null machine" << endl;
return FsmRes( FsmRes::Fsm(), FsmAp::lambdaFsm( pd->fsmCt x ) ); return FsmRes( FsmRes::Fsm(), FsmAp::lambdaFsm( pd->fsmCt x ) );
} }
else { else {
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError()
);
}
pd->id->warning(loc) << "applying max repetition to a machine that " pd->id->warning(loc) << "applying max repetition to a machine that "
"accepts zero length word" << end l; "accepts zero length word" << end l;
} }
} }
/* Do the repetition on the machine. Handles the n == 0 case. */ /* Do the repetition on the machine. Handles the n == 0 case. */
return FsmAp::maxRepeatOp( factorTree.fsm, upperRep ); return FsmAp::maxRepeatOp( factorTree.fsm, upperRep );
} }
case MinType: { case MinType: {
/* Evaluate the repeated machine. */ /* Evaluate the repeated machine. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying min repetition to a mac hine that " pd->id->warning(loc) << "applying min repetition to a mac hine that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
return FsmAp::minRepeatOp( factorTree.fsm, lowerRep ); return FsmAp::minRepeatOp( factorTree.fsm, lowerRep );
} }
case RangeType: { case RangeType: {
/* Check for bogus range. */ /* Check for bogus range. */
if ( upperRep - lowerRep < 0 ) { if ( upperRep - lowerRep < 0 ) {
pd->id->error(loc) << "invalid range repetition" << endl; pd->id->error(loc) << "invalid range repetition" << endl;
skipping to change at line 1826 skipping to change at line 1797
} }
/* Now need to evaluate the repeated machine. */ /* Now need to evaluate the repeated machine. */
FsmRes factorTree = factorWithRep->walk( pd ); FsmRes factorTree = factorWithRep->walk( pd );
if ( !factorTree.success() ) if ( !factorTree.success() )
return factorTree; return factorTree;
if ( lowerRep == 0 && upperRep == 0 ) { if ( lowerRep == 0 && upperRep == 0 ) {
/* No copies. Don't need to evaluate the factorWithRep. This /* No copies. Don't need to evaluate the factorWithRep. This
* defeats the purpose so give a warning. */ * defeats the purpose so give a warning. */
if ( pd->id->inLibRagel )
return FsmRes( FsmRes::RepetitionError() );
pd->id->warning(loc) << "zero to zero repetitions results " pd->id->warning(loc) << "zero to zero repetitions results "
"in the null machine" << endl; "in the null machine" << endl;
} }
else { else {
if ( factorTree.fsm->startState->isFinState() ) { if ( factorTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete factorTree.fsm;
return FsmRes( FsmRes::RepetitionError()
);
}
pd->id->warning(loc) << "applying range repetitio n to a machine that " pd->id->warning(loc) << "applying range repetitio n to a machine that "
"accepts zero length word" << end l; "accepts zero length word" << end l;
} }
} }
return FsmAp::rangeRepeatOp( factorTree.fsm, lowerRep, upperRep ) ; return FsmAp::rangeRepeatOp( factorTree.fsm, lowerRep, upperRep ) ;
} }
case FactorWithNegType: { case FactorWithNegType: {
/* Evaluate the Factor. Pass it up. */ /* Evaluate the Factor. Pass it up. */
return factorWithNeg->walk( pd ); return factorWithNeg->walk( pd );
skipping to change at line 2025 skipping to change at line 1989
res.fsm->verifyIntegrity(); res.fsm->verifyIntegrity();
return res; return res;
} }
case CondStar: { case CondStar: {
FsmRes exprTree = expression->walk( pd ); FsmRes exprTree = expression->walk( pd );
if ( !exprTree.success() ) if ( !exprTree.success() )
return exprTree; return exprTree;
if ( exprTree.fsm->startState->isFinState() ) { if ( exprTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete exprTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying plus operator to a mach ine that " pd->id->warning(loc) << "applying plus operator to a mach ine that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
return FsmAp::condStar( exprTree.fsm, repId, action1, action2, ac tion3, action4 ); return FsmAp::condStar( exprTree.fsm, repId, action1, action2, ac tion3, action4 );
} }
case CondPlus: { case CondPlus: {
FsmRes exprTree = expression->walk( pd ); FsmRes exprTree = expression->walk( pd );
if ( !exprTree.success() ) if ( !exprTree.success() )
return exprTree; return exprTree;
if ( exprTree.fsm->startState->isFinState() ) { if ( exprTree.fsm->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete exprTree.fsm;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying plus operator to a mach ine that " pd->id->warning(loc) << "applying plus operator to a mach ine that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
return FsmAp::condPlus( exprTree.fsm, repId, action1, action2, ac tion3, action4 ); return FsmAp::condPlus( exprTree.fsm, repId, action1, action2, ac tion3, action4 );
}} }}
return FsmRes( FsmRes::InternalError() ); return FsmRes( FsmRes::InternalError() );
} }
skipping to change at line 2303 skipping to change at line 2259
FsmRes res = FsmAp::subtractOp( rtnVal, fsm ); FsmRes res = FsmAp::subtractOp( rtnVal, fsm );
rtnVal = res.fsm; rtnVal = res.fsm;
rtnVal->minimizePartition2(); rtnVal->minimizePartition2();
break; break;
} }
} }
/* If the item is followed by a star, then apply the star op. */ /* If the item is followed by a star, then apply the star op. */
if ( star ) { if ( star ) {
if ( rtnVal->startState->isFinState() ) { if ( rtnVal->startState->isFinState() ) {
if ( pd->id->inLibRagel ) {
delete rtnVal;
return FsmRes( FsmRes::RepetitionError() );
}
pd->id->warning(loc) << "applying kleene star to a machin e that " pd->id->warning(loc) << "applying kleene star to a machin e that "
"accepts zero length word" << endl; "accepts zero length word" << endl;
} }
FsmRes res = FsmAp::starOp( rtnVal ); FsmRes res = FsmAp::starOp( rtnVal );
rtnVal = res.fsm; rtnVal = res.fsm;
rtnVal->minimizePartition2(); rtnVal->minimizePartition2();
} }
return FsmRes( FsmRes::Fsm(), rtnVal ); return FsmRes( FsmRes::Fsm(), rtnVal );
 End of changes. 17 change blocks. 
68 lines changed or deleted 17 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS