diff options
-rw-r--r-- | src/compiler.cc | 8 | ||||
-rw-r--r-- | src/lmparse.kl | 12 | ||||
-rw-r--r-- | src/parsetree.cc | 4 | ||||
-rw-r--r-- | src/parsetree.h | 37 |
4 files changed, 43 insertions, 18 deletions
diff --git a/src/compiler.cc b/src/compiler.cc index c1e775f2..9ca947b7 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -230,6 +230,8 @@ FsmGraph *makeBuiltin( BuiltinMachine builtin, Compiler *pd ) bool isSigned = keyOps->isSigned; switch ( builtin ) { + case BT_None: + break;; case BT_Any: { /* All characters. */ retFsm = dotFsm( pd ); @@ -692,7 +694,7 @@ NameInst **Compiler::makeNameIndex( NameInst *rootName ) void Compiler::createBuiltin( const char *name, BuiltinMachine builtin ) { - Expression *expression = new Expression( builtin ); + Expression *expression = Expression::cons( builtin ); Join *join = new Join( expression ); VarDef *varDef = new VarDef( name, join ); GraphDictEl *graphDictEl = new GraphDictEl( name, varDef ); @@ -1056,7 +1058,7 @@ void Compiler::createDefaultScanner() newEl->isInstance = true; instanceList.append( newEl ); - Join *join = new Join( new Expression( BT_Any ) ); + Join *join = new Join( Expression::cons( BT_Any ) ); TokenDef *tokenDef = new TokenDef( name, String(), false, false, join, 0, loc, nextTokenId++, @@ -1270,7 +1272,7 @@ void Compiler::initEmptyScanners() InputLoc loc = { 0, 0, 0 }; String name( reg->name.length() + 16, "__%s_DEF_PAT_%d", reg->name.data, def++ ); - Join *join = new Join( new Expression( BT_Any ) ); + Join *join = new Join( Expression::cons( BT_Any ) ); TokenDef *tokenDef = new TokenDef( name, String(), false, false, join, 0, loc, nextTokenId++, rootNamespace, reg, 0, 0, 0 ); diff --git a/src/lmparse.kl b/src/lmparse.kl index 3ead7c98..8ef15a79 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -977,7 +977,7 @@ literal_item: opt_no_ignore TK_Literal opt_no_ignore if ( ldel != 0 ) error( $2->loc ) << "literal already defined in this namespace" << endp; else { - Join *join = new Join( new Expression( new Term( new FactorWithAug( + Join *join = new Join( Expression::cons( new Term( new FactorWithAug( new FactorWithRep( $2->loc, new FactorWithNeg( $2->loc, new Factor( new Literal( $2->loc, $2->data, Literal::LitString ) ) ) ) ) ) ) ); @@ -2091,29 +2091,29 @@ nonterm rl_expr rl_expr: rl_expr '|' rl_term_short final { - $$->expression = new Expression( $1->expression, + $$->expression = Expression::cons( $1->expression, $3->term, Expression::OrType ); }; rl_expr: rl_expr '&' rl_term_short final { - $$->expression = new Expression( $1->expression, + $$->expression = Expression::cons( $1->expression, $3->term, Expression::IntersectType ); }; # This priority specification overrides the innermost parsing strategy which # results ordered choice interpretation of the grammar. rl_expr: rl_expr '-' rl_term_short final { - $$->expression = new Expression( $1->expression, + $$->expression = Expression::cons( $1->expression, $3->term, Expression::SubtractType ); }; rl_expr: rl_expr TK_DashDash rl_term_short final { - $$->expression = new Expression( $1->expression, + $$->expression = Expression::cons( $1->expression, $3->term, Expression::StrongSubtractType ); }; rl_expr: rl_term_short final { - $$->expression = new Expression( $1->term ); + $$->expression = Expression::cons( $1->term ); }; nonterm rl_term_short diff --git a/src/parsetree.cc b/src/parsetree.cc index 084ffbb8..496167e4 100644 --- a/src/parsetree.cc +++ b/src/parsetree.cc @@ -610,6 +610,8 @@ FsmGraph *Join::walk( Compiler *pd ) Expression::~Expression() { switch ( type ) { + case None: + break; case OrType: case IntersectType: case SubtractType: case StrongSubtractType: delete expression; @@ -628,6 +630,8 @@ FsmGraph *Expression::walk( Compiler *pd, bool lastInSeq ) { FsmGraph *rtnVal = 0; switch ( type ) { + case None: + break; case OrType: { /* Evaluate the expression. */ rtnVal = expression->walk( pd, false ); diff --git a/src/parsetree.h b/src/parsetree.h index c3a75df5..89a15793 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -129,6 +129,7 @@ struct CodeVect : public Vector<Code> /* Types of builtin machines. */ enum BuiltinMachine { + BT_None, BT_Any, BT_Ascii, BT_Extend, @@ -808,6 +809,7 @@ struct Join struct Expression { enum Type { + None, OrType, IntersectType, SubtractType, @@ -816,20 +818,37 @@ struct Expression BuiltinType }; + Expression( ) : + expression(0), term(0), builtin(BT_None), + type(None), prev(this), next(this) { } + /* Construct with an expression on the left and a term on the right. */ - Expression( Expression *expression, Term *term, Type type ) : - expression(expression), term(term), - builtin(builtin), type(type), prev(this), next(this) { } + static Expression *cons( Expression *expression, Term *term, Type type ) + { + Expression *expr = new Expression; + expr->type = type; + expr->expression = expression; + expr->term = term; + return expr; + } /* Construct with only a term. */ - Expression( Term *term ) : - expression(0), term(term), builtin(builtin), - type(TermType) , prev(this), next(this) { } + static Expression *cons( Term *term ) + { + Expression *expr = new Expression; + expr->type = TermType; + expr->term = term; + return expr; + } /* Construct with a builtin type. */ - Expression( BuiltinMachine builtin ) : - expression(0), term(0), builtin(builtin), - type(BuiltinType), prev(this), next(this) { } + static Expression *cons( BuiltinMachine builtin ) + { + Expression *expr = new Expression; + expr->type = BuiltinType; + expr->builtin = builtin; + return expr; + } ~Expression(); |