dialogos-project / dialogos

The DialogOS dialog system.
https://www.dialogos.app
GNU General Public License v3.0
21 stars 8 forks source link

Tags in grammars #131

Closed TheresaSchmidt closed 5 years ago

TheresaSchmidt commented 5 years ago

Hi, I have an issue with the use of tags in grammars. I found out that tags are only recognized as such if they are used in the extension of the start symbol of the grammar. However, if you want to use variables (non-terminals) as value of the tag, the tag has to be used in the same line as the variable.

The following example grammars illustrate the problem. I also include the dialog in which I tested the grammars. Beispiel Tags.zip

In Grammar A and C for the input "Hallo Welt" I get "Hallo Welt" as output of the grammar (as expected). For "Wie viel Milch brauche ich" and "Wie viel Zucker brauche ich" I get the following error message:

grafik In Grammar B the output of the grammar equals its input. However, I would expect to get "Zucker" as output for the input "Wie viel Zucker brauche ich". The tag seems to be ignored in the evaluation of the grammar.

Grammar A:

root $input;
 $input = $zutaten {$=$term_z}| Hallo Welt ;
$zutaten = Wie viel $term_z brauche ich  ;
$term_z = Milch | Zucker ;

Grammar B:

root $input;
 $input = $zutaten | Hallo Welt ;
$zutaten = Wie viel $term_z brauche ich {$=$term_z} ;
$term_z = Milch | Zucker ;

Grammar C:

root $input;
 $input = $zutaten | Hallo Welt ;
$zutaten = Wie viel $term_z brauche ich  ;
$term_z = (Milch | Zucker) {$=$term_z} ;
timobaumann commented 5 years ago

thanks theresa.

can you try putting the tag earlier in grammar b? (between brauche and ich?) I'm surprised it doesn't work, I really would have thought it should.

As for the other versions:

timobaumann commented 5 years ago

also, can you try to do this without underscores?

TheresaSchmidt commented 5 years ago

Thanks for the quick answer. Unfortunately, neither moving the tag around nor omitting the underscore changes anything.

TheresaSchmidt commented 5 years ago

Oh, I work on Windows 7 if that matters...

alexanderkoller commented 5 years ago

Hi, I have looked at grammar B. The problem is that you do not define a tag for the rule $input = $zutaten, and therefore DialogOS will simply return the matched input string for $input.

A variant of grammar B that works as you intended looks as follows (note the {$ = $zutaten} in the rule for $input = $zutaten):

root $input;
$input = $zutaten {$ = $zutaten} | Hallo Welt ;
$zutaten = Wie viel $term_z brauche ich {$=$term_z} ;
$term_z = Milch | Zucker ;

I have clarified the documentation on the Wiki page for grammars.

@timobaumann already explained why grammars A and C should not be expected to behave as you intended.

I hope this helps you. If not, feel free to reopen the issue.

Happy new year!