Started on the frontend support for pointer-based length conditions.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 11 Jun 2009 00:25:19 +0000 (00:25 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 11 Jun 2009 00:25:19 +0000 (00:25 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@900 052ea7fc-9027-0410-9066-f65837a77df0

ragel/dotcodegen.cpp
ragel/fsmgraph.h
ragel/parsedata.cpp
ragel/parsedata.h
ragel/parsetree.cpp
ragel/parsetree.h
ragel/rlparse.kh
ragel/rlparse.kl
ragel/rlscan.rl

index dc401df..a61bdb7 100644 (file)
@@ -130,8 +130,8 @@ std::ostream &GraphvizDotGen::ACTION( RedAction *action )
 
 std::ostream &GraphvizDotGen::ONCHAR( Key lowKey, Key highKey )
 {
-       if ( lowKey > keyOps->maxKey ) {
-               GenCondSpace *condSpace = findCondSpace( lowKey, highKey );
+       GenCondSpace *condSpace;
+       if ( lowKey > keyOps->maxKey && (condSpace=findCondSpace(lowKey, highKey) ) ) {
                Key values = ( lowKey - condSpace->baseKey ) / keyOps->alphSize();
 
                lowKey = keyOps->minKey + 
index e74b5c0..1b7d6f5 100644 (file)
@@ -57,6 +57,7 @@ struct StateAp;
 struct FsmAp;
 struct Action;
 struct LongestMatchPart;
+struct LengthDef;
 
 /* State list element for unambiguous access to list element. */
 struct FsmListEl 
index 6dd8492..125e9f7 100644 (file)
@@ -829,8 +829,8 @@ void ParseData::createBuiltin( const char *name, BuiltinMachine builtin )
 {
        Expression *expression = new Expression( builtin );
        Join *join = new Join( expression );
-       JoinOrLm *joinOrLm = new JoinOrLm( join );
-       VarDef *varDef = new VarDef( name, joinOrLm );
+       MachineDef *machineDef = new MachineDef( join );
+       VarDef *varDef = new VarDef( name, machineDef );
        GraphDictEl *graphDictEl = new GraphDictEl( name, varDef );
        graphDict.insert( graphDictEl );
 }
index 3cad47e..3e3bfa6 100644 (file)
@@ -151,6 +151,17 @@ struct NameFrame
        NameInst *prevLocalScope;
 };
 
+struct LengthDef
+{
+       LengthDef( char *name )
+               : name(name) {}
+
+       char *name;
+       LengthDef *prev, *next;
+};
+
+typedef DList<LengthDef> LengthDefList;
+
 /* Class to collect information about the machine during the 
  * parse of input. */
 struct ParseData
@@ -357,6 +368,7 @@ struct ParseData
        KeyOps thisKeyOps;
 
        ExportList exportList;
+       LengthDefList lengthDefList;
 
        CodeGenData *cgd;
 };
index 770810c..b1ce8b7 100644 (file)
@@ -91,7 +91,7 @@ FsmAp *VarDef::walk( ParseData *pd )
        NameFrame nameFrame = pd->enterNameScope( true, 1 );
 
        /* Recurse on the expression. */
-       FsmAp *rtnVal = joinOrLm->walk( pd );
+       FsmAp *rtnVal = machineDef->walk( pd );
        
        /* Do the tranfer of local error actions. */
        LocalErrDictEl *localErrDictEl = pd->localErrDict.find( name );
@@ -103,7 +103,7 @@ FsmAp *VarDef::walk( ParseData *pd )
        /* If the expression below is a join operation with multiple expressions
         * then it just had epsilon transisions resolved. If it is a join
         * with only a single expression then run the epsilon op now. */
-       if ( joinOrLm->type == JoinOrLm::JoinType && joinOrLm->join->exprList.length() == 1 )
+       if ( machineDef->type == MachineDef::JoinType && machineDef->join->exprList.length() == 1 )
                rtnVal->epsilonOp();
 
        /* We can now unset entry points that are not longer used. */
@@ -125,11 +125,11 @@ void VarDef::makeNameTree( const InputLoc &loc, ParseData *pd )
        NameInst *prevNameInst = pd->curNameInst;
        pd->curNameInst = pd->addNameInst( loc, name, false );
 
-       if ( joinOrLm->type == JoinOrLm::LongestMatchType )
+       if ( machineDef->type == MachineDef::LongestMatchType )
                pd->curNameInst->isLongestMatch = true;
 
        /* Recurse. */
-       joinOrLm->makeNameTree( pd );
+       machineDef->makeNameTree( pd );
 
        /* The name scope ends, pop the name instantiation. */
        pd->curNameInst = prevNameInst;
@@ -141,7 +141,7 @@ void VarDef::resolveNameRefs( ParseData *pd )
        NameFrame nameFrame = pd->enterNameScope( true, 1 );
 
        /* Recurse. */
-       joinOrLm->resolveNameRefs( pd );
+       machineDef->resolveNameRefs( pd );
        
        /* The name scope ends, pop the name instantiation. */
        pd->popNameScope( nameFrame );
@@ -524,7 +524,7 @@ FsmAp *LongestMatch::walk( ParseData *pd )
        return rtnVal;
 }
 
-FsmAp *JoinOrLm::walk( ParseData *pd )
+FsmAp *MachineDef::walk( ParseData *pd )
 {
        FsmAp *rtnVal = 0;
        switch ( type ) {
@@ -534,11 +534,16 @@ FsmAp *JoinOrLm::walk( ParseData *pd )
        case LongestMatchType:
                rtnVal = longestMatch->walk( pd );
                break;
+       case LengthDefType:
+               condData->lastCondKey.increment();
+               rtnVal = new FsmAp();
+               rtnVal->concatFsm( condData->lastCondKey );
+               break;
        }
        return rtnVal;
 }
 
-void JoinOrLm::makeNameTree( ParseData *pd )
+void MachineDef::makeNameTree( ParseData *pd )
 {
        switch ( type ) {
        case JoinType:
@@ -547,10 +552,12 @@ void JoinOrLm::makeNameTree( ParseData *pd )
        case LongestMatchType:
                longestMatch->makeNameTree( pd );
                break;
+       case LengthDefType:
+               break;
        }
 }
 
-void JoinOrLm::resolveNameRefs( ParseData *pd )
+void MachineDef::resolveNameRefs( ParseData *pd )
 {
        switch ( type ) {
        case JoinType:
@@ -559,6 +566,8 @@ void JoinOrLm::resolveNameRefs( ParseData *pd )
        case LongestMatchType:
                longestMatch->resolveNameRefs( pd );
                break;
+       case LengthDefType:
+               break;
        }
 }
 
index 88373a3..dd38678 100644 (file)
@@ -66,11 +66,12 @@ struct FactorWithNeg;
 struct Factor;
 struct Expression;
 struct Join;
-struct JoinOrLm;
+struct MachineDef;
 struct LongestMatch;
 struct LongestMatchPart;
 struct LmPartList;
 struct Range;
+struct LengthDef;
 
 /* Type of augmentation. Describes locations in the machine. */
 enum AugType
@@ -221,8 +222,8 @@ struct PriorityAug
  */
 struct VarDef
 {
-       VarDef( const char *name, JoinOrLm *joinOrLm )
-               : name(name), joinOrLm(joinOrLm), isExport(false) { }
+       VarDef( const char *name, MachineDef *machineDef )
+               : name(name), machineDef(machineDef), isExport(false) { }
        
        /* Parse tree traversal. */
        FsmAp *walk( ParseData *pd );
@@ -230,7 +231,7 @@ struct VarDef
        void resolveNameRefs( ParseData *pd );
 
        const char *name;
-       JoinOrLm *joinOrLm;
+       MachineDef *machineDef;
        bool isExport;
 };
 
@@ -322,17 +323,20 @@ struct LongestMatch
 /* List of Expressions. */
 typedef DList<Expression> ExprList;
 
-struct JoinOrLm
+struct MachineDef
 {
        enum Type {
                JoinType,
-               LongestMatchType
+               LongestMatchType,
+               LengthDefType
        };
 
-       JoinOrLm( Join *join ) : 
-               join(join), longestMatch(0), type(JoinType) {}
-       JoinOrLm( LongestMatch *longestMatch ) :
-               join(0), longestMatch(longestMatch), type(LongestMatchType) {}
+       MachineDef( Join *join )
+               : join(join), longestMatch(0), lengthDef(0), type(JoinType) {}
+       MachineDef( LongestMatch *longestMatch )
+               : join(0), longestMatch(longestMatch), lengthDef(0), type(LongestMatchType) {}
+       MachineDef( LengthDef *lengthDef )
+               : join(0), longestMatch(0), lengthDef(lengthDef), type(LengthDefType) {}
 
        FsmAp *walk( ParseData *pd );
        void makeNameTree( ParseData *pd );
@@ -340,6 +344,7 @@ struct JoinOrLm
        
        Join *join;
        LongestMatch *longestMatch;
+       LengthDef *lengthDef;
        Type type;
 };
 
index 4fbf082..899bbbc 100644 (file)
@@ -93,7 +93,7 @@ struct Parser
        token KW_Machine, KW_Include, KW_Import, KW_Write, KW_Action, KW_AlphType,
                KW_Range, KW_GetKey, KW_Include, KW_Write, KW_Machine, KW_InWhen,
                KW_When, KW_OutWhen, KW_Eof, KW_Err, KW_Lerr, KW_To, KW_From,
-               KW_Export, KW_PrePush, KW_PostPop;
+               KW_Export, KW_PrePush, KW_PostPop, KW_Length;
 
        # Specials in code blocks.
        token KW_Break, KW_Exec, KW_Hold, KW_PChar, KW_Char, KW_Goto, KW_Call,
@@ -117,7 +117,7 @@ struct Parser
 
        int token( InputLoc &loc, int tokId, char *tokstart, int toklen );
        void tryMachineDef( InputLoc &loc, char *name, 
-               JoinOrLm *joinOrLm, bool isInstance );
+               MachineDef *machineDef, bool isInstance );
 
        /* Report an error encountered by the parser. */
        ostream &parse_error( int tokId, Token &token );
index 79e816a..36b8777 100644 (file)
@@ -54,6 +54,18 @@ statement: variable_spec commit;
 statement: export_block commit;
 statement: pre_push_spec commit;
 statement: post_pop_spec commit;
+statement: length_spec commit;
+
+length_spec:
+       KW_Length TK_Word ';'
+       final {
+               LengthDef *lengthDef = new LengthDef( $2->data );
+               pd->lengthDefList.append( lengthDef );
+
+               /* Generic creation of machine for instantiation and assignment. */
+               MachineDef *machineDef = new MachineDef( lengthDef );
+               tryMachineDef( $2->loc, $2->data, machineDef, false );
+       };
 
 pre_push_spec:
        KW_PrePush '{' inline_block '}' 
@@ -108,8 +120,8 @@ assignment:
                }
 
                /* Generic creation of machine for instantiation and assignment. */
