BOOL assoc_comm_symbols(void);This function tells you if any symbol has been declared to be associative-commutative;
BOOL binary_parse_type(char *str, int *precedence, Parsetype *type);This routine gets the parse/print properties for a binary symbol. If *str is a binary symbol, TRUE is returned and the properties are filled in. If *str is a not a binary symbol, FALSE is returned.
BOOL comm_symbols(void);This function tells you if any symbol has been declared to be commutative/symmetric;
void declare_functions_and_relations(Ilist fsyms, Ilist rsyms);
void empty_sym_tab(void);This routine deletes all entries in the symbol table.
void fprint_sym(FILE *fp, int symnum);This routine prints (to FILE *fp) the string associated with a symbol ID. A newline is NOT printed.
void fprint_symbols_mem(FILE *fp, BOOL heading);This routine prints (to FILE *fp) memory usage statistics for Sym_ents. The Boolean argument heading tells whether to print a heading on the table.
void fprint_syms(FILE *fp);This routine prints (to FILE *fp) the symbol table, including all of the attributes of each symbol.
int fresh_symbol(char *prefix, int arity);This routine returns a symbol ID for a new symbol with the given arity. The symbol is made up of the given prefix followed by the smallest natural number that results in a new symbol (regardless of arity). The prefix must be less than MAX_NAME characters.
BOOL function_symbol(int sym_num);
Symbol_type get_symbol_type(int sym_num);
int greatest_symnum(void);This function returns the greatest symnum (symbol ID) currently in use. This can be used if you need to dynamnically allocate an array of objects to be indexed by symnum.
BOOL is_assoc_comm(int sn);This function checks if a symbol ID has the associative-commutative property. Note that set_assoc_comm() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms.
BOOL is_commutative(int sn);This function checks if a symbol ID has the commutative property. Note that set_commutative() takes a string, but this routine takes a symbol ID. Recall that str_to_sn() and sn_to_str() translate between the two forms.
BOOL is_eq_symbol(int symnum);This Boolean routine checks if a given symbol ID is for =/2. One could use is_symbol(symnum, "=", 2) instead, but this should be a bit faster.
BOOL is_symbol(int symnum, char *str, int arity);This Boolean routine checks if a given symbol ID matches a given (string,arity) pair.
void itoa(int n, char *s);This routine converts an integer to a string (in decimal form). The character array s must be large enough to hold the string.
void lex_order_1(void);This routine imposes a default total ordering on symbols.
constants < arity-2 < arity-3 < ... < arity-infinity < arity-1Within arity, the order is determined by the C library function strcmp, which is (usually) lexicographic ASCII order.void lex_order_2(Ilist fsyms, Ilist rsyms);Assign a total order on lex_vals of (fsyms U rsyms). If any of the symbols already have lex_vals, they are considered, but overwritten by this rouine. For the rules, see lex_compare_2.int next_skolem_symbol(int arity);This routine returns a fresh symbol ID, which is intended to be used as a Skolem symbol. The symbols are $c1, $c2, $c3, ... for arity 0 (constants) and $f1, $f2, $f3, ... for arity != 0. If some of those symbols already exist in the symbol table (with any arity), they will be skipped.BOOL no_symbols_have_lex_val(void);Return TRUE if no symbol has been given a lex_val;void p_sym(int symnum);This routine prints (stdout) the string associated with a symbol ID. A newline is NOT printed.void p_symbols_mem(void);This routine prints (to stdout) memory usage statistics for Sym_ents.void p_syms(void);This routine prints (to stdout) the symbol table, including all of the attributes of each symbol.BOOL relation_symbol(int sym_num);void reverse_chars(char *s, int start, int end);This routine reverses an array of characters. You must give the starting and ending positions.void set_assoc_comm(char *str);This routine declares a string to be a (binary) symbol with the logical property "associative-commutative". This property is used for AC unification/matching/identity. (If you wish to print AC expressions without parentheses, see set_parse_type().)void set_commutative(char *str);This routine declares a string to be a (binary) symbol with the logical property "commutative". This includes symmetric relations as well as commutative functions. This property is used for commutative unification/matching/identity.void set_lex_val(int symnum, int lex_val);This routine is used to assign a lexical value to a symbol. The value can be retrieved later with sn_to_lex_val();void set_parse_type(char *str, int precedence, Parsetype type);This routine sets the parse/print properties of a binary or unary symbol. The types for binary infix symbols are INFIX_LEFT, INFIX_RIGHT, INFIX. The types for prefix unary symbols are PREFIX, PREFIX_PAREN. The types for postfix unary symbols are POSTFIX, POSTFIX_PAREN.If the precedence is out of range [MIN_PRECEDENCE ... MAX_PRECEDENCE], nothing happens.
void set_symbol_type(int sym_num, Symbol_type type);void set_variable_style(Variable_style style);This routine determines how variables are parsed and printed.int sn_to_arity(int sym_num);This routine returns the arity associated with a symbol ID.int sn_to_lex_val(int sn);This routine returns the lexical value associated with a symbol ID. The default value is INT_MAX. If the symbol ID is not valid, INT_MIN is returned.Lrpo_status sn_to_lrpo_status(int sn);This routine returns the LRPO status associated with a symbol ID. The default value is LRPO_LR_STATUS. See order.h for the possible values. If the symbol ID is not valid, 0 is returned.char *sn_to_str(int sym_num);This routine returns the string assocated with a symbol ID.Ilist sort_by_lex_val(Ilist p);void sprint_sym(String_buf sb, int symnum);This routine appends, to String_buf sb, the string associated with a symbol ID. A newline is NOT printed.BOOL str_exists(char *str);This function checks if the given string occurs in the symbol table (with any arity).BOOL str_to_int(char *str, int *ip);This routine tries to convert a string into an integer (using strtol()). If successful, TRUE is returned and *ip is set to the integer. If failure, FALSE is returned.int str_to_sn(char *str, int arity);This routine takes a string and an arity, and returns an integer identifier for the pair. If the pair is not already in the symbol table, a new entry is inserted into the table. A pair, say ("f",2), is sometimes written as f/2, which is a different symbol from f/3. There is no limit on the length of the string.Ordertype sym_precedence(int symnum_1, int symnum_2);This routine compares two symbol IDs by looking at their lex_val in the symbol table. The range of return values is
{SAME_AS, GREATER_THAN, LESS_THAN, NOT_COMPARABLE}.Ilist syms_with_lex_val(void);Return an Ilist containing symnums of symbols to which lex_vals have been assigned.BOOL unary_parse_type(char *str, int *precedence, Parsetype *type);This routine gets the parse/print properties for a unary symbol. If *str is a unary symbol, TRUE is returned and the properties are filled in. If *str is a not a unary symbol, FALSE is returned.BOOL variable_name(char *s);Is the given name a variable? In some cases (in particular clauses) variables are not explicitly quantified, so we have a rule to distinguish variables from constants. This is it.Variable_style variable_style(void);This routine gives the current variable style.Public Definitions in File symbols.h
/* maximum number of chars in string part of symbol (includes '\0') */ #define MAX_NAME 51 /* parse/print properties of symbols */ typedef enum {NOTHING_SPECIAL, INFIX, /* xfx */ INFIX_LEFT , /* yfx */ INFIX_RIGHT, /* xfy */ PREFIX_PAREN, /* fx */ PREFIX, /* fy */ POSTFIX_PAREN, /* xf */ POSTFIX /* yf */ } Parsetype; #define MIN_PRECEDENCE 1 #define MAX_PRECEDENCE 999 /* Function/relation properties of symbols */ typedef enum { FUNCTION_SYMBOL, RELATION_SYMBOL, UNSPECIFIED_SYMBOL } Symbol_type; /* Unification properties of symbols */ typedef enum { EMPTY_THEORY, COMMUTE, ASSOC_COMMUTE } Unif_theory; /* LRPO status */ typedef enum { LRPO_LR_STATUS, LRPO_MULTISET_STATUS } Lrpo_status; /* Variable style */ typedef enum { STANDARD_STYLE, /* x,y,z,... */ PROLOG_STYLE, /* A,B,C,... */ INTEGER_STYLE /* 0,1,2,... */ } Variable_style; /* Logic symbols when in Term form */ #define TRUE_SYM "$T" #define FALSE_SYM "$F" #define AND_SYM "&" #define OR_SYM "|" #define NOT_SYM "~" #define IFF_SYM "<->" #define IMP_SYM "->" #define IMPBY_SYM "<-" #define ALL_SYM "all" #define EXISTS_SYM "exists" #define QUANT_SYM "$quantified" /* Other symbols when in Term form */ #define ATTRIB_SYM "#" /* operator for attaching attributes */ typedef struct sym_ent * Sym_ent;Introduction
This collection of routines manages the global symbol table. Each symbol is a pair (string,arity) and has a unique ID number. For example, ("f",2), sometimes written f/2, is a different symbol from f/3.These symbols are used mostly as constant, function, and predicate symbols, but they can be used for variables and other things as well.
These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.