bool Nullable(Node* regexTree)
{
	if (regexTree != NULL)
	{
		if (regexTree->value.compare("l") == 0)
		{
			return true;
		}
		else if (regexTree->value.compare("|") == 0)
		{
			return Nullable(regexTree->left) || Nullable(regexTree->right);
		}
		else if (regexTree->value.compare(".") == 0)
		{
			return Nullable(regexTree->left) && Nullable(regexTree->right);
		}
		else if (regexTree->value.compare("*") == 0)
		{
			return true;
		}
		else // alphabet character
		{
			return false;
		}
	}
}
예제 #2
0
Stack mk_alt(Stack *s, Re_node r)
{
    Re_node node;

    if (s == NULL || *s == NULL || r == NULL) return NULL;
    node = (Re_node) new_node(node);
    if (node == NULL) return NULL;
    Op(node) = OPALT;
    Lchild(node) = Pop(s);
    Rchild(node) = r;
    if (Push(s, node) == NULL) return NULL;
    Nullable(node) = Nullable(Lchild(node)) || Nullable(Rchild(node));
    Firstpos(node) = pset_union(Firstpos(Lchild(node)), Firstpos(Rchild(node)));
    Lastpos(node) = pset_union(Lastpos(Lchild(node)), Lastpos(Rchild(node)));
    return *s;
}
예제 #3
0
파일: DbValue.hpp 프로젝트: denghe/69net
    void DbValue::Assign( T v )
    {
        GetColumnData().SetValue( parent->rowIndex, v );
#if __DEBUG
        if( Nullable() )
        {
#endif
            GetNullflag().SetFalse( parent->rowIndex );
#if __DEBUG
        }
#endif
    }
void SDR(Node* regexTree)
{
	if (regexTree != NULL)
	{
		SDR(regexTree->left);
		SDR(regexTree->right);
		regexTree->bNullable = Nullable(regexTree);
		CalculateFirstPos(regexTree);
		CalculateLastPos(regexTree);
		CalculateFollowPos(regexTree);
	}
}
예제 #5
0
Stack cat2(Stack *stk)
{
    Re_node r;

    if (stk == NULL) return NULL;
    if (*stk == NULL || (*stk)->next == NULL) return *stk;
    r = (Re_node) new_node(r);
    if (r == NULL) return NULL;	    /* can't allocate memory */
    Op(r) = OPCAT;
    Rchild(r) = Pop(stk);
    Lchild(r) = Pop(stk);
    if (Push(stk, r) == NULL) return NULL;
    Nullable(r) = Nullable(Lchild(r)) && Nullable(Rchild(r));
    if (Nullable(Lchild(r)))
        Firstpos(r) = pset_union(Firstpos(Lchild(r)), Firstpos(Rchild(r)));
    else Firstpos(r) = Firstpos(Lchild(r));
    if (Nullable(Rchild(r)))
        Lastpos(r) = pset_union(Lastpos(Lchild(r)), Lastpos(Rchild(r)));
    else Lastpos(r) = Lastpos(Rchild(r));
    return *stk;
}
예제 #6
0
void lalr1( void )
{
    a_state         *x;
    a_shift_action  *tx;
    a_reduce_action *rx;
    a_look          *lk, *look;
    a_word          *lp, *lset;
    a_word          *rp, *rset;

    InitSets( nterm );
    lk = look = CALLOC( nvtrans + nstate, a_look );
    lp = lset = AllocSet( nvtrans );
    rp = rset = AllocSet( nredun );
    for( x = statelist; x != NULL; x = x->next ) {
        x->look = lk;
        for( tx = x->trans; tx->sym != NULL; ++tx ) {
            if( tx->sym->pro != NULL ) {
                lk->trans = tx;
                lk->follow = lp;
                lp += GetSetSize( 1 );
                ++lk;
            }
        }
        ++lk;
        for( rx = x->redun; rx->pro != NULL; ++rx ) {
            rx->follow = rp;
            rp += GetSetSize( 1 );
        }
    }
    stk = CALLOC( nvtrans, a_look * );
    top = stk;
    Nullable();
    CalcReads();
    CalcIncludes();
    Lookback();
    if( lk - look != nvtrans + nstate ) {
        puts( "internal error" );
    }
    if( lp - lset != GetSetSize( nvtrans ) ) {
        puts( "internal error" );
    }
    if( rp - rset != GetSetSize( nredun ) ) {
        puts( "internal error" );
    }
    FREE( look );
    FREE( lset );
    FREE( stk );
    Conflict();
    nbstate = nstate;
}
예제 #7
0
Stack wrap(Stack *s, short opv)
{
    Re_node r;

    if (s == NULL || *s == NULL) return NULL;
    r = (Re_node) new_node(r);
    if (r == NULL) return NULL;
    Op(r) = opv;
    Child(r) = Pop(s);
    if (Push(s, r) == NULL) return NULL;
    Nullable(r) = TRUE;
    Firstpos(r) = Firstpos(Child(r));
    Lastpos(r)  = Lastpos(Child(r));
    return *s;
}
예제 #8
0
Re_node mk_leaf(short opval, short type, char ch, Ch_Set cset)
{
    Re_node node;
    Re_Lit l;

    l = (Re_Lit) new_node(l);
    node = (Re_node) new_node(node);
    if (l == NULL || node == NULL) return NULL;
    lit_type(l) = type;
    lit_pos(l)  = pos_cnt++;
    if (type == C_SET) lit_cset(l) = cset;
    else lit_char(l) = ch;			/* type == C_LIT */
    Op(node) = opval;
    Lit(node) = l;
    Nullable(node) = FALSE;
    Firstpos(node) = create_pos(lit_pos(l));
    Lastpos(node) = Firstpos(node);
    return node;
}