-               JoinOrLm *joinOrLm = new JoinOrLm( $4->join );
-               tryMachineDef( $2->token.loc, $2->token.data, joinOrLm, isInstance );
+               MachineDef *machineDef = new MachineDef( $4->join );
+               tryMachineDef( $2->token.loc, $2->token.data, machineDef, isInstance );
 
                if ( $1->isSet )
                        exportContext.remove( exportContext.length()-1 );
@@ -120,14 +132,14 @@ assignment:
 instantiation: 
        opt_export machine_name TK_ColonEquals join_or_lm ';' final {
                /* Generic creation of machine for instantiation and assignment. */
-               tryMachineDef( $2->token.loc, $2->token.data, $4->joinOrLm, true );
+               tryMachineDef( $2->token.loc, $2->token.data, $4->machineDef, true );
 
                if ( $1->isSet )
                        exportContext.remove( exportContext.length()-1 );
 
                /* Pass a location to join_or_lm */
-               if ( $4->joinOrLm->join != 0 )
-                       $4->joinOrLm->join->loc = $3->loc;
+               if ( $4->machineDef->join != 0 )
+                       $4->machineDef->join->loc = $3->loc;
        };
 
 type token_type
@@ -230,12 +242,12 @@ opt_whitespace: ;
 
 nonterm join_or_lm
 {
-       JoinOrLm *joinOrLm;
+       MachineDef *machineDef;
 };
 
 join_or_lm: 
        join final {
-               $$->joinOrLm = new JoinOrLm( $1->join );
+               $$->machineDef = new MachineDef( $1->join );
        };
 join_or_lm:
        TK_BarStar lm_part_list '*' '|' final {
@@ -245,7 +257,7 @@ join_or_lm:
                pd->lmList.append( lm );
                for ( LmPartList::Iter lmp = *($2->lmPartList); lmp.lte(); lmp++ )
                        lmp->longestMatch = lm;
-               $$->joinOrLm = new JoinOrLm( lm );
+               $$->machineDef = new MachineDef( lm );
        };
 
 nonterm lm_part_list
@@ -1448,12 +1460,12 @@ int Parser::parseLangEl( int type, const Token *token )
 }
 
 void Parser::tryMachineDef( InputLoc &loc, char *name, 
-               JoinOrLm *joinOrLm, bool isInstance )
+               MachineDef *machineDef, bool isInstance )
 {
        GraphDictEl *newEl = pd->graphDict.insert( name );
        if ( newEl != 0 ) {
                /* New element in the dict, all good. */
-               newEl->value = new VarDef( name, joinOrLm );
+               newEl->value = new VarDef( name, machineDef );
                newEl->isInstance = isInstance;
                newEl->loc = loc;
                newEl->value->isExport = exportContext[exportContext.length()-1];
index 6dc2804..5b95468 100644 (file)
@@ -934,6 +934,7 @@ ifstream *Scanner::tryOpenInclude( char **pathChecks, long &found )
 
        # Parser definitions. 
        parser_def := |*
+               'length_cond' => { token( KW_Length ); };
                'machine' => { token( KW_Machine ); };
                'include' => { token( KW_Include ); };
                'import' => { token( KW_Import ); };