Question on expression levels in Prolog parsing rules

Hi guys,

I am looking at Tau Prolog’s grammar rules, see in particular Figure 1: Formal grammar, where the parsing rules are represented.

I do not understand why in Expr_0 the sub-expressions in parentheses are at level 1200, while in Term_2 and Term_3 and in List_2 and List_3 the sub-expressions in parentheses are at level 999.

Can anybody explain? What’s the idea?

BTW, Tau Prolog is mostly ISO conformant, so I suppose mostly the same parsing rules are found in SWI and ISO: right? (I do not have a copy of the ISO standard, and parsing rules are not documented in the SWI manual AFAICT.)

The rule is motivated to resolve some ambiguity of (‘,’)/2:


image

The rule is not strictly followed by SWI-Prolog, you can write:

p(a :- b, c).

And then query:

?- p(X, Y).
X = (a:-b),
Y = c.

If you enter the same fact in Tau-Prolog sandbox you get:

p(a :- b, c).
error parsing program: error(syntax_error(, or ) 
expected),[line(1),column(7),found(:-)])

So Tau-Prolog enforces to enter the fact either as p((a :- b, c)),
or as p((a :- b), c). Depending on what the end-user wants,
a binary predicate or an unary predicate.

2 Likes

The rule is motivated to resolve some ambiguity of (‘,’)/2

Ah, I see. Thank you!

The rule is not strictly followed by SWI-Prolog

Is that documented anywhere?

@ridgeworks made a PEG grammar:

Parsing text using a formal grammar: SWIPL Example
https://swi-prolog.discourse.group/t/parsing-text-using-a-formal-grammar-swipl-example/5088

1 Like