Phone_Number.gram

Example


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

tag-format <semantics/1.0>;

root $PhoneNumber;

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

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

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

/*
* $Number resolves to a seven digit string
* after semantic interpretation.
*/

$Number = { out = "" } ( $Digit { out += rules.latest() } ) <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 { out.areacode = rules.latest() }
$Number { out.number = rules.latest() }
) |
( $Number ) { out.areacode = "858"; out.number = rules.latest() };





Was this article helpful?
Copyright (C) 2001-2024, Ai Software, LLC d/b/a LumenVox