Scryer-prolog: Tabled DCG unexpectedly fails

Created on 30 May 2020  路  4Comments  路  Source: mthom/scryer-prolog

With the following definitions:

:- use_module(library(dcgs)).
:- use_module(library(tabling)).

:- table expr//0.

expr --> "1".
expr --> expr, "+", expr.

I get:

?- phrase(expr, "1+1+1").
false.

Expected: true.

Most helpful comment

Fixed. I was totally wrong about variants being the culprit.

All 4 comments

This case is tricky. The tabling library indexes answer tries using "variants" of queries, which it attaches to unique table identifiers. The variant of your query is expr("1+1+1", []), but the variant of the first internal expr call is expr("1+1+1", '$VAR'(0)). The tabling library doesn't recognize that expr("1+1+1", '$VAR'(0)) can unify with expr("1+1+1", []), and should therefore be tried as an answer source.

I agree, this query should succeed. I will try to generalize the library accordingly.

Thank you for looking into this! This feature is very important for writing parsers with left-recursion. Combining tabling with DCGs in this way yields a parsing strategy that is called packrat parsing.

Could it be a workable solution to store variants using Prolog variables, such as expr("1+1+1", X), and then to use subsumes_term/2 or a variant check?

This would use Prolog's built-in mechanisms to detect variants.

Fixed. I was totally wrong about variants being the culprit.

Very nice, thank you a lot, this is truly awesome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

XVilka picture XVilka  路  3Comments

UWN picture UWN  路  4Comments

notoria picture notoria  路  3Comments

triska picture triska  路  3Comments

srenatus picture srenatus  路  4Comments