# #include "fastparse.h"

This page has information from files fastparse.h and fastparse.c.

## Contents

- Public Routines
- Public Definitions
- Introduction

## Public Routines in File fastparse.c

#### Index

fast_fwrite_clause | fast_read_clause | fast_set_defaults |
fast_fwrite_term_nl | fast_read_term | fast_set_symbol |

#### Details

    void fast_fwrite_clause(FILE *fp, Topform c);

This routine writes a clause in fastparse form.

    void fast_fwrite_term_nl(FILE *fp, Term t);

This routine writes a term in prefix form, without parentheses, commas, or spaces, followed by ".\n". If a variable number is >= 9, then '?' is printed for that variable.

If each symbol is one character, then terms written by this routine should be readable by fast_read_term().

There is nothing particularly "fast" about this routine.

    Topform fast_read_clause(FILE *fin, FILE *fout);

This routine reads a clause in fast-parse form.

If the clause has more than one literal, then '|' must first be declared as binary with fast_set_symbol(), and if the clause has any negative literals, then '~' must first be declared as unary.

For example, the fast-parse form of p(a,b) | ~q | ~(f(x)=x) is

    |pab|~q~=fxx.

    Term fast_read_term(FILE *fin, FILE *fout);

This routine reads a prefix term.

- The term must start on a new line and end with a period.
- Without parentheses, commas, or spaces.
- Each symbol is one character.
- Variables are 'r' -- 'z'.
- Symbols with arity > 0 (including '=') must declared first by calling fast_set_symbol().
- If the first character is '%', the line is a comment and sent directly to the output stream fout.
- Example:

      =mxxx.
      =jxyjyx.
      =jxxmxx.
      =jjxyzjxjyz.

    void fast_set_defaults(void);

Call this routine to declare a fixed set of symbols for fast parsing.

- binary: [=mjfd*+/]
- unary: [cgi-~']

The defaults can be overridden by nsubsequent calls to fast_set_symbol

    void fast_set_symbol(char c, int arity);

Call this routine to declare a symbol/arity for fast parsing. Since fast parsing handles single-characters symbols only, you send character/arity to this routine.

For fast parsing, variables are always 'r' -- 'z', and those symbols should not be declared.

Also, you don't need to call this routine for constants.

## Public Definitions in File fastparse.h

## Introduction

This package is meant for use when there are a great number of terms to be read and written. I wrote it when I was looking for a single axiom for lattice theory and was filtering trillions (really) of equations.

The ordinary parsing is very general and rather slow.

This package reads and writes prefix terms, without parentheses commas, or spaces. Each symbol is one character. Each term to be read starts on a new line and ends with a period. The user has to declare the arities of symbols by calling fast_set_symbol().

Here's an example to read lattice equations in fast-parse form and write them in ordinary form.

    int main(int argc, char **argv)
    {
      Term t;
      fast_set_symbol('=', 2);
      fast_set_symbol('m', 2);
      fast_set_symbol('j', 2);
      t = fast_read_term(stdin, stderr);
      while (t != NULL) {
        fwrite_term_nl(stdout, t);
        zap_term(t);
        t = fast_read_term(stdin, stderr);
      }
      exit(0);
    }

There are also routines for reading and writing fast-parse clauses.