Skip to content

Recursive rule definitions #18

@drmfinlay

Description

@drmfinlay

JSGF spec sections 4.8-4.9 discuss right recursive rules:

<command> = <action> | (<action> and <command>);
<action> = stop | start | pause | resume | finish;

and nested right recursive rules:

<X> = something | <Y>;
<Y> = another thing <X>;

While constructing or parsing rules like these works, matching speech to them doesn't. Matching will fail with a "maximum recursion depth exceeded" error.

The JSGF spec has some notes on how to support right-recursive rules:

Any right recursive rule can be re-written using the Kleene star *' and/or the plus operator +'. For example, the following rule definitions are equivalent:

   <command> = <action> | (<action> and <command>);
   <command> = <action> (and <action>) *;

Although it is possible to re-write right recursive grammars using the +' and *' operators, the recursive form is permitted because it allows simpler and more elegant representations of some grammars. Other forms of recursion (left recursion, embedded recursion) are not supported because the re-write condition cannot be guaranteed.

With that in mind, it should be possible to use rewritten matcher elements somehow when right recursion is detected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    missingMissing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions