Previous Up Next

A.5  Changing the Parser’s behaviour

Some of these properties can be changed by choosing one of the following syntax options (see syntax_options in the description of get_flag/2). The following options exist (unless otherwise noted, the options are disabled by default):

disallow the use of an unquoted vertical bar as atom or functor, except when it occurs in infix-position.
translate occurrences of unquoted infix vertical bars into terms with functor ;/2, e.g. (a|b) = (a;b).
Allow base notation even to write integers longer than the wordsize (this implies they are always positive because the most significant bit is not interpreted as a sign bit).
ignore blank space between a sign and a number (by default, this space is significant and will lead to the sign being taken as prefix operator rather than the number’s sign). Also allow signs of numbers to be quoted.
parse a pair of quotes within a quoted item as one occurrence of the quote within the item (atom, string, or character list). If this option is off (the default), this is simply parsed as two consecutive items. In the case of strings and character lists, these consecutive items are concatenated into a single literal, unless the no_string_concatenation options is set.
do not treat end-of-file as a fullstop.
require floating point numbers to be written with a decimal point, e.g. 1.0e-3 instead of 1e-3.
ISO-Prolog compatible escape sequences within strings and atoms.
allow binary, octal or hexadecimal numbers to be written with 0b, 0o or 0x prefix respectively, and disallow the base’number notation.
enable all ISO-Prolog syntax restrictions that are not controlled by individual settings. This includes: disallowing operators as operands of operators; disallowing an atom to be declared as both an infix and a postfix operator; restrictions on changing operator properties for comma, vertical bar, and the empty-bracket atoms.
do not allow terms with a precedence higher than 999 as structure arguments, unless parenthesised.
allow bracketed comments to be nested.
allow newlines to occur inside quotes (default).
disallow the ECLiPSe specific array-subscript syntax.
disallow the ECLiPSe specific syntax for variable attributes in curly braces.
do not allow blanks between functor an opening parenthesis (default).
disallow the ECLiPSe specific syntax for structures with named arguments in curly braces.
do not parse consecutive string literals as a single (concatenated) string.
do not interpret a plus sign preceding a number as the number’s sign (effectively ignoring it), but treat it as a possible prefix operator +/1.
read all floating point numbers as bounded reals rather than as floats. The resulting breal is a small interval enclosing the true value of the number in decimal notation.
the predicates of the read-family fail when encountering a syntax error (after printing an error message). Without this option, the predicates throw an error term of the form error(syntax_error(MessageString), context(...)).
allow variables as functors, and parse a term like X(A,B,C) as if it were apply(X,[A,B,C]).

A number of further syntax options is provided for the purpose of parsing non-Prolog-like languages, in particular the Zinc family:

allow subscripts after atoms, and parse a term like a[B,C] as if it were subscript(a,[B,C]).
allow subscripts after atoms, parenthesized subterms and subscripted terms, and parse a term such as a[B][C] as if it were written in the form subscript(subscript(a,[B]),[C]), or a term such as (a-b)[C] as if it were subscript(a-b,[C]).
parse the arguments of a term in curly brackets as a list, i.e., parse {a,b,c} as {}([a,b,c]) instead of the default {}((a,b,c)).

Syntax option settings can be local to a module or exported, e.g.,

:- local syntax_option(not nl_in_quotes).
:- export syntax_option(var_functor_is_apply).

Previous Up Next