cie / rubylog

A Prolog DSL and interpreter for Ruby
MIT License
31 stars 1 forks source link

Definite clause grammar syntax #5

Open jarble opened 8 years ago

jarble commented 8 years ago

In Prolog, it is possible to define definite clause grammars like this one:

 sentence --> noun_phrase, verb_phrase.
 noun_phrase --> det, noun.
 verb_phrase --> verb, noun_phrase.
 det --> [the].
 det --> [a].
 noun --> [cat].
 noun --> [bat].
 verb --> [eats].

Does an equivalent notation exist in Rubylog?

cie commented 8 years ago

Hello! Yes and no. See dcg.rb and dcg2.rb in examples/. Both of them are examples for these. The first one is a nicer syntax, it works alike, but it's inefficient for long inputs. The second one is semantically equivalent, but the syntax is not so nice. It's actually just the Rubylog version of the semantics of how the prolog DCG preprocessor translates DCGs.

So currently there is no simple syntax for real DCGs. I've thought about it a lot, but didn't find an easy solution. If you have an idea, tell me, and if someone can implement it, I'm open to adding it to the language. But I'm quite busy with other projects, so I cannot promise to work too much on it.