home *** CD-ROM | disk | FTP | other *** search
- -------------------------------------------------------------------------------
- -- --
- -- Library Unit: Data_def -- Common data type definitions --
- -- --
- -- Author: Bradley L. Richards --
- -- --
- -- Version Date Notes . . . --
- -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
- -- 1.0 19 Jun 86 Initial Version (broken out from Token) --
- -- 2.0 20 Jun 86 Extracted token_type from Token as well --
- -- 2.1 21 Jul 86 Demonstration Version --
- -- 2.3 19 Aug 86 Combine strings and identifiers --
- -- 3.0 10 Oct 86 Final thesis product --
- -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
- -- --
- -- Library units used: none --
- -- --
- -------------------------------------------------------------------------------
- -- --
- -- Package Specification --
- -- --
- -------------------------------------------------------------------------------
-
- package data_def is
-
-
- --
- -- define special types required for identifier and string tokens
- --
-
- type name_record(size : positive := 1) is -- minimum of one character
- record
- name : string(1..size);
- end record;
- type name_ptr is access name_record;
-
- --
- -- This type defines all tokens which may be encountered in a Fuzzy
- -- Prolog source program. The tokens which represent reserved words
- -- (RW_xxx) only occur as elements under type "reserved_word." The
- -- grouping of these tokens is required to allow subtypes to be defined
- -- (see below)
- --
- type token_type is (character_lit, end_of_file, float_num, identifier,
- integer_num, null_token, reserved_word, variable,
- --
- -- special tokens
- --
- implication, left_bracket, left_paren, period,
- right_bracket, right_paren, underline,
- --
- -- binary operators
- --
- bar, comma, hat, semicolon,
- asterisk, minus, plus, slash, rw_mod,
- equal, equality, greater_or_equal, greater_than,
- less_or_equal, less_than, not_equal, not_equality,
- univ, rw_is,
- --
- -- unary operators
- --
- rw_nospy, rw_not, rw_spy,
-
- --
- -- reserved predicates
- --
- cut,
- rw_asserta, rw_assertz, rw_atom, rw_atomic, rw_call,
- rw_clause, rw_consult, rw_debugging, rw_display,
- rw_fail, rw_float, rw_functor, rw_fuzzy, rw_get,
- rw_get0, rw_integer, rw_listing, rw_ln, rw_log,
- rw_name, rw_nl, rw_nodebug, rw_nonvar, rw_notrace,
- rw_number, rw_op, rw_org, rw_parse, rw_put, rw_read,
- rw_repeat, rw_reset, rw_retract, rw_see, rw_seeing,
- rw_seen, rw_skip, rw_tab, rw_tell, rw_telling,
- rw_threshold, rw_told, rw_trace, rw_true, rw_user,
- rw_var, rw_write);
-
- subtype operators is token_type range bar..rw_spy;
- subtype binary_operators is token_type range bar..rw_is;
- subtype binary_logic_operators is token_type range bar..semicolon;
- subtype unary_operators is token_type range rw_nospy..rw_spy;
- subtype reserved_predicates is token_type range cut..rw_write;
-
- --
- -- Define the range of fuzzy values
- --
- subtype fuzzy_values is float range 0.0..1.0;
-
- --
- -- These declarations must be interlaced because of their mutual
- -- dependencies. They could be clarified somewhat by more use of
- -- multilevel variant records. Unfortunately, Dave Craine has shown
- -- that multilevel variants which contain pointers are not handled
- -- correctly by the Verdix compiler.
- --
- -- ident_data is a variant record which holds data corresponding to
- -- the type of the identifier.
- --
- -- Abstract Syntax Trees are built up out of operator nodes and leaf
- -- nodes. These are all variant types of type AST.
- --
-
- --
- -- define the types of things that can appear as arguments to predicates
- --
- type argument_type is (character_lit, float_num, integer_num, predicate,
- prolog_list, variable);
- --
- -- A couple of forward references
- --
- type p_list(has_tail : boolean);
- type p_list_ptr is access p_list;
- --
- -- Arguments are defined as a linked list of variant records. The
- -- representation of a Prolog list also uses these definitions, since
- -- the requirements are essentially identical.
- --
- type argument(is_a : argument_type);
- type argument_ptr is access argument;
- type argument(is_a : argument_type) is
- record
- next_arg : argument_ptr := null;
- case is_a is
- when character_lit => char : character := ' ';
- when float_num => fp_num : float := 0.0;
- when integer_num => int_num : integer := 0;
- when predicate => name : name_ptr := null;
- p_arguments : argument_ptr := null;
- when prolog_list => list : p_list_ptr := null;
- when variable => v_name : name_ptr := null;
- end case;
- end record;
-
- --
- -- Now we need to define the representation of a Fuzzy Prolog list.
- -- We'll leach off of the argument types, since they're what we need.
- --
- -- for example: [ a, b | X ]
- --
- type p_list(has_tail : boolean) is
- record
- elt : argument_ptr := null;
- case has_tail is
- when false => next_elt : p_list_ptr := null;
- when true => tail : argument_ptr := null;
- end case;
- end record;
-
- --
- -- Now to define the type of nodes we can have in our Abstract Syntax
- -- Tree (AST). These fall into two main categories: interior nodes and
- -- leaf nodes. All interior nodes represent operators of one variety or
- -- another; "implication" also links the clauses in the
- -- data base together. Similarly, leaf nodes generally represent operands.
- -- There are a few which are a bit different; for example, it may not be
- -- obvious at first glance that the "cut" is an operand, as are all calls
- -- to predicates.
- --
- type AST_node_type is (implication, binary_operator, unary_operator,
- predicate, integer_num, float_num, character_lit, fuzzy_value,
- reserved_predicate, variable, resolution_marker,
- threshold_marker);
- type AST(node_type : AST_node_type);
- type AST_ptr is access AST;
- type AST(node_type : AST_node_type) is
- record
- case node_type is
- --
- -- interior nodes
- --
- when implication => head, tail : AST_ptr := null;
- prev, next : AST_ptr := null;
- when binary_operator => binary_op : binary_operators;
- left_operand : AST_ptr := null;
- right_operand : AST_ptr := null;
- when unary_operator => unary_op : unary_operators;
- operand : AST_ptr := null;
- --
- -- leaf nodes
- --
- when predicate => name : name_ptr := null;
- p_arguments : argument_ptr := null;
- when integer_num => int_num : integer := 0;
- when float_num => fp_num : float := 0.0;
- when character_lit => char : character := ascii.nul;
- when fuzzy_value => fuzzy_num : fuzzy_values := 0.0;
- when reserved_predicate => predicate : reserved_predicates;
- r_arguments : argument_ptr := null;
- when variable => var_name : name_ptr;
- --
- -- interior nodes used only in Prover goal trees
- --
- when resolution_marker => level : natural;
- old_threshold : fuzzy_values;
- subgoals : AST_ptr;
- when threshold_marker => fuzzy_value : fuzzy_values;
- threshold : fuzzy_values;
- end case;
- end record;
-
- type binding;
- type binding_list is access binding;
- type binding is
- record
- name : name_ptr;
- level : natural;
- value : argument_ptr;
- value_level : natural;
- next_binding : binding_list;
- end record;
-
- end data_def;
-