grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] BNF grammar files


From: Per Cederberg
Subject: Re: [Grammatica-users] BNF grammar files
Date: Sat, 19 Jun 2010 22:55:42 +0200

If two token definitions match the same character sequence, such as
"add" being both IDENTIFIER_STRING and ADD_TOKEN, then the top
definition from the grammar file is chosen.

So. If you put your constant tokens at the top of the token list you
should be fine.

Cheers,

/Per Cederberg

On Sat, Jun 19, 2010 at 16:38, Dan Miller <address@hidden> wrote:
> Hi,
> I am new to using grammatica, and its been years since I wrote something in 
> BNF. I am trying to setup a command parser,
> and I have it working when I group my command tokens such as
> ADD_COMMAND = "add lb monitor" but when I break it up  so that I have tokens 
> for "add" "lb" "monitor" It fails with my input. I know it must be something 
> silly I am forgetting. Can someone eyeball my grammar below. The data file 
> that fails is below. It complains there is no "add" | "bind" in column 1 but 
> there is in the input file.
>
> Below is the grammar. Thanks in advance
>
> net.percederberg.grammatica.parser.ParserLogException: unexpected
> token "add" <IDENTIFIER_STRING>, expected one of "add", or "bind", on line 1 
> column: 1
>
>
> add lb monitor DEFAULT_HTTP "/" "."
> add lb monitor wowza "/" "Wowza Media Server 2" -port 8086
> add lb
> monitor tcp_check
> add server wowza3 63.240.112.28
> add server
> wowza2 63.240.112.27
> add server wowza1 63.240.112.26
>
>
>
>
> %tokens%
> NUMBER                       = <<[0-9]+>>
> SINGLE_LINE_COMMENT          = <<//.*>> %ignore%
> MULTI_LINE_COMMENT           = <</\*([^*]|\*+[^*/])*\*+/>> %ignore%
> IDENTIFIER_STRING            = <<[a-zA-Z][a-zA-Z0-9-_]*>>
> QUOTED_STRING                = <<"[^"]*"|'[^']*'>>
> WHITESPACE                   = <<[ \t\n\r]+>> %ignore%
> COMMENT                      = <<--([^\n\r-]|-[^\n\r-])*(--|-?[\n\r])>> 
> %ignore%
> IP_ADDRESS                   = 
> <<\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b>>
> EMAIL_ADDRESS                 = <<address@hidden,4}\b>>
>
>
> PORT_OPTION                    = "-port"
> ADD_TOKEN                    = "add"
> SERVER_TOKEN                  = "server"
> SERVICE_TOKEN                = "service"
> LB_TOKEN                    = "lb"
> MONITOR_TOKEN                = "monitor"
> VSERVER_TOKEN                = "vserver"
> BIND_TOKEN                    = "bind"
> ALERT_TOKEN                 = "alert"
>
> /** Production definitions **/
> %productions%
> Start = CmdDefinition +;
> CmdDefinition          = AddServerCmd | AddLbMonitorCmd | AddServiceCmd | 
> AddLbVserverCmd | BindLbMonCmd| BindLbVserverCmd | BindAlertServiceCmd;
>
> AddServer            = ADD_TOKEN WHITESPACE? SERVER_TOKEN;
> AddService            = ADD_TOKEN SERVICE_TOKEN;
> AddLb                 = ADD_TOKEN LB_TOKEN;
> AddServerCmd          = AddServer WHITESPACE? IDENTIFIER_STRING WHITESPACE? 
> IP_ADDRESS;
> AddLbMonitorCmd      = AddLb MONITOR_TOKEN  WHITESPACE? IDENTIFIER_STRING 
> WHITESPACE? QUOTED_STRING WHITESPACE? QUOTED_STRING WHITESPACE? [PORT_OPTION 
> NUMBER] | AddLb MONITOR_TOKEN WHITESPACE? IDENTIFIER_STRING;
> AddServiceCmd        = AddService IDENTIFIER_STRING IDENTIFIER_STRING NUMBER;
> AddLbVserverCmd      = AddLb VSERVER_TOKEN IDENTIFIER_STRING;
>
> BindLb                = BIND_TOKEN LB_TOKEN;
> BindAlert            = BIND_TOKEN ALERT_TOKEN;
> BindLbMonCmd         = BindLb MONITOR_TOKEN IDENTIFIER_STRING 
> IDENTIFIER_STRING;
> BindLbVserverCmd     = BindLb VSERVER_TOKEN IDENTIFIER_STRING 
> IDENTIFIER_STRING;
> BindAlertServiceCmd = BindAlert SERVICE_TOKEN IDENTIFIER_STRING EMAIL_ADDRESS;
>
>
>
>
> _______________________________________________
> Grammatica-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]