next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Parsing > Parser

Parser -- the class of all parsers

Description

A parser is a type of function that parses a sequence of tokens. Tokens can be anything except null. A parser p is called repeatedly, like this: p t, one token at a time. The return value that indicates acceptance of the input token is a new parser, which replaces the old, and is ready to accept the next token; the original parser p should not change its internal state. The return value that indicates rejection of the input token is null. Rejection may be interpreted as a syntax error.

When the input stream is exhausted, we call p one more time like this: p null. The return value is null if the parser is not in a terminal state. Otherwise the return value is the parsed (and possibly evaluated) result.

Methods that use a parser :

Fixed objects of class Parser :

For the programmer

The object Parser is a self initializing type, with ancestor classes FunctionClosure < Function < Thing.

Menu

simple parsers

making new parsers from old ones