# Grammar Guide

# A guide to Voice Type grammar annotations

### Sending keystrokes to an application

The annotation prefix `&keys:` instructs Voice Manager to interpret the characters following the prefix as a sequence of keystrokes to be sent to the application. For example:

            <start> = <select> <all> .
            <select> = select .
            <all> = all:"&keys:[alt e]a" .

With this grammar enabled, Voice Manager will send the keystrokes `[alt e]a` upon recognizing select all.

### Variables

The assignment of variables is done with the `&X:` annotation. This annotation has the following form:

`&X:i:s`

where `i` is an integer greater than zero and `s` is a string. This has the effect of assigning the value `s` to variable `i`. For example,

       <blue> = blue:"&X:1:[down]" .

assigns `down` to be the value of `X1`. Referencing variables is done with the `@X(i)` operator (where `i` is a positive integer). For example:

       <change-color> = <set> <color> <to> <colors> .
       <set>  = set .
       <color> = color:"&keys:[alt o]c[home]@X(1)[enter]" .
       <colors> = <blue>  .
       <blue> = blue .

When Voice Manager recognizes the phrase set color to blue the annotation on `blue` sets the value of `X(1)` to `[down]`. The annotation on `color` is `&keys:[alt o]c[home]@X(1)[enter]`. The variable `@X(1)` is replaced by its value `[down]` and voice manager sends the following keystrokes:

        [alt o]c[home][down][enter]

### The @count() variable

In order to use the `@count` annotation you need to put the following line at the end of you grammar file:

     EXTERN <Extern_counts> .

This enables you to use the `<Extern_counts>` nonterminal and the `@count(i)` annotation. The nonterminal `<Extern_counts>` has the following rewrite rule:

        <Extern_counts> = one       | two       | three     |
                          four      | five      | six       |
                          seven     | eight     | nine      |
                          ten       | eleven    | twelve    |
                          thirteen  | fourteen  | fifteen   |
                          sixteen   | seventeen | eighteen  |
                          nineteen  | twenty    | thirty    |
                          forty     | fifty     .

The annotation `@count(i)` specifies the value of the i-th count nonterminal. For example, if you have the grammar rule:

     <sample> = <print> <Extern_counts> <copies> <of> <pages> <Extern_counts> <through> <Extern_counts> .

and the user utters: print five copies of pages one through three. Then:

- `@count(1)` has the value of the first `<count>` encountered (in this case "5")
- `@count(2)` has the value of the second `<count>` encountered (in this case "1")
- `@count(3)` has the value of the third (in this case "3").

  Here's an example that will work with IBM Works:

            <font-size> = <change> <font> <size> <to> <Extern_counts>  .
            <change> = change .
            <font> = font .
            <size> = size:"&keys:[ctrl f][alt s]@count(1)[enter]" .
            <to> = to .

            EXTERN <Extern_counts> .

  Consider the case where the user says Change the font size to twelve. The annotation for `twelve` sets the `count(1)` variable to `12`. The annotation on `size` is `&keys:[ctrl f][alt s]@count(1)[enter]`. The `@count(1)` variable is replaced with `12` yielding:

      &keys:[ctrl f][alt s]12[enter]

  ### The @repeat(i, s) annotation

  The `@repeat(i, s)` function constructs a string of `i` instances of the string `s`. For example, the annotation `@repeat(4, [down])` will be replaced by `[down][down][down][down]`. A typical use of this annotation is as follows:

      <move-command> = move right <count> words:"&keys:@repeat(@count(1),[shift[right]])" .

      EXTERN <Extern_counts> .

  Consider the case where this grammar is active and Voice Manager recognzies move right three words. The `count(1)` variable has the value `3`. The annotation on `words` is `&keys:@repeat(@count(1),[shift[right]])`. Replacing `@count(1)` by its value yields `&keys:@repeat(3,[shift[right]])`. The `@repeat` sequence is performed yielding `&keys:[shift[right]][shift[right]][shift[right]]`.

  [ Top of Page | Previous Page | Back to Grammar Guide ]