2002-06-25 17:23:07 +00:00
|
|
|
//
|
|
|
|
// rbbitblb.h
|
|
|
|
//
|
|
|
|
|
|
|
|
/*
|
|
|
|
**********************************************************************
|
2003-12-18 23:16:48 +00:00
|
|
|
* Copyright (c) 2002-2003, International Business Machines
|
2002-06-25 17:23:07 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RBBITBLB_H
|
|
|
|
#define RBBITBLB_H
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
2002-06-25 17:23:07 +00:00
|
|
|
#include "unicode/rbbi.h"
|
|
|
|
#include "rbbinode.h"
|
|
|
|
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class RBBIRuleScanner;
|
2002-06-27 21:14:47 +00:00
|
|
|
class RBBIRuleBuilder;
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// class RBBITableBuilder is part of the RBBI rule compiler.
|
|
|
|
// It builds the state transition table used by the RBBI runtime
|
|
|
|
// from the expression syntax tree generated by the rule scanner.
|
|
|
|
//
|
|
|
|
// This class is part of the RBBI implementation only.
|
|
|
|
// There is no user-visible public API here.
|
|
|
|
//
|
|
|
|
|
2002-10-04 01:23:34 +00:00
|
|
|
class RBBITableBuilder : public UMemory {
|
2002-06-25 17:23:07 +00:00
|
|
|
public:
|
2002-06-27 21:14:47 +00:00
|
|
|
RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
|
2002-06-25 17:23:07 +00:00
|
|
|
~RBBITableBuilder();
|
|
|
|
|
|
|
|
void build();
|
2004-03-27 07:05:32 +00:00
|
|
|
int32_t getTableSize() const; // Return the runtime size in bytes of
|
2002-06-25 17:23:07 +00:00
|
|
|
// the built state table
|
|
|
|
void exportTable(void *where); // fill in the runtime state table.
|
|
|
|
// Sufficient memory must exist at
|
|
|
|
// the specified location.
|
|
|
|
|
2003-12-04 02:12:42 +00:00
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
private:
|
|
|
|
void calcNullable(RBBINode *n);
|
|
|
|
void calcFirstPos(RBBINode *n);
|
|
|
|
void calcLastPos(RBBINode *n);
|
|
|
|
void calcFollowPos(RBBINode *n);
|
2003-10-09 01:13:08 +00:00
|
|
|
void calcChainedFollowPos(RBBINode *n);
|
2002-06-25 17:23:07 +00:00
|
|
|
void buildStateTable();
|
|
|
|
void flagAcceptingStates();
|
|
|
|
void flagLookAheadStates();
|
|
|
|
void flagTaggedStates();
|
2004-03-05 05:04:10 +00:00
|
|
|
void mergeRuleStatusVals();
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
// Set functions for UVector.
|
|
|
|
// TODO: make a USet subclass of UVector
|
|
|
|
|
|
|
|
void setAdd(UVector *dest, UVector *source);
|
|
|
|
UBool setEquals(UVector *a, UVector *b);
|
|
|
|
|
2004-03-05 05:04:10 +00:00
|
|
|
void sortedAdd(UVector **dest, int32_t val);
|
|
|
|
|
|
|
|
public:
|
2003-12-04 22:44:05 +00:00
|
|
|
#ifdef RBBI_DEBUG
|
2002-06-25 17:23:07 +00:00
|
|
|
void printSet(UVector *s);
|
2003-12-06 00:13:57 +00:00
|
|
|
void printPosSets(RBBINode *n /* = NULL*/);
|
2002-06-25 17:23:07 +00:00
|
|
|
void printStates();
|
2004-03-05 05:04:10 +00:00
|
|
|
void printRuleStatusTable();
|
2003-12-04 22:44:05 +00:00
|
|
|
#else
|
|
|
|
#define printSet(s)
|
2003-12-06 00:13:57 +00:00
|
|
|
#define printPosSets(n)
|
2003-12-04 22:44:05 +00:00
|
|
|
#define printStates()
|
2004-03-05 05:04:10 +00:00
|
|
|
#define printRuleStatusTable()
|
2003-12-04 22:44:05 +00:00
|
|
|
#endif
|
2002-06-25 17:23:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RBBIRuleBuilder *fRB;
|
|
|
|
RBBINode *&fTree; // The root node of the parse tree to build a
|
2002-06-27 21:14:47 +00:00
|
|
|
// table for.
|
2002-06-25 17:23:07 +00:00
|
|
|
UErrorCode *fStatus;
|
|
|
|
|
|
|
|
UVector *fDStates; // D states (Aho's terminology)
|
|
|
|
// Index is state number
|
|
|
|
// Contents are RBBIStateDescriptor pointers.
|
|
|
|
|
2003-12-04 02:12:42 +00:00
|
|
|
|
2002-10-04 01:23:34 +00:00
|
|
|
RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
|
|
|
|
RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
|
|
|
|
// one for each state.
|
2002-10-04 01:23:34 +00:00
|
|
|
class RBBIStateDescriptor : public UMemory {
|
2002-06-25 17:23:07 +00:00
|
|
|
public:
|
|
|
|
UBool fMarked;
|
|
|
|
int32_t fAccepting;
|
|
|
|
int32_t fLookAhead;
|
2004-03-05 05:04:10 +00:00
|
|
|
UVector *fTagVals;
|
|
|
|
int32_t fTagsIdx;
|
2002-06-25 17:23:07 +00:00
|
|
|
UVector *fPositions; // Set of parse tree positions associated
|
|
|
|
// with this state. Unordered (it's a set).
|
|
|
|
// UVector contents are RBBINode *
|
|
|
|
|
|
|
|
UVector *fDtran; // Transitions out of this state.
|
|
|
|
// indexed by input character
|
|
|
|
// contents is int index of dest state
|
|
|
|
// in RBBITableBuilder.fDStates
|
|
|
|
|
|
|
|
RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
|
|
|
|
~RBBIStateDescriptor();
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
private:
|
2002-10-04 01:23:34 +00:00
|
|
|
RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
|
|
|
|
RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class
|
2002-06-25 17:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
#endif
|