Since 1995, there is an ISO / IEC standard for Prolog: ISO / IEC 13211-1: 1995. It also contains a grammar defining the Prolog syntax, which consists of two levels:
Token Level: ( 6.4 Tokens, 6.5 CPU Character Set )
They are defined by regular expressions and use the longest rule of input / impatient consumer / greedy matching / maximum munk, like many languages of that era. In the words of the standard (6.4):
And the token should not be accompanied by symbols, so when concatenating the token symbols with these symbol symbols, a valid token is formed, as indicated above. syntaxNOTES
1 This is the right consumer rule: 123.e defines tokens
123 . e 123 . e . A layout text sometimes it is necessary to separate two tokens.
This method of defining tokens is typical of programming languages created in the 1970s.
Token level is of particular importance to the Prolog syntax, because a term or read term first defined as a sequence of tokens:
term (* 6.4 *) = { token (* 6.4 *) } ; read term (* 6.4 *) = term (* 6.4 *) , end (* 6.4 *) ;
Most tokens contain an optional layout text sequence at the beginning. But never at the end. Also note that to determine the end (i.e., the end period), you need to look at the next character. In a tokenizer written in Prolog, this will be implemented using peek_char/1 .
Only after defining the term at this level does the actual grammar come into play. See 8.14.1.1 Description of read_term/3 . Of course, an implementation can do it differently if it behaves "as if".
Syntax Level: (6.2 Prolog Text and Data, 6.3 Terms)
These definitions rely on full context-free grammar formalism plus a few context-sensitive restrictions.
Conformity
Regarding conformance of implementations, see this table . SWI has always been distinguished by many features: both at the marker level and at the syntax level. Even the operator syntax ( for certain cases ) is incompatible with other systems and the standard. That is, some terms are read differently. Since SWI7, SWI is now different even for canonical syntax . Try writeq('.'(1,[])). This should give [1] , but SWI7 creates some error.
For relevant implementations see sicstus-prolog (version 4.3) and gnu-prolog .
false
source share