parser More...
Go to the source code of this file.
Functions | |
int | bad_psi_term (ptr_psi_term t) |
bad_psi_term More... | |
void | show (long limit) |
show More... | |
void | push (psi_term tok, long prec, long op) |
push More... | |
long | pop (ptr_psi_term tok, long *op) |
pop More... | |
long | look () |
look More... | |
long | precedence (psi_term tok, long typ) |
precedence More... | |
ptr_psi_term | stack_copy_psi_term (psi_term t) |
stack_copy_psi_term More... | |
ptr_psi_term | heap_copy_psi_term (psi_term t) |
heap_copy_psi_term More... | |
void | feature_insert (char *keystr, ptr_node *tree, ptr_psi_term psi) |
feature_insert More... | |
psi_term | list_nil (ptr_definition type) |
list_nil More... | |
psi_term | parse_list (ptr_definition typ, char e, char s) |
parse_list More... | |
psi_term | read_psi_term () |
read_psi_term More... | |
psi_term | make_life_form (ptr_psi_term tok, ptr_psi_term arg1, ptr_psi_term arg2) |
make_life_form More... | |
void | crunch (long prec, long limit) |
crunch More... | |
psi_term | read_life_form (char ch1, char ch2) |
read_life_form More... | |
psi_term | parse (long *q) |
parse More... | |
parser
Definition in file parser.c.
int bad_psi_term | ( | ptr_psi_term | t | ) |
bad_psi_term
t | - ptr_psi_term t |
BAD_PSI_TERM(t) This returns true if T is a psi_term which is not allowed to be considered as a constant by the parser.
Example: "A=)+6." would otherwise be parsed as: "=(A,+(')',6))", this was going a bit far.
Definition at line 31 of file parser.c.
References final_dot, final_question, wl_definition::keyword, wl_keyword::symbol, TRUE, and wl_psi_term::type.
void crunch | ( | long | prec, |
long | limit | ||
) |
crunch
prec | - long prec |
limit | - long limit |
CRUNCH(prec,limit) Crunch up = work out the arguments of anything on the stack whose precedence is <= PREC, and replace it with the corresponding psi-term. Do not go any further than LIMIT which is the end of the current expression.
Definition at line 662 of file parser.c.
References error_psi_term, FALSE, fx, look(), make_life_form(), nop, NULL, parse_ok, parser_stack_index, pop(), push(), xf, and xfx.
void feature_insert | ( | char * | keystr, |
ptr_node * | tree, | ||
ptr_psi_term | psi | ||
) |
feature_insert
keystr | - char *keystr |
tree | - ptr_node *tree |
psi | - ptr_psi_term psi |
FEATURE_INSERT(keystr,tree,psi) Insert the psi_term psi into the attribute tree. If the feature already exists, create a call to the unification function.
Definition at line 251 of file parser.c.
References FEATCMP, find(), stack_copy_psi_term(), stack_insert_copystr(), and Syntaxerrorline().
ptr_psi_term heap_copy_psi_term | ( | psi_term | t | ) |
heap_copy_psi_term
t | - psi_term t |
HEAP_COPY_PSI_TERM(tok) Return the address of a copy of TOK on the HEAP.
Definition at line 226 of file parser.c.
References global_time_stamp, and HEAP_ALLOC.
psi_term list_nil | ( | ptr_definition | type | ) |
list_nil
type | - ptr_definition type |
LIST_NIL(type) Returns the atom NIL to mark the end of a list.
Definition at line 278 of file parser.c.
References wl_psi_term::attr_list, wl_psi_term::coref, disj_nil, disjunction, FALSE, wl_psi_term::flags, nil, NULL, wl_psi_term::resid, wl_psi_term::status, wl_psi_term::type, and wl_psi_term::value_3.
long look | ( | ) |
look
LOOK() This function returns the precedence of the stack top.
Definition at line 163 of file parser.c.
References int_stack, and parser_stack_index.
psi_term make_life_form | ( | ptr_psi_term | tok, |
ptr_psi_term | arg1, | ||
ptr_psi_term | arg2 | ||
) |
make_life_form
tok | - ptr_psi_term tok |
arg1 | - ptr_psi_term arg1 |
arg2 | - ptr_psi_term arg2 |
MAKE_LIFE_FORM(tok,arg1,arg2) This routine inserts ARG1 and ARG2 as the first and second attributes of psi_term TOK, thus creating the term TOK(1=>arg1,2=>arg2).
If TOK is ':' then a conjunction is created if necessary. Example: a:V:b:5:long => V: <a,b,5,int> (= conjunction list).
Definition at line 571 of file parser.c.
References wl_psi_term::attr_list, wl_psi_term::coref, deref_ptr, equ_tokch, error_psi_term, FEATCMP, heap_alloc(), integer, minus_symbol, NULL, one, push_psi_ptr_value(), REAL, real, wl_psi_term::resid, stack_copy_psi_term(), stack_insert(), Syntaxerrorline(), top, two, wl_psi_term::type, and wl_psi_term::value_3.
psi_term parse | ( | long * | q | ) |
parse
q | - long *q |
PARSE(is_it_a_clause) This returns one clause or query from the input stream. It also indicates the type psi-term read, that is whether it was a clause or a query in the IS_IT_A_CLAUSE variable. This is the top level of the parser.
The whole parser is, rather like the psi_termiser, not too well written. It handles psi_terms rather than pointers which causes a lot of messy code and is somewhat slower.
Definition at line 907 of file parser.c.
References eof, EOLN, ERROR, FACT, FALSE, final_dot, final_question, mark_nonstrict(), NULL, parse_ok, parser_stack_index, prompt, put_back_char(), QUERY, read_char(), read_life_form(), read_token(), saved_char, saved_psi_term, stringparse, Syntaxerrorline(), TRUE, and wl_psi_term::type.
psi_term parse_list | ( | ptr_definition | typ, |
char | e, | ||
char | s | ||
) |
parse_list
typ | - ptr_definition typ |
e | - char e |
s | - char s |
PARSE_LIST(type,end,separator)
This function provides a replacement for the function 'read_list'. It does not create the old (slightly more compact and a lot more complicated) list structure, but instead creates a generic psi-term with 2 features. The list is terminated by the atom 'nil'.
Example:
[a,b,c|d] -> cons(a,cons(b,cons(c,d))). [] -> nil {a;b;c} -> disj(a,disj(b,disj(c,{}))). {} -> {} = bottom
Example: TYP=disjunction, END="}", SEPARATOR=";" will read in disjunctions.
Example: TYP=list, END="]", SEPARATOR="," will read lists such as [1,2,a,b,c|d]
Definition at line 329 of file parser.c.
References wl_psi_term::attr_list, display_psi_stderr(), equ_tokc, equ_tokch, FALSE, FEATCMP, list_nil(), NULL, one, parse_ok, perr(), psi_term_error(), put_back_token(), read_life_form(), read_token(), stack_copy_psi_term(), stack_insert(), stringparse, two, and wl_psi_term::type.
long pop | ( | ptr_psi_term | tok, |
long * | op | ||
) |
pop
tok | - ptr_psi_term tok |
op | - long *op |
POP(psi_term,op); This function pops PSI_TERM and OP off the parser stack and returns its precedence.
Definition at line 132 of file parser.c.
References error_psi_term, FALSE, int_stack, parse_ok, parser_stack_index, and psi_term_stack.
long precedence | ( | psi_term | tok, |
long | typ | ||
) |
precedence
tok | - psi_term tok |
typ | - long typ |
PRECEDENCE(tok,typ) This function returns the precedence of TOK if it is an operator of type TYP where TYP is FX XFX XF etc... Note that this allows both a binary and unary minus. The result is NOP if tok is not an operator.
Definition at line 180 of file parser.c.
References wl_operator_data::next, NOP, wl_definition::op_data, wl_operator_data::precedence, and wl_psi_term::type.
void push | ( | psi_term | tok, |
long | prec, | ||
long | op | ||
) |
push
tok | - psi_term tok |
prec | - long prec |
op | - long op |
PUSH(tok,prec,op) Push psi_term and precedence and operator onto parser stack.
Definition at line 107 of file parser.c.
References int_stack, parser_stack_index, PARSER_STACK_SIZE, perr(), psi_term_error(), and psi_term_stack.
psi_term read_life_form | ( | char | ch1, |
char | ch2 | ||
) |
read_life_form
ch1 | - char ch1 |
ch2 | - char ch2 |
READ_LIFE_FORM(str1,str2) This reads in one life-form from the input stream which finishes with the psi_term whose name is STR1 or STR2, typically if we're reading a list [A,4*5,b-4!] then STR1="," and STR2="|" . It would be incorrect if "," were taken as an operator.
This routine implements the two state expression parser as described in the implementation guide. It deals with all the various types of operators, precedence is dealt with by the CRUNCH function. Each time an opening parenthesis is encountered a new expression is started.
Definition at line 728 of file parser.c.
References wl_psi_term::attr_list, bad_psi_term(), crunch(), equ_tokc, equ_tokch, error_psi_term, FALSE, fx, fy, line_count, MAX_PRECEDENCE, nop, NOP, parse_ok, parser_stack_index, pop(), precedence(), push(), put_back_token(), read_psi_term(), read_token(), stringparse, Syntaxerrorline(), TRUE, xf, xfx, xfy, yf, and yfx.
psi_term read_psi_term | ( | ) |
read_psi_term
READ_PSI_TERM() This reads in a complex object from the input stream, that is, a whole psi-term.
Examples:
[A,B,C]
{0;1;2+A}
<a,b,c> death(victim => V,murderer => M)
which(x,y,z)
A:g(f)
I have allowed mixing labelled with unlabelled attributes.
Example:
f(x=>A,B,y=>K,"hklk",D) is parsed as f(1=>B,2=>"hklk",3=>D,x=>A,y=>K).
Definition at line 421 of file parser.c.
References add_module1, add_module2, add_module3, alist, apply, wl_psi_term::attr_list, bad_psi_term(), wl_keyword::combined_name, wl_psi_term::coref, current_module, disjunction, eof, equ_tok, equ_tokch, equal_types, error_psi_term, FALSE, FEATCMP, feature_insert(), find(), functor, heap_copy_string(), integer, wl_definition::keyword, wl_module::module_name, NULL, parse_list(), parse_ok, wl_keyword::private_feature, put_back_token(), quoted_string, read_life_form(), read_token(), REAL, wl_psi_term::resid, stack_copy_psi_term(), stack_insert(), stack_psi_term(), stringparse, wl_keyword::symbol, Syntaxerrorline(), TRUE, two, wl_psi_term::type, wl_psi_term::value_3, variable, and wl_const_3.
void show | ( | long | limit | ) |
show
limit | - long limit |
SHOW(limit) This prints the parser's stack, for debugging purposes only, LIMIT marks the bottom of the current stack.
Definition at line 64 of file parser.c.
References display_psi_stdout(), fx, int_stack, nop, parser_stack_index, psi_term_stack, xf, and xfx.
ptr_psi_term stack_copy_psi_term | ( | psi_term | t | ) |
stack_copy_psi_term
t | - psi_term t |
STACK_COPY_PSI_TERM(tok) Return the address of a copy of TOK on the STACK. All psi_terms read in by the parser are read into the stack.
Definition at line 205 of file parser.c.
References global_time_stamp, and STACK_ALLOC.