2002-09-17 23:03:30 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
#define MAX_ARITY 2
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
typedef int ItemSetNum;
|
|
|
|
typedef int OperatorNum;
|
|
|
|
typedef int NonTerminalNum;
|
|
|
|
typedef int RuleNum;
|
|
|
|
typedef int ArityNum;
|
|
|
|
typedef int ERuleNum;
|
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
extern NonTerminalNum last_user_nonterminal;
|
|
|
|
extern NonTerminalNum max_nonterminal;
|
|
|
|
extern RuleNum max_rule;
|
|
|
|
extern ERuleNum max_erule_num;
|
|
|
|
extern int max_arity;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
#define ARGS(x) x
|
|
|
|
#else
|
|
|
|
#define ARGS(x) ()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NOLEX
|
2005-04-22 04:13:13 +00:00
|
|
|
#define DELTAWIDTH 4
|
2002-09-17 23:03:30 +00:00
|
|
|
typedef short DeltaCost[DELTAWIDTH];
|
|
|
|
typedef short *DeltaPtr;
|
|
|
|
extern void ASSIGNCOST ARGS((DeltaPtr, DeltaPtr));
|
|
|
|
extern void ADDCOST ARGS((DeltaPtr, DeltaPtr));
|
|
|
|
extern void MINUSCOST ARGS((DeltaPtr, DeltaPtr));
|
|
|
|
extern void ZEROCOST ARGS((DeltaPtr));
|
|
|
|
extern int LESSCOST ARGS((DeltaPtr, DeltaPtr));
|
|
|
|
extern int EQUALCOST ARGS((DeltaPtr, DeltaPtr));
|
2005-04-22 04:13:13 +00:00
|
|
|
#define PRINCIPLECOST(x) (x[0])
|
2002-09-17 23:03:30 +00:00
|
|
|
#else
|
2005-04-22 04:13:13 +00:00
|
|
|
#define DELTAWIDTH 1
|
2002-09-17 23:03:30 +00:00
|
|
|
typedef int DeltaCost;
|
|
|
|
typedef int DeltaPtr;
|
2005-04-22 04:13:13 +00:00
|
|
|
#define ASSIGNCOST(l, r) ((l) = (r))
|
|
|
|
#define ADDCOST(l, r) ((l) += (r))
|
|
|
|
#define MINUSCOST(l, r) ((l) -= (r))
|
|
|
|
#define ZEROCOST(x) ((x) = 0)
|
|
|
|
#define LESSCOST(l, r) ((l) < (r))
|
|
|
|
#define EQUALCOST(l, r) ((l) == (r))
|
|
|
|
#define PRINCIPLECOST(x) (x)
|
2002-09-17 23:03:30 +00:00
|
|
|
#endif /* NOLEX */
|
2005-04-22 04:13:13 +00:00
|
|
|
#define NODIVERGE(c,state,nt,base) if (prevent_divergence > 0) CHECKDIVERGE(c,state,nt,base);
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct list {
|
2005-04-22 04:13:13 +00:00
|
|
|
void *x;
|
|
|
|
struct list *next;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct list *List;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct intlist {
|
2005-04-22 04:13:13 +00:00
|
|
|
int x;
|
|
|
|
struct intlist *next;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct intlist *IntList;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct operator {
|
2005-04-22 04:13:13 +00:00
|
|
|
char *name;
|
|
|
|
unsigned int ref:1;
|
|
|
|
OperatorNum num;
|
|
|
|
ItemSetNum baseNum;
|
|
|
|
ItemSetNum stateCount;
|
|
|
|
ArityNum arity;
|
|
|
|
struct table *table;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct operator *Operator;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct nonterminal {
|
2005-04-22 04:13:13 +00:00
|
|
|
char *name;
|
|
|
|
NonTerminalNum num;
|
|
|
|
ItemSetNum baseNum;
|
|
|
|
ItemSetNum ruleCount;
|
|
|
|
struct plankMap *pmap;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
struct rule *sampleRule; /* diagnostic---gives "a" rule that with this lhs */
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct nonterminal *NonTerminal;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct pattern {
|
2005-04-22 04:13:13 +00:00
|
|
|
NonTerminal normalizer;
|
|
|
|
Operator op; /* NULL if NonTerm -> NonTerm */
|
|
|
|
NonTerminal children[MAX_ARITY];
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct pattern *Pattern;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct rule {
|
2005-04-22 04:13:13 +00:00
|
|
|
DeltaCost delta;
|
|
|
|
ERuleNum erulenum;
|
|
|
|
RuleNum num;
|
|
|
|
RuleNum newNum;
|
|
|
|
NonTerminal lhs;
|
|
|
|
Pattern pat;
|
|
|
|
unsigned int used:1;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct rule *Rule;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct item {
|
2005-04-22 04:13:13 +00:00
|
|
|
DeltaCost delta;
|
|
|
|
Rule rule;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct item Item;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef short *Relevant; /* relevant non-terminals */
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef Item *ItemArray;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
struct item_set { /* indexed by NonTerminal */
|
|
|
|
ItemSetNum num;
|
|
|
|
ItemSetNum newNum;
|
|
|
|
Operator op;
|
|
|
|
struct item_set *kids[2];
|
|
|
|
struct item_set *representative;
|
|
|
|
Relevant relevant;
|
|
|
|
ItemArray virgin;
|
|
|
|
ItemArray closed;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct item_set *Item_Set;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
#define DIM_MAP_SIZE (1 << 8)
|
|
|
|
#define GLOBAL_MAP_SIZE (1 << 15)
|
2002-09-17 23:03:30 +00:00
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
struct mapping { /* should be a hash table for TS -> int */
|
|
|
|
List *hash;
|
|
|
|
int hash_size;
|
|
|
|
int max_size;
|
|
|
|
ItemSetNum count;
|
|
|
|
Item_Set *set; /* map: int <-> Item_Set */
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct mapping *Mapping;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct index_map {
|
2005-04-22 04:13:13 +00:00
|
|
|
ItemSetNum max_size;
|
|
|
|
Item_Set *class;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct index_map Index_Map;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct dimension {
|
2005-04-22 04:13:13 +00:00
|
|
|
Relevant relevant;
|
|
|
|
Index_Map index_map;
|
|
|
|
Mapping map;
|
|
|
|
ItemSetNum max_size;
|
|
|
|
struct plankMap *pmap;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct dimension *Dimension;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct table {
|
2005-04-22 04:13:13 +00:00
|
|
|
Operator op;
|
|
|
|
List rules;
|
|
|
|
Relevant relevant;
|
|
|
|
Dimension dimen[MAX_ARITY]; /* 1 for each dimension */
|
|
|
|
Item_Set *transition; /* maps local indices to global
|
|
|
|
itemsets */
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct table *Table;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct relation {
|
2005-04-22 04:13:13 +00:00
|
|
|
Rule rule;
|
|
|
|
DeltaCost chain;
|
|
|
|
NonTerminalNum nextchain;
|
|
|
|
DeltaCost sibling;
|
|
|
|
int sibFlag;
|
|
|
|
int sibComputed;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct relation *Relation;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct queue {
|
2005-04-22 04:13:13 +00:00
|
|
|
List head;
|
|
|
|
List tail;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct queue *Queue;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct plank {
|
2005-04-22 04:13:13 +00:00
|
|
|
char *name;
|
|
|
|
List fields;
|
|
|
|
int width;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct plank *Plank;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct except {
|
2005-04-22 04:13:13 +00:00
|
|
|
short index;
|
|
|
|
short value;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct except *Exception;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct plankMap {
|
2005-04-22 04:13:13 +00:00
|
|
|
List exceptions;
|
|
|
|
int offset;
|
|
|
|
struct stateMap *values;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct plankMap *PlankMap;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct stateMap {
|
2005-04-22 04:13:13 +00:00
|
|
|
char *fieldname;
|
|
|
|
Plank plank;
|
|
|
|
int width;
|
|
|
|
short *value;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef struct stateMap *StateMap;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
struct stateMapTable {
|
2005-04-22 04:13:13 +00:00
|
|
|
List maps;
|
2002-09-17 23:03:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void CHECKDIVERGE ARGS((DeltaPtr, Item_Set, int, int));
|
|
|
|
extern void zero ARGS((Item_Set));
|
|
|
|
extern ItemArray newItemArray ARGS((void));
|
|
|
|
extern ItemArray itemArrayCopy ARGS((ItemArray));
|
|
|
|
extern Item_Set newItem_Set ARGS((Relevant));
|
|
|
|
extern void freeItem_Set ARGS((Item_Set));
|
|
|
|
extern Mapping newMapping ARGS((int));
|
|
|
|
extern NonTerminal newNonTerminal ARGS((char *));
|
|
|
|
extern int nonTerminalName ARGS((char *, int));
|
|
|
|
extern Operator newOperator ARGS((char *, OperatorNum, ArityNum));
|
|
|
|
extern Pattern newPattern ARGS((Operator));
|
|
|
|
extern Rule newRule ARGS((DeltaPtr, ERuleNum, NonTerminal, Pattern));
|
|
|
|
extern List newList ARGS((void *, List));
|
|
|
|
extern IntList newIntList ARGS((int, IntList));
|
|
|
|
extern int length ARGS((List));
|
|
|
|
extern List appendList ARGS((void *, List));
|
|
|
|
extern Table newTable ARGS((Operator));
|
|
|
|
extern Queue newQ ARGS((void));
|
|
|
|
extern void addQ ARGS((Queue, Item_Set));
|
|
|
|
extern Item_Set popQ ARGS((Queue));
|
|
|
|
extern int equivSet ARGS((Item_Set, Item_Set));
|
|
|
|
extern Item_Set decode ARGS((Mapping, ItemSetNum));
|
|
|
|
extern Item_Set encode ARGS((Mapping, Item_Set, int *));
|
|
|
|
extern void build ARGS((void));
|
|
|
|
extern Item_Set *transLval ARGS((Table, int, int));
|
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
typedef void * (*ListFn) ARGS((void *));
|
2002-09-17 23:03:30 +00:00
|
|
|
extern void foreachList ARGS((ListFn, List));
|
|
|
|
extern void reveachList ARGS((ListFn, List));
|
|
|
|
|
|
|
|
extern void addToTable ARGS((Table, Item_Set));
|
|
|
|
|
|
|
|
extern void closure ARGS((Item_Set));
|
|
|
|
extern void trim ARGS((Item_Set));
|
|
|
|
extern void findChainRules ARGS((void));
|
|
|
|
extern void findAllPairs ARGS((void));
|
|
|
|
extern void addRelevant ARGS((Relevant, NonTerminalNum));
|
|
|
|
|
|
|
|
extern void *zalloc ARGS((unsigned int));
|
|
|
|
extern void zfree ARGS((void *));
|
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
extern NonTerminal start;
|
|
|
|
extern List rules;
|
|
|
|
extern List chainrules;
|
|
|
|
extern List operators;
|
|
|
|
extern List leaves;
|
|
|
|
extern List nonterminals;
|
|
|
|
extern List grammarNts;
|
|
|
|
extern Queue globalQ;
|
|
|
|
extern Mapping globalMap;
|
|
|
|
extern int exceptionTolerance;
|
|
|
|
extern int prevent_divergence;
|
|
|
|
extern int principleCost;
|
|
|
|
extern int lexical;
|
|
|
|
extern struct rule stub_rule;
|
|
|
|
extern Relation *allpairs;
|
|
|
|
extern Item_Set *sortedStates;
|
|
|
|
extern Item_Set errorState;
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
extern void dumpRelevant ARGS((Relevant));
|
|
|
|
extern void dumpOperator ARGS((Operator, int));
|
|
|
|
extern void dumpOperator_s ARGS((Operator));
|
|
|
|
extern void dumpOperator_l ARGS((Operator));
|
|
|
|
extern void dumpNonTerminal ARGS((NonTerminal));
|
|
|
|
extern void dumpRule ARGS((Rule));
|
|
|
|
extern void dumpRuleList ARGS((List));
|
|
|
|
extern void dumpItem ARGS((Item *));
|
|
|
|
extern void dumpItem_Set ARGS((Item_Set));
|
|
|
|
extern void dumpMapping ARGS((Mapping));
|
|
|
|
extern void dumpQ ARGS((Queue));
|
|
|
|
extern void dumpIndex_Map ARGS((Index_Map *));
|
|
|
|
extern void dumpDimension ARGS((Dimension));
|
|
|
|
extern void dumpPattern ARGS((Pattern));
|
|
|
|
extern void dumpTable ARGS((Table, int));
|
|
|
|
extern void dumpTransition ARGS((Table));
|
|
|
|
extern void dumpCost ARGS((DeltaCost));
|
|
|
|
extern void dumpAllPairs ARGS((void));
|
|
|
|
extern void dumpRelation ARGS((Relation));
|
|
|
|
extern void dumpSortedStates ARGS((void));
|
|
|
|
extern void dumpSortedRules ARGS((void));
|
|
|
|
extern int debugTrim;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-04-22 04:13:13 +00:00
|
|
|
#define debug(a,b) if (a) b
|
2002-09-17 23:03:30 +00:00
|
|
|
#else
|
|
|
|
#define debug(a,b)
|
|
|
|
#endif
|
|
|
|
extern int debugTables;
|
|
|
|
|
2005-04-22 04:13:13 +00:00
|
|
|
#define TABLE_INCR 8
|
|
|
|
#define STATES_INCR 64
|
2002-09-17 23:03:30 +00:00
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define assert(c) ((void) 0)
|
|
|
|
#else
|
|
|
|
#define assert(c) ((void) ((c) || fatal(__FILE__,__LINE__)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void doStart ARGS((char *));
|
|
|
|
extern void exit ARGS((int));
|
2002-09-22 02:40:40 +00:00
|
|
|
extern int fatal ARGS((const char *, int));
|
|
|
|
extern void yyerror ARGS((const char *));
|
|
|
|
extern void yyerror1 ARGS((const char *));
|