First public contribution.
6 **********************************************************************
7 * Copyright (c) 2002-2004, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 **********************************************************************
15 #include "unicode/utypes.h"
16 #include "unicode/uobject.h"
17 #include "unicode/rbbi.h"
23 class RBBIRuleScanner;
24 class RBBIRuleBuilder;
27 // class RBBITableBuilder is part of the RBBI rule compiler.
28 // It builds the state transition table used by the RBBI runtime
29 // from the expression syntax tree generated by the rule scanner.
31 // This class is part of the RBBI implementation only.
32 // There is no user-visible public API here.
35 class RBBITableBuilder : public UMemory {
37 RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
41 int32_t getTableSize() const; // Return the runtime size in bytes of
42 // the built state table
43 void exportTable(void *where); // fill in the runtime state table.
44 // Sufficient memory must exist at
45 // the specified location.
49 void calcNullable(RBBINode *n);
50 void calcFirstPos(RBBINode *n);
51 void calcLastPos(RBBINode *n);
52 void calcFollowPos(RBBINode *n);
53 void calcChainedFollowPos(RBBINode *n);
54 void buildStateTable();
55 void flagAcceptingStates();
56 void flagLookAheadStates();
57 void flagTaggedStates();
58 void mergeRuleStatusVals();
60 // Set functions for UVector.
61 // TODO: make a USet subclass of UVector
63 void setAdd(UVector *dest, UVector *source);
64 UBool setEquals(UVector *a, UVector *b);
66 void sortedAdd(UVector **dest, int32_t val);
70 void printSet(UVector *s);
71 void printPosSets(RBBINode *n /* = NULL*/);
73 void printRuleStatusTable();
76 #define printPosSets(n)
78 #define printRuleStatusTable()
83 RBBINode *&fTree; // The root node of the parse tree to build a
87 UVector *fDStates; // D states (Aho's terminology)
88 // Index is state number
89 // Contents are RBBIStateDescriptor pointers.
92 RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
93 RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
97 // RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
98 // one for each state.
99 class RBBIStateDescriptor : public UMemory {
106 UVector *fPositions; // Set of parse tree positions associated
107 // with this state. Unordered (it's a set).
108 // UVector contents are RBBINode *
110 UVector *fDtran; // Transitions out of this state.
111 // indexed by input character
112 // contents is int index of dest state
113 // in RBBITableBuilder.fDStates
115 RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
116 ~RBBIStateDescriptor();
119 RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
120 RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class