src/HOL/TPTP/TPTP_Parser/tptp.yacc
author sultana
Wed, 04 Apr 2012 16:29:17 +0100
changeset 48218 d1ecc9cec531
parent 48216 26c4e431ef05
child 48440 fce9d97a3258
permissions -rw-r--r--
tuned;
     1 open TPTP_Syntax
     2 
     3 exception UNRECOGNISED_SYMBOL of string * string
     4 
     5 exception UNRECOGNISED_ROLE of string
     6 fun classify_role role =
     7   case role of
     8     "axiom" => Role_Axiom
     9   | "hypothesis" => Role_Hypothesis
    10   | "definition" => Role_Definition
    11   | "assumption" => Role_Assumption
    12   | "lemma" => Role_Lemma
    13   | "theorem" => Role_Theorem
    14   | "conjecture" => Role_Conjecture
    15   | "negated_conjecture" => Role_Negated_Conjecture
    16   | "plain" => Role_Plain
    17   | "fi_domain" => Role_Fi_Domain
    18   | "fi_functors" => Role_Fi_Functors
    19   | "fi_predicates" => Role_Fi_Predicates
    20   | "type" => Role_Type
    21   | "unknown" => Role_Unknown
    22   | thing => raise (UNRECOGNISED_ROLE thing)
    23 
    24 fun extract_quant_info (Quant (quantifier, vars, tptp_formula)) =
    25   (quantifier, vars, tptp_formula)
    26 
    27 %%
    28 %name TPTP
    29 %term AMPERSAND | AT_SIGN | CARET | COLON | COMMA | EQUALS | EXCLAMATION
    30   | LET | ARROW | FI | IFF | IMPLIES | INCLUDE
    31   | LAMBDA | LBRKT | LPAREN | MAP_TO | MMINUS | NAND
    32   | NEQUALS | XOR | NOR | PERIOD | PPLUS | QUESTION | RBRKT | RPAREN
    33   | TILDE | TOK_FALSE | TOK_I | TOK_O | TOK_INT | TOK_REAL | TOK_RAT | TOK_TRUE
    34   | TOK_TYPE | VLINE | EOF | DTHF | DFOF | DCNF | DFOT | DTFF | REAL of string
    35   | RATIONAL of string | SIGNED_INTEGER of string | UNSIGNED_INTEGER of string
    36   | DOT_DECIMAL of string | SINGLE_QUOTED of string | UPPER_WORD of string
    37   | LOWER_WORD of string | COMMENT of string
    38   | DISTINCT_OBJECT of string
    39   | DUD | INDEF_CHOICE | DEFIN_CHOICE
    40   | OPERATOR_FORALL | OPERATOR_EXISTS
    41   | PLUS | TIMES | GENTZEN_ARROW | DEP_SUM | DEP_PROD
    42   | DOLLAR_WORD of string | DOLLAR_DOLLAR_WORD of string
    43   | SUBTYPE | LET_TERM
    44   | THF | TFF | FOF | CNF
    45   | ITE_F | ITE_T
    46   | LET_TF | LET_FF | LET_FT | LET_TT
    47 
    48 %nonterm
    49     annotations of annotation option
    50   | name of string
    51   | name_list of string list
    52   | formula_selection of string list
    53   | optional_info of general_term list
    54   | general_list of general_list | general_terms of general_term list
    55   | general_term of general_term
    56 
    57   | atomic_word of string
    58   | general_data of general_data | variable_ of string
    59   | number of number_kind * string | formula_data of general_data
    60   | integer of string
    61   | identifier of string
    62   | general_function of general_data | useful_info of general_list
    63   | file_name of string
    64   | functor_ of symbol
    65   | term of tptp_term
    66   | arguments of tptp_term list
    67   | defined_functor of symbol
    68   | system_functor of symbol
    69   | system_constant of symbol
    70   | system_term of symbol * tptp_term list
    71   | defined_constant of symbol
    72   | defined_plain_term of symbol * tptp_term list
    73   | defined_atomic_term of tptp_term
    74   | defined_atom of tptp_term
    75   | defined_term of tptp_term
    76   | constant of symbol
    77   | plain_term of symbol * tptp_term list
    78   | function_term of tptp_term
    79   | conditional_term of tptp_term
    80   | system_atomic_formula of tptp_formula
    81   | infix_equality of symbol
    82   | infix_inequality of symbol
    83   | defined_infix_pred of symbol
    84   | defined_infix_formula of tptp_formula
    85   | defined_prop of string
    86   | defined_pred of string
    87   | defined_plain_formula of tptp_formula
    88   | defined_atomic_formula of tptp_formula
    89   | plain_atomic_formula of tptp_formula
    90   | atomic_formula of tptp_formula
    91   | unary_connective of symbol
    92 
    93   | defined_type of tptp_base_type
    94   | system_type of string
    95   | assoc_connective of symbol
    96   | binary_connective of symbol
    97   | fol_quantifier of quantifier
    98   | thf_unary_connective of symbol
    99   | thf_pair_connective of symbol
   100   | thf_quantifier of quantifier
   101   | fol_infix_unary of tptp_formula
   102   | thf_conn_term of symbol
   103   | literal of tptp_formula
   104   | disjunction of tptp_formula
   105   | cnf_formula of tptp_formula
   106   | fof_tuple_list of tptp_formula list
   107   | fof_tuple of tptp_formula list
   108   | fof_sequent of tptp_formula
   109   | fof_unary_formula of tptp_formula
   110   | fof_variable_list of string list
   111   | fof_quantified_formula of tptp_formula
   112   | fof_unitary_formula of tptp_formula
   113   | fof_and_formula of tptp_formula
   114   | fof_or_formula of tptp_formula
   115   | fof_binary_assoc of tptp_formula
   116   | fof_binary_nonassoc of tptp_formula
   117   | fof_binary_formula of tptp_formula
   118   | fof_logic_formula of tptp_formula
   119   | fof_formula of tptp_formula
   120   | tff_tuple of tptp_formula list
   121   | tff_tuple_list of tptp_formula list
   122   | tff_sequent of tptp_formula
   123   | tff_conditional of tptp_formula
   124   | tff_xprod_type of tptp_type
   125   | tff_mapping_type of tptp_type
   126   | tff_atomic_type of tptp_type
   127   | tff_unitary_type of tptp_type
   128   | tff_top_level_type of tptp_type
   129   | tff_untyped_atom of symbol * tptp_type option
   130   | tff_typed_atom of symbol * tptp_type option
   131   | tff_unary_formula of tptp_formula
   132   | tff_typed_variable of string * tptp_type option
   133   | tff_variable of string * tptp_type option
   134   | tff_variable_list of (string * tptp_type option) list
   135   | tff_quantified_formula of tptp_formula
   136   | tff_unitary_formula of tptp_formula
   137   | tff_and_formula of tptp_formula
   138   | tff_or_formula of tptp_formula
   139   | tff_binary_assoc of tptp_formula
   140   | tff_binary_nonassoc of tptp_formula
   141   | tff_binary_formula of tptp_formula
   142   | tff_logic_formula of tptp_formula
   143   | tff_formula of tptp_formula
   144 
   145   | thf_tuple of tptp_formula list
   146   | thf_tuple_list of tptp_formula list
   147   | thf_sequent of tptp_formula
   148   | thf_conditional of tptp_formula
   149   | thf_let of tptp_formula
   150   | thf_atom of tptp_formula
   151   | thf_union_type of tptp_type
   152   | thf_xprod_type of tptp_type
   153   | thf_mapping_type of tptp_type
   154   | thf_binary_type of tptp_type
   155   | thf_unitary_type of tptp_type
   156   | thf_top_level_type of tptp_type
   157   | thf_subtype of tptp_type
   158   | thf_typeable_formula of tptp_formula
   159   | thf_type_formula of tptp_formula * tptp_type
   160   | thf_unary_formula of tptp_formula
   161   | thf_typed_variable of string * tptp_type option
   162   | thf_variable of string * tptp_type option
   163   | thf_variable_list of (string * tptp_type option) list
   164   | thf_quantified_formula of tptp_formula
   165   | thf_unitary_formula of tptp_formula
   166   | thf_apply_formula of tptp_formula
   167   | thf_and_formula of tptp_formula
   168   | thf_or_formula of tptp_formula
   169   | thf_binary_tuple of tptp_formula
   170   | thf_binary_pair of tptp_formula
   171   | thf_binary_formula of tptp_formula
   172   | thf_logic_formula of tptp_formula
   173   | thf_formula of tptp_formula
   174   | formula_role of role
   175 
   176   | cnf_annotated of tptp_line
   177   | fof_annotated of tptp_line
   178   | tff_annotated of tptp_line
   179   | thf_annotated of tptp_line
   180   | annotated_formula of tptp_line
   181   | include_ of tptp_line
   182   | tptp_input of tptp_line
   183   | tptp_file of tptp_problem
   184   | tptp of tptp_problem
   185 
   186   | thf_let_defn of tptp_let list
   187   | tff_let of tptp_formula
   188   | tff_let_term_defn of tptp_let list
   189   | tff_let_formula_defn of tptp_let list
   190   | tff_quantified_type of tptp_type
   191   | tff_monotype of tptp_type
   192   | tff_type_arguments of tptp_type list
   193   | let_term of tptp_term
   194   | atomic_defined_word of string
   195   | atomic_system_word of string
   196 
   197 %pos int
   198 %eop EOF
   199 %noshift EOF
   200 %arg (file_name) : string
   201 
   202 %nonassoc LET
   203 %nonassoc RPAREN
   204 %nonassoc DUD
   205 %right COMMA
   206 %left COLON
   207 
   208 %left AT_SIGN
   209 %nonassoc IFF XOR
   210 %right IMPLIES FI
   211 %nonassoc EQUALS NEQUALS
   212 %right VLINE NOR
   213 %left AMPERSAND NAND
   214 %right ARROW
   215 %left PLUS
   216 %left TIMES
   217 
   218 %right OPERATOR_FORALL OPERATOR_EXISTS
   219 
   220 %nonassoc EXCLAMATION QUESTION LAMBDA CARET
   221 %nonassoc TILDE
   222 %pure
   223 %start tptp
   224 %verbose
   225 %%
   226 
   227 (*  Title:      HOL/TPTP/TPTP_Parser/tptp.yacc
   228     Author:     Nik Sultana, Cambridge University Computer Laboratory
   229 
   230  Parser for TPTP languages. Latest version of the language spec can
   231  be obtained from http://www.cs.miami.edu/~tptp/TPTP/SyntaxBNF.html
   232  This implements version 5.3.0.
   233 *)
   234 
   235 tptp : tptp_file (( tptp_file ))
   236 
   237 tptp_file : tptp_input tptp_file (( tptp_input :: tptp_file ))
   238           | COMMENT tptp_file    (( tptp_file ))
   239           |                      (( [] ))
   240 
   241 tptp_input : annotated_formula (( annotated_formula ))
   242            | include_           (( include_ ))
   243 
   244 annotated_formula : thf_annotated (( thf_annotated ))
   245                   | tff_annotated (( tff_annotated ))
   246                   | fof_annotated (( fof_annotated ))
   247                   | cnf_annotated (( cnf_annotated ))
   248 
   249 thf_annotated : THF LPAREN name COMMA formula_role COMMA thf_formula annotations RPAREN PERIOD ((
   250   Annotated_Formula ((file_name, THFleft + 1, THFright + 1),
   251    THF, name, formula_role, thf_formula, annotations)
   252 ))
   253 
   254 tff_annotated : TFF LPAREN name COMMA formula_role COMMA tff_formula annotations RPAREN PERIOD ((
   255   Annotated_Formula ((file_name, TFFleft + 1, TFFright + 1),
   256    TFF, name, formula_role, tff_formula, annotations)
   257 ))
   258 
   259 fof_annotated : FOF LPAREN name COMMA formula_role COMMA fof_formula annotations RPAREN PERIOD ((
   260   Annotated_Formula ((file_name, FOFleft + 1, FOFright + 1),
   261    FOF, name, formula_role, fof_formula, annotations)
   262 ))
   263 
   264 cnf_annotated : CNF LPAREN name COMMA formula_role COMMA cnf_formula annotations RPAREN PERIOD ((
   265   Annotated_Formula ((file_name, CNFleft + 1, CNFright + 1),
   266    CNF, name, formula_role, cnf_formula, annotations)
   267 ))
   268 
   269 annotations : COMMA general_term optional_info (( SOME (general_term, optional_info) ))
   270             |                                  (( NONE ))
   271 
   272 formula_role : LOWER_WORD (( classify_role LOWER_WORD ))
   273 
   274 
   275 (* THF formulas *)
   276 
   277 thf_formula : thf_logic_formula (( thf_logic_formula ))
   278             | thf_sequent       (( thf_sequent ))
   279 
   280 thf_logic_formula : thf_binary_formula   (( thf_binary_formula ))
   281                   | thf_unitary_formula  (( thf_unitary_formula ))
   282                   | thf_type_formula     (( THF_typing thf_type_formula ))
   283                   | thf_subtype          (( Type_fmla thf_subtype ))
   284 
   285 thf_binary_formula : thf_binary_pair   (( thf_binary_pair ))
   286                    | thf_binary_tuple  (( thf_binary_tuple ))
   287                    | thf_binary_type   (( Type_fmla thf_binary_type ))
   288 
   289 thf_binary_pair : thf_unitary_formula thf_pair_connective thf_unitary_formula ((
   290   Fmla (thf_pair_connective, [thf_unitary_formula1, thf_unitary_formula2])
   291 ))
   292 
   293 thf_binary_tuple : thf_or_formula    (( thf_or_formula ))
   294                  | thf_and_formula   (( thf_and_formula ))
   295                  | thf_apply_formula (( thf_apply_formula ))
   296 
   297 thf_or_formula : thf_unitary_formula VLINE thf_unitary_formula (( Fmla (Interpreted_Logic Or, [thf_unitary_formula1, thf_unitary_formula2]) ))
   298                | thf_or_formula VLINE thf_unitary_formula      (( Fmla (Interpreted_Logic Or, [thf_or_formula, thf_unitary_formula]) ))
   299 
   300 thf_and_formula : thf_unitary_formula AMPERSAND thf_unitary_formula (( Fmla (Interpreted_Logic And, [thf_unitary_formula1, thf_unitary_formula2]) ))
   301                 | thf_and_formula AMPERSAND thf_unitary_formula     (( Fmla (Interpreted_Logic And, [thf_and_formula, thf_unitary_formula]) ))
   302 
   303 thf_apply_formula : thf_unitary_formula AT_SIGN thf_unitary_formula (( Fmla (Interpreted_ExtraLogic Apply, [thf_unitary_formula1, thf_unitary_formula2]) ))
   304                   | thf_apply_formula AT_SIGN thf_unitary_formula   (( Fmla (Interpreted_ExtraLogic Apply, [thf_apply_formula, thf_unitary_formula]) ))
   305 
   306 thf_unitary_formula : thf_quantified_formula (( thf_quantified_formula ))
   307                     | thf_unary_formula      (( thf_unary_formula ))
   308                     | thf_atom               (( thf_atom ))
   309                     | thf_conditional        (( thf_conditional ))
   310                     | thf_let                (( thf_let ))
   311                     | LPAREN thf_logic_formula RPAREN  (( thf_logic_formula ))
   312 
   313 thf_quantified_formula : thf_quantifier LBRKT thf_variable_list RBRKT COLON thf_unitary_formula ((
   314   Quant (thf_quantifier, thf_variable_list, thf_unitary_formula)
   315 ))
   316 
   317 thf_variable_list : thf_variable                          (( [thf_variable] ))
   318                   | thf_variable COMMA thf_variable_list  (( thf_variable :: thf_variable_list ))
   319 
   320 thf_variable : thf_typed_variable (( thf_typed_variable ))
   321              | variable_          (( (variable_, NONE) ))
   322 
   323 thf_typed_variable : variable_ COLON thf_top_level_type (( (variable_, SOME thf_top_level_type) ))
   324 
   325 thf_unary_formula : thf_unary_connective LPAREN thf_logic_formula RPAREN ((
   326   Fmla (thf_unary_connective, [thf_logic_formula])
   327 ))
   328 
   329 thf_atom : term          (( Atom (THF_Atom_term term) ))
   330          | thf_conn_term (( Atom (THF_Atom_conn_term thf_conn_term) ))
   331 
   332 thf_conditional : ITE_F LPAREN thf_logic_formula COMMA thf_logic_formula COMMA thf_logic_formula RPAREN ((
   333   Conditional (thf_logic_formula1, thf_logic_formula2, thf_logic_formula3)
   334 ))
   335 
   336 thf_let : LET_TF LPAREN thf_let_defn COMMA thf_formula RPAREN ((
   337   Let (thf_let_defn, thf_formula)
   338 ))
   339 
   340 (*FIXME here could check that fmla is of right form (TPTP BNF L130-134)*)
   341 thf_let_defn : thf_quantified_formula ((
   342   let
   343     val (_, vars, fmla) = extract_quant_info thf_quantified_formula
   344   in [Let_fmla (hd vars, fmla)]
   345   end
   346 ))
   347 
   348 thf_type_formula : thf_typeable_formula COLON thf_top_level_type (( (thf_typeable_formula, thf_top_level_type) ))
   349 
   350 thf_typeable_formula : thf_atom                         (( thf_atom ))
   351                      | LPAREN thf_logic_formula RPAREN  (( thf_logic_formula ))
   352 
   353 thf_subtype : constant SUBTYPE constant (( Subtype(constant1, constant2) ))
   354 
   355 thf_top_level_type : thf_logic_formula (( Fmla_type thf_logic_formula ))
   356 
   357 thf_unitary_type : thf_unitary_formula (( Fmla_type thf_unitary_formula ))
   358 
   359 thf_binary_type : thf_mapping_type (( thf_mapping_type ))
   360                 | thf_xprod_type   (( thf_xprod_type ))
   361                 | thf_union_type   (( thf_union_type ))
   362 
   363 thf_mapping_type : thf_unitary_type ARROW thf_unitary_type (( Fn_type(thf_unitary_type1, thf_unitary_type2) ))
   364                  | thf_unitary_type ARROW thf_mapping_type (( Fn_type(thf_unitary_type, thf_mapping_type) ))
   365 
   366 thf_xprod_type : thf_unitary_type TIMES thf_unitary_type   (( Prod_type(thf_unitary_type1, thf_unitary_type2) ))
   367                | thf_xprod_type TIMES thf_unitary_type     (( Prod_type(thf_xprod_type, thf_unitary_type) ))
   368 
   369 thf_union_type : thf_unitary_type PLUS thf_unitary_type    (( Sum_type(thf_unitary_type1, thf_unitary_type2) ))
   370                | thf_union_type PLUS thf_unitary_type      (( Sum_type(thf_union_type, thf_unitary_type) ))
   371 
   372 thf_sequent : thf_tuple GENTZEN_ARROW thf_tuple  (( Sequent(thf_tuple1, thf_tuple2) ))
   373             | LPAREN thf_sequent RPAREN          (( thf_sequent ))
   374 
   375 thf_tuple : LBRKT RBRKT                (( [] ))
   376           | LBRKT thf_tuple_list RBRKT (( thf_tuple_list ))
   377 
   378 thf_tuple_list : thf_logic_formula                      (( [thf_logic_formula] ))
   379                | thf_logic_formula COMMA thf_tuple_list (( thf_logic_formula :: thf_tuple_list ))
   380 
   381 
   382 (* TFF Formulas *)
   383 
   384 tff_formula : tff_logic_formula  (( tff_logic_formula ))
   385             | tff_typed_atom     (( Atom (TFF_Typed_Atom tff_typed_atom) ))
   386             | tff_sequent        (( tff_sequent ))
   387 
   388 tff_logic_formula : tff_binary_formula   (( tff_binary_formula ))
   389                   | tff_unitary_formula  (( tff_unitary_formula ))
   390 
   391 tff_binary_formula : tff_binary_nonassoc (( tff_binary_nonassoc ))
   392                    | tff_binary_assoc    (( tff_binary_assoc ))
   393 
   394 tff_binary_nonassoc : tff_unitary_formula binary_connective tff_unitary_formula (( Fmla (binary_connective, [tff_unitary_formula1, tff_unitary_formula2]) ))
   395 
   396 tff_binary_assoc : tff_or_formula  (( tff_or_formula ))
   397                  | tff_and_formula (( tff_and_formula ))
   398 
   399 tff_or_formula : tff_unitary_formula VLINE tff_unitary_formula      (( Fmla (Interpreted_Logic Or, [tff_unitary_formula1, tff_unitary_formula2]) ))
   400                | tff_or_formula VLINE tff_unitary_formula           (( Fmla (Interpreted_Logic Or, [tff_or_formula, tff_unitary_formula]) ))
   401 
   402 tff_and_formula : tff_unitary_formula AMPERSAND tff_unitary_formula (( Fmla (Interpreted_Logic And, [tff_unitary_formula1, tff_unitary_formula2]) ))
   403                 | tff_and_formula AMPERSAND tff_unitary_formula     (( Fmla (Interpreted_Logic And, [tff_and_formula, tff_unitary_formula]) ))
   404 
   405 tff_unitary_formula : tff_quantified_formula           (( tff_quantified_formula ))
   406                     | tff_unary_formula                (( tff_unary_formula ))
   407                     | atomic_formula                   (( atomic_formula ))
   408                     | tff_conditional                  (( tff_conditional ))
   409                     | tff_let                          (( tff_let ))
   410                     | LPAREN tff_logic_formula RPAREN  (( tff_logic_formula ))
   411 
   412 tff_quantified_formula : fol_quantifier LBRKT tff_variable_list RBRKT COLON tff_unitary_formula ((
   413   Quant (fol_quantifier, tff_variable_list, tff_unitary_formula)
   414 ))
   415 
   416 tff_variable_list : tff_variable                         (( [tff_variable] ))
   417                   | tff_variable COMMA tff_variable_list (( tff_variable :: tff_variable_list ))
   418 
   419 tff_variable : tff_typed_variable (( tff_typed_variable ))
   420              | variable_          (( (variable_, NONE) ))
   421 
   422 tff_typed_variable : variable_ COLON tff_atomic_type (( (variable_, SOME tff_atomic_type) ))
   423 
   424 tff_unary_formula : unary_connective tff_unitary_formula (( Fmla (unary_connective, [tff_unitary_formula]) ))
   425                   | fol_infix_unary                      (( fol_infix_unary ))
   426 
   427 tff_conditional : ITE_F LPAREN tff_logic_formula COMMA tff_logic_formula COMMA tff_logic_formula RPAREN ((
   428   Conditional (tff_logic_formula1, tff_logic_formula2, tff_logic_formula3)
   429 ))
   430 
   431 tff_let : LET_TF LPAREN tff_let_term_defn COMMA tff_formula RPAREN ((Let (tff_let_term_defn, tff_formula) ))
   432         | LET_FF LPAREN tff_let_formula_defn COMMA tff_formula RPAREN (( Let (tff_let_formula_defn, tff_formula) ))
   433 
   434 (*FIXME here could check that fmla is of right form (TPTP BNF L210-214)*)
   435 (*FIXME why "term" if using "Let_fmla"?*)
   436 tff_let_term_defn : tff_quantified_formula ((
   437   let
   438     val (_, vars, fmla) = extract_quant_info tff_quantified_formula
   439   in [Let_fmla (hd vars, fmla)]
   440   end
   441 ))
   442 
   443 (*FIXME here could check that fmla is of right form (TPTP BNF L215-217)*)
   444 tff_let_formula_defn : tff_quantified_formula ((
   445   let
   446     val (_, vars, fmla) = extract_quant_info tff_quantified_formula
   447   in [Let_fmla (hd vars, fmla)]
   448   end
   449 ))
   450 
   451 tff_sequent : tff_tuple GENTZEN_ARROW tff_tuple (( Sequent (tff_tuple1, tff_tuple2) ))
   452             | LPAREN tff_sequent RPAREN         (( tff_sequent ))
   453 
   454 tff_tuple : LBRKT RBRKT    (( [] ))
   455           | LBRKT tff_tuple_list RBRKT (( tff_tuple_list ))
   456 
   457 tff_tuple_list : tff_logic_formula COMMA tff_tuple_list (( tff_logic_formula :: tff_tuple_list ))
   458                | tff_logic_formula                      (( [tff_logic_formula] ))
   459 
   460 tff_typed_atom : tff_untyped_atom COLON tff_top_level_type (( (fst tff_untyped_atom, SOME tff_top_level_type) ))
   461                | LPAREN tff_typed_atom RPAREN              (( tff_typed_atom ))
   462 
   463 tff_untyped_atom : functor_       (( (functor_, NONE) ))
   464                  | system_functor (( (system_functor, NONE) ))
   465 
   466 tff_top_level_type : tff_atomic_type     (( tff_atomic_type ))
   467                    | tff_mapping_type    (( tff_mapping_type ))
   468                    | tff_quantified_type (( tff_quantified_type ))
   469 
   470 tff_quantified_type : DEP_PROD LBRKT tff_variable_list RBRKT COLON tff_monotype ((
   471        Fmla_type (Quant (Dep_Prod, tff_variable_list, Type_fmla tff_monotype))
   472 ))
   473                     | LPAREN tff_quantified_type RPAREN (( tff_quantified_type ))
   474 
   475 tff_monotype : tff_atomic_type                (( tff_atomic_type ))
   476              | LPAREN tff_mapping_type RPAREN (( tff_mapping_type ))
   477 
   478 tff_unitary_type : tff_atomic_type               (( tff_atomic_type ))
   479                  | LPAREN tff_xprod_type RPAREN  (( tff_xprod_type ))
   480 
   481 tff_atomic_type : atomic_word   (( Atom_type atomic_word ))
   482                 | defined_type  (( Defined_type defined_type ))
   483                 | atomic_word LPAREN tff_type_arguments RPAREN (( Fmla_type (Fmla (Uninterpreted atomic_word, (map Type_fmla tff_type_arguments))) ))
   484                 | variable_ (( Fmla_type (Pred (Interpreted_ExtraLogic Apply, [Term_Var variable_])) ))
   485 
   486 tff_type_arguments : tff_atomic_type   (( [tff_atomic_type]  ))
   487                    | tff_atomic_type COMMA tff_type_arguments (( tff_atomic_type :: tff_type_arguments ))
   488 
   489 tff_mapping_type : tff_unitary_type ARROW tff_atomic_type (( Fn_type(tff_unitary_type, tff_atomic_type) ))
   490                  | LPAREN tff_mapping_type RPAREN         (( tff_mapping_type ))
   491 
   492 tff_xprod_type : tff_atomic_type TIMES tff_atomic_type (( Prod_type(tff_atomic_type1, tff_atomic_type2) ))
   493                | tff_xprod_type TIMES tff_atomic_type  (( Prod_type(tff_xprod_type, tff_atomic_type) ))
   494                | LPAREN tff_xprod_type RPAREN          (( tff_xprod_type ))
   495 
   496 
   497 (* FOF Formulas *)
   498 
   499 fof_formula : fof_logic_formula  (( fof_logic_formula ))
   500             | fof_sequent        (( fof_sequent ))
   501 
   502 fof_logic_formula : fof_binary_formula   (( fof_binary_formula ))
   503                   | fof_unitary_formula  (( fof_unitary_formula ))
   504 
   505 fof_binary_formula : fof_binary_nonassoc (( fof_binary_nonassoc ))
   506                    | fof_binary_assoc    (( fof_binary_assoc ))
   507 
   508 fof_binary_nonassoc : fof_unitary_formula binary_connective fof_unitary_formula ((
   509   Fmla (binary_connective, [fof_unitary_formula1, fof_unitary_formula2] )
   510 ))
   511 
   512 fof_binary_assoc : fof_or_formula  (( fof_or_formula ))
   513                  | fof_and_formula (( fof_and_formula ))
   514 
   515 fof_or_formula : fof_unitary_formula VLINE fof_unitary_formula  (( Fmla (Interpreted_Logic Or, [fof_unitary_formula1, fof_unitary_formula2]) ))
   516                | fof_or_formula VLINE fof_unitary_formula       (( Fmla (Interpreted_Logic Or, [fof_or_formula, fof_unitary_formula]) ))
   517 
   518 fof_and_formula : fof_unitary_formula AMPERSAND fof_unitary_formula (( Fmla (Interpreted_Logic And, [fof_unitary_formula1, fof_unitary_formula2]) ))
   519                 | fof_and_formula AMPERSAND fof_unitary_formula     (( Fmla (Interpreted_Logic And, [fof_and_formula, fof_unitary_formula]) ))
   520 
   521 fof_unitary_formula : fof_quantified_formula (( fof_quantified_formula ))
   522                     | fof_unary_formula      (( fof_unary_formula ))
   523                     | atomic_formula         (( atomic_formula ))
   524                     | LPAREN fof_logic_formula RPAREN (( fof_logic_formula ))
   525 
   526 fof_quantified_formula : fol_quantifier LBRKT fof_variable_list RBRKT COLON fof_unitary_formula ((
   527   Quant (fol_quantifier, map (fn v => (v, NONE)) fof_variable_list, fof_unitary_formula)
   528 ))
   529 
   530 fof_variable_list : variable_                          (( [variable_] ))
   531                   | variable_ COMMA fof_variable_list  (( variable_ :: fof_variable_list ))
   532 
   533 fof_unary_formula : unary_connective fof_unitary_formula (( Fmla (unary_connective, [fof_unitary_formula]) ))
   534                   | fol_infix_unary                      (( fol_infix_unary ))
   535 
   536 fof_sequent : fof_tuple GENTZEN_ARROW fof_tuple (( Sequent (fof_tuple1, fof_tuple2) ))
   537             | LPAREN fof_sequent RPAREN         (( fof_sequent ))
   538 
   539 fof_tuple : LBRKT RBRKT                 (( [] ))
   540           | LBRKT fof_tuple_list RBRKT  (( fof_tuple_list ))
   541 
   542 fof_tuple_list : fof_logic_formula                      (( [fof_logic_formula] ))
   543                | fof_logic_formula COMMA fof_tuple_list (( fof_logic_formula :: fof_tuple_list ))
   544 
   545 
   546 (* CNF Formulas *)
   547 
   548 cnf_formula : LPAREN disjunction RPAREN  (( disjunction ))
   549             | disjunction                (( disjunction ))
   550 
   551 disjunction : literal                    (( literal ))
   552             | disjunction VLINE literal  (( Fmla (Interpreted_Logic Or, [disjunction, literal]) ))
   553 
   554 literal : atomic_formula        (( atomic_formula ))
   555         | TILDE atomic_formula  (( Fmla (Interpreted_Logic Not, [atomic_formula]) ))
   556         | fol_infix_unary       (( fol_infix_unary ))
   557 
   558 
   559 (* Special Formulas  *)
   560 
   561 thf_conn_term : thf_pair_connective   (( thf_pair_connective ))
   562               | assoc_connective      (( assoc_connective ))
   563               | thf_unary_connective  (( thf_unary_connective ))
   564 
   565 fol_infix_unary : term infix_inequality term (( Pred (infix_inequality, [term1, term2]) ))
   566 
   567 
   568 (* Connectives - THF *)
   569 
   570 thf_quantifier : fol_quantifier (( fol_quantifier ))
   571                | CARET          (( Lambda ))
   572                | DEP_PROD       (( Dep_Prod ))
   573                | DEP_SUM        (( Dep_Sum ))
   574                | INDEF_CHOICE   (( Epsilon ))
   575                | DEFIN_CHOICE   (( Iota ))
   576 
   577 thf_pair_connective : infix_equality    (( infix_equality ))
   578                     | infix_inequality  (( infix_inequality ))
   579                     | binary_connective (( binary_connective ))
   580 
   581 thf_unary_connective : unary_connective (( unary_connective ))
   582                      | OPERATOR_FORALL  (( Interpreted_Logic Op_Forall ))
   583                      | OPERATOR_EXISTS  (( Interpreted_Logic Op_Exists ))
   584 
   585 
   586 (* Connectives - THF and TFF
   587 instead of subtype_sign use token SUBTYPE
   588 *)
   589 
   590 
   591 (* Connectives - FOF *)
   592 
   593 fol_quantifier : EXCLAMATION  (( Forall ))
   594                | QUESTION     (( Exists ))
   595 
   596 binary_connective : IFF       (( Interpreted_Logic Iff ))
   597                   | IMPLIES   (( Interpreted_Logic If ))
   598                   | FI        (( Interpreted_Logic Fi ))
   599                   | XOR       (( Interpreted_Logic Xor ))
   600                   | NOR       (( Interpreted_Logic Nor ))
   601                   | NAND      (( Interpreted_Logic Nand ))
   602 
   603 assoc_connective : VLINE      (( Interpreted_Logic Or ))
   604                  | AMPERSAND  (( Interpreted_Logic And ))
   605 
   606 unary_connective : TILDE (( Interpreted_Logic Not ))
   607 
   608 
   609 (* The sequent arrow
   610 use token GENTZEN_ARROW
   611 *)
   612 
   613 
   614 (* Types for THF and TFF *)
   615 
   616 defined_type : atomic_defined_word ((
   617   case atomic_defined_word of
   618     "$oType" => Type_Bool
   619   | "$o" => Type_Bool
   620   | "$iType" => Type_Ind
   621   | "$i" => Type_Ind
   622   | "$tType" => Type_Type
   623   | "$real" => Type_Real
   624   | "$rat" => Type_Rat
   625   | "$int" => Type_Int
   626   | thing => raise UNRECOGNISED_SYMBOL ("defined_type", thing)
   627 ))
   628 
   629 system_type : atomic_system_word (( atomic_system_word ))
   630 
   631 
   632 (* First-order atoms *)
   633 
   634 atomic_formula : plain_atomic_formula   (( plain_atomic_formula ))
   635                | defined_atomic_formula (( defined_atomic_formula ))
   636                | system_atomic_formula  (( system_atomic_formula ))
   637 
   638 plain_atomic_formula : plain_term (( Pred plain_term ))
   639 
   640 defined_atomic_formula : defined_plain_formula (( defined_plain_formula ))
   641                        | defined_infix_formula (( defined_infix_formula ))
   642 
   643 defined_plain_formula : defined_plain_term (( Pred defined_plain_term ))
   644 
   645 (*FIXME not used*)
   646 defined_prop : atomic_defined_word ((
   647   case atomic_defined_word of
   648     "$true"  => "$true"
   649   | "$false" => "$false"
   650   | thing => raise UNRECOGNISED_SYMBOL ("defined_prop", thing)
   651 ))
   652 
   653 (*FIXME not used*)
   654 defined_pred : atomic_defined_word ((
   655   case atomic_defined_word of
   656     "$distinct"  => "$distinct"
   657   | "$ite_f" => "$ite_f"
   658   | "$less" => "$less"
   659   | "$lesseq" => "$lesseq"
   660   | "$greater" => "$greater"
   661   | "$greatereq" => "$greatereq"
   662   | "$is_int" => "$is_int"
   663   | "$is_rat" => "$is_rat"
   664   | thing => raise UNRECOGNISED_SYMBOL ("defined_pred", thing)
   665 ))
   666 
   667 defined_infix_formula : term defined_infix_pred term ((Pred (defined_infix_pred, [term1, term2])))
   668 
   669 defined_infix_pred : infix_equality  (( infix_equality ))
   670 
   671 infix_equality : EQUALS    (( Interpreted_Logic Equals ))
   672 
   673 infix_inequality : NEQUALS (( Interpreted_Logic NEquals ))
   674 
   675 system_atomic_formula : system_term  (( Pred system_term ))
   676 
   677 
   678 (* First-order terms *)
   679 
   680 term : function_term     (( function_term ))
   681      | variable_         (( Term_Var variable_ ))
   682      | conditional_term  (( conditional_term ))
   683      | let_term          (( let_term ))
   684 
   685 function_term : plain_term    (( Term_Func plain_term ))
   686               | defined_term  (( defined_term ))
   687               | system_term   (( Term_Func system_term ))
   688 
   689 plain_term : constant                          (( (constant, []) ))
   690            | functor_ LPAREN arguments RPAREN  (( (functor_, arguments) ))
   691 
   692 constant : functor_ (( functor_ ))
   693 
   694 functor_ : atomic_word (( Uninterpreted atomic_word ))
   695 
   696 defined_term : defined_atom        (( defined_atom ))
   697              | defined_atomic_term (( defined_atomic_term ))
   698 
   699 defined_atom : number          (( Term_Num number ))
   700              | DISTINCT_OBJECT (( Term_Distinct_Object DISTINCT_OBJECT ))
   701 
   702 defined_atomic_term : defined_plain_term (( Term_Func defined_plain_term ))
   703 
   704 defined_plain_term : defined_constant                        (( (defined_constant, []) ))
   705                    | defined_functor LPAREN arguments RPAREN (( (defined_functor, arguments) ))
   706 
   707 defined_constant : defined_functor (( defined_functor ))
   708 
   709 (*FIXME would be nicer to split these up*)
   710 defined_functor : atomic_defined_word ((
   711   case atomic_defined_word of
   712     "$uminus" => Interpreted_ExtraLogic UMinus
   713   | "$sum" => Interpreted_ExtraLogic Sum
   714   | "$difference" => Interpreted_ExtraLogic Difference
   715   | "$product" => Interpreted_ExtraLogic Product
   716   | "$quotient" => Interpreted_ExtraLogic Quotient
   717   | "$quotient_e" => Interpreted_ExtraLogic Quotient_E
   718   | "$quotient_t" => Interpreted_ExtraLogic Quotient_T
   719   | "$quotient_f" => Interpreted_ExtraLogic Quotient_F
   720   | "$remainder_e" => Interpreted_ExtraLogic Remainder_E
   721   | "$remainder_t" => Interpreted_ExtraLogic Remainder_T
   722   | "$remainder_f" => Interpreted_ExtraLogic Remainder_F
   723   | "$floor" => Interpreted_ExtraLogic Floor
   724   | "$ceiling" => Interpreted_ExtraLogic Ceiling
   725   | "$truncate" => Interpreted_ExtraLogic Truncate
   726   | "$round" => Interpreted_ExtraLogic Round
   727   | "$to_int" => Interpreted_ExtraLogic To_Int
   728   | "$to_rat" => Interpreted_ExtraLogic To_Rat
   729   | "$to_real" => Interpreted_ExtraLogic To_Real
   730 
   731   | "$i" => TypeSymbol Type_Ind
   732   | "$o" => TypeSymbol Type_Bool
   733   | "$iType" => TypeSymbol Type_Ind
   734   | "$oType" => TypeSymbol Type_Bool
   735   | "$int" => TypeSymbol Type_Int
   736   | "$real" => TypeSymbol Type_Real
   737   | "$rat" => TypeSymbol Type_Rat
   738   | "$tType" => TypeSymbol Type_Type
   739 
   740   | "$true" => Interpreted_Logic True
   741   | "$false" => Interpreted_Logic False
   742 
   743   | "$less" => Interpreted_ExtraLogic Less
   744   | "$lesseq" => Interpreted_ExtraLogic LessEq
   745   | "$greatereq" => Interpreted_ExtraLogic GreaterEq
   746   | "$greater" => Interpreted_ExtraLogic Greater
   747   | "$evaleq" => Interpreted_ExtraLogic EvalEq
   748 
   749   | "$is_int" => Interpreted_ExtraLogic Is_Int
   750   | "$is_rat" => Interpreted_ExtraLogic Is_Rat
   751 
   752   | "$distinct" => Interpreted_ExtraLogic Distinct
   753 
   754   | thing => raise UNRECOGNISED_SYMBOL ("defined_functor", thing)
   755 ))
   756 
   757 system_term : system_constant                         (( (system_constant, []) ))
   758             | system_functor LPAREN arguments RPAREN  (( (system_functor, arguments) ))
   759 
   760 system_constant : system_functor (( system_functor ))
   761 
   762 system_functor : atomic_system_word (( System atomic_system_word ))
   763 
   764 variable_ : UPPER_WORD  (( UPPER_WORD ))
   765 
   766 arguments : term                  (( [term] ))
   767           | term COMMA arguments  (( term :: arguments ))
   768 
   769 conditional_term : ITE_T LPAREN tff_logic_formula COMMA term COMMA term RPAREN ((
   770   Term_Conditional (tff_logic_formula, term1, term2)
   771 ))
   772 
   773 
   774 let_term : LET_FT LPAREN tff_let_formula_defn COMMA term RPAREN ((Term_Let (tff_let_formula_defn, term) ))
   775          | LET_TT LPAREN tff_let_term_defn COMMA term RPAREN ((Term_Let (tff_let_term_defn, term) ))
   776 
   777 
   778 (* Formula sources
   779 Don't currently use following non-terminals:
   780 source, sources, dag_source, inference_record, inference_rule, parent_list,
   781 parent_info, parent_details, internal_source, intro_type, external_source,
   782 file_source, file_info, theory, theory_name, creator_source, creator_name.
   783 *)
   784 
   785 
   786 (* Useful info fields *)
   787 
   788 optional_info : COMMA useful_info (( useful_info ))
   789               |                   (( [] ))
   790 
   791 useful_info : general_list (( general_list ))
   792 
   793 include_ : INCLUDE LPAREN file_name formula_selection RPAREN PERIOD ((
   794   Include (file_name, formula_selection)
   795 ))
   796 
   797 formula_selection : COMMA LBRKT name_list RBRKT   (( name_list  ))
   798                   |                               (( [] ))
   799 
   800 name_list : name COMMA name_list   (( name :: name_list ))
   801           | name                   (( [name] ))
   802 
   803 
   804 (* Non-logical data *)
   805 
   806 general_term : general_data                    (( General_Data general_data ))
   807              | general_data COLON general_term (( General_Term (general_data, general_term) ))
   808              | general_list                    (( General_List general_list ))
   809 
   810 general_data : atomic_word       (( Atomic_Word atomic_word ))
   811              | general_function  (( general_function ))
   812              | variable_         (( V variable_ ))
   813              | number            (( Number number ))
   814              | DISTINCT_OBJECT   (( Distinct_Object DISTINCT_OBJECT ))
   815              | formula_data      (( formula_data ))
   816 
   817 general_function: atomic_word LPAREN general_terms RPAREN (( Application (atomic_word, general_terms) ))
   818 
   819 formula_data : DTHF LPAREN thf_formula RPAREN (( Formula_Data (THF, thf_formula) ))
   820              | DTFF LPAREN tff_formula RPAREN (( Formula_Data (TFF, tff_formula) ))
   821              | DFOF LPAREN fof_formula RPAREN (( Formula_Data (FOF, fof_formula) ))
   822              | DCNF LPAREN cnf_formula RPAREN (( Formula_Data (CNF, cnf_formula) ))
   823              | DFOT LPAREN term RPAREN (( Term_Data term ))
   824 
   825 general_list : LBRKT general_terms RBRKT (( general_terms ))
   826              | LBRKT RBRKT               (( [] ))
   827 
   828 general_terms : general_term COMMA general_terms (( general_term :: general_terms ))
   829               | general_term                     (( [general_term] ))
   830 
   831 
   832 (* General purpose *)
   833 
   834 name : atomic_word (( atomic_word ))
   835      | integer     (( integer ))
   836 
   837 atomic_word : LOWER_WORD    (( LOWER_WORD ))
   838             | SINGLE_QUOTED (( SINGLE_QUOTED ))
   839             | THF           (( "thf" ))
   840             | TFF           (( "tff" ))
   841             | FOF           (( "fof" ))
   842             | CNF           (( "cnf" ))
   843             | INCLUDE       (( "include" ))
   844 
   845 atomic_defined_word : DOLLAR_WORD (( DOLLAR_WORD ))
   846 
   847 atomic_system_word : DOLLAR_DOLLAR_WORD (( DOLLAR_DOLLAR_WORD ))
   848 
   849 integer: UNSIGNED_INTEGER (( UNSIGNED_INTEGER ))
   850        | SIGNED_INTEGER   (( SIGNED_INTEGER ))
   851 
   852 number : integer          (( (Int_num, integer) ))
   853        | REAL             (( (Real_num, REAL) ))
   854        | RATIONAL         (( (Rat_num, RATIONAL) ))
   855 
   856 file_name : SINGLE_QUOTED (( SINGLE_QUOTED ))