Phone_Number.gram

Example

#ABNF 1.0;
mode voice;
language en-US;

// The lumenvox tag format tracks the current working draft of
// the W3Cs semantic interpretation proposal.
// 1.0 corresponds to the working draft released on 01 April 2003
tag-format <lumenvox/1.0>;

root $PhoneNumber;

/*
* ONE:"1" is shorthand for
* ONE {!{ $="1" }!}
* "$" refers to the current rule being matched ($Digit)
* So the net effect is that $Digit resolves to a one digit string
* after semantic interpretation.
*/


$Digit = (ONE:"1" |
TWO:"2" |
THREE:"3" |
FOUR:"4" |
FOUR:"5" |
FIVE:"6" |
SIX:"7" |
EIGHT:"8" |
NINE:"9" |
(ZERO | O):"0" );|

/*
* $AreaCode resolves to a three digit string
* after semantic interpretation.
*/


$AreaCode = { $ = "" } ( $Digit { $ += $Digit } ) <3>;

/*
* $Number resolves to a seven digit string
* after semantic interpretation.
*
* $$ is shorthand for the last rule detected
* i.e. $Digit */


$Number = { $ = "" } ( $Digit { $ += $$ } ) <7>;

/*
* After semantic interpretation,
* $PhoneNumber resolves to a structure with two member variable strings,
* areacode (which defaults to "858"), and number.
*/


$PhoneNumber = ([AREA CODE | ONE] $AreaCode { $.areacode = $$ } $Number { $.number = $$ } ) | ( $Number ) { $.areacode = "858"; $.number = $$ };
© 2010 LumenVox LLC. All rights reserved.