This document gives a formal definition of the syntax of the Grammar Language supported by NuGram IDE and NuGram™ Server. The syntax is itself described using an EBNF grammar.
The language described here is a proper superset of the ABNF language defined in the Speech Recognition Grammar Specification Version 1.0, a W3C Recommandation published on March 16, 2004.
#ABNF 1.0 encoding; Headers Top-forms
All the standard ABNF headers are supported. The difference is
that each value can be made dynamic by using the @string
directive.
Headers --> Header *
Header
--> 'mode' ( 'voice' | 'dtmf' | Dynamic-String ) [ '@when' Expression ] ';'
--> 'root' ( LocalRulename | Dynamic-String ) [ '@when' Expression ] ';'
--> 'language' ( Word | Dynamic-String ) [ '@when' Expression ] ';'
--> 'lexicon' ( Uri | Dynamic-String ) [ '@when' Expression ] ';'
--> 'meta String 'is' ( String | Dynamic-String ) [ '@when' Expression ] ';'
--> 'tag-format ( Uri | Dynamic-String ) [ '@when' Expression ] ';'
Dynamic-String
--> '@string' Expression
Top forms are either static rule definitions, dynamic rule definitions, macro definitions, or dynamic forms that is ultimately expanded into dynamic rule or macro definitions.
A macro is an abstracted expansion that help reduce repetitive patterns in static or dynamic rules.
Top-forms
--> Top-Form *
Top-Form
--> Static-Rule-Definition
--> Macro-Definition
--> Top-Body-Form
Top-Body-Form
--> Dynamic-Rule-Definition
--> Top-Foreach-Form
--> Top-Let-Form
--> Top-If-Form
Top-Body
--> Top-Body-Form *
Static-Rule-Definition
--> [ 'public' | 'private' ] LocalRulename '=' Expansion ';'
Macro-Definition
--> '@define' Identifier Formal-Parameters ':' Expansion '@end'
Formal-Parameters
--> '(' [ Identifier ( ',' Identifier ) * ] ')'
Dynamic-Rule-Definition
--> '@rule' Expression ':' Expansion '@end'
Top-Foreach-Form
--> '@for' '(' Identifier ':' Expression ')' Top-Body '@end'
Top-Let-Form
--> '@var' Identifier '=' Expression ( ',' Identifier '=' Expression ) * ':'
Top-Body
'@end'
Top-If-Form
--> '@if' '(' Expression ')' Top-Body
( '@elseif' '(' Expression ')' Top-Body ) *
[ '@else' Top-Body ]
'@end'
Expansions are what we find at the right-hand side of a grammar rule definition.
Expansion
--> Static-Alternatives
Static-Alternatives
--> Static-Sequence ( '|' Static-Sequence ) *
Static-Sequence
--> [ Weight ] Item
Weight
--> weight
--> '@weight' Expression
Item
--> Simple-Item [ Repeat ]
Repeat
--> repeatSpecification
--> '@repeat' Expression ',' Expression-Or-Dash ',' Expression-Or-Dash '@end'
(Dashes are used in dynamic repeat specifications to indicate an unknown or default value.)
Expression-Or-Dash
--> Expression
--> '-'
Simple-Item
--> Word
--> Quoted-Word
--> SemanticTag
--> LocalRulename
--> ExternalRulename
--> '(' Expansion ')'
--> '[' Expansion ']'
--> Dynamic-Item
Dynamic-Item
--> Dynamic-Word
--> Dynamic-Tag
--> Dynamic-Reference
--> Dynamic-Alternative
--> Dynamic-Sequence
--> Macro-Call
--> Let-Expansion
--> Foreach-Expansion
--> If-Expansion
--> Fragment-Expansion
Dynamic-Word --> '@word' '(' Expression + ')'
Dynamic-Reference --> '@ref' '(' Expression + ')'
Dynamic-Tag --> '@tag' '(' Expression + ')'
Dynamic-Alternative --> '@alt' Expansion + '@end'
Dynamic-Sequence --> '@seq' Expansion + '@end'
Macro-Call --> '@call' Identifier Actual-Parameters
Fragment-Expansion --> '@fragment' Expression
Foreach-Expansion
--> '@for' '(' Identifier ':' Expression ')' Expansion '@end'
Let-Expansion
--> '@var' Identifier '=' Expression ( ',' Identifier '=' Expression ) * ':'
Expansion
'@end'
If-Expansion
--> '@if' '(' Expression ')' Expansion
( '@elseif' '(' Expression ')'Expansion ) *
[ '@else' Expansion ]
'@end'
The set of legal expressions is a very limited subset of expressions ordinarily found in mainstream programming languages.
Expression
--> Or-Expression
Or-Expression
--> And-Expression [ '||' And-Expression ]
And-Expression
--> Not-Expression [ '&&' Not-Expression ]
Not-Expression
--> [ '!' ] Simple-Expression
Simple-Expression
--> Constant-Expression
--> Identifier [ Field-or-Method-Call ]
--> '(' Expression ')'
Field-or-Method-Call
--> '.' Identifier [ Actual-Parameters ]
Actual-Parameters
--> '(' [ Expression ( ',' Expression ) * ] ')'
Constant-Expression
--> 'null'
--> 'false'
--> 'true'
--> Number
--> String
Copyright © 2007,2008,2009,2010,2011
Nu Echo Inc.