grammatica-users
[Top][All Lists]
Advanced

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

Re: [Grammatica-users] Catch All production


From: Anant Mistry
Subject: Re: [Grammatica-users] Catch All production
Date: Wed, 23 Mar 2005 06:23:06 -0700


I suppose it's hard to describe, so I've cut out an example out the grammar I'm struggling with.

%tokens%

dash    = '-'
period  = '.'
slash   = '/'
colon   = ':'
lparen  = '('
rparen  = ')'
letter  = <<[A-Z]>>
digit   = <<[0-9]>>
WHITESPACE = <<[ \t\n\r]+>> %ignore%

%productions%

reference       =   fedPrefix | default ;

alpha           = ( letter )+ ;
number          = ( digit )+ ;

delimiter       = dash | period | slash | colon | lparen | rparen ;

fedPrefix       = fedHead dash letter dash ;

fedHead         = alpha ;  // Production code will ensure that this alpha can only contain up to 3 of the same character from A-Z

default         = ( alpha [number] ) | ( number [alpha] ) ;

Gives me the following when I run it with inpfile of "DDD-C-"

bandikoot$ java -jar lib/grammatica-1.4.jar test.g --parse inpfile
Error: in test.g: line 36:
    inherent ambiguity in production 'reference' starting with token
    <letter>

reference       =   fedPrefix | default ;


The fedHead is a production that you had provided an answer for in a previous email. I matches the generic definition of an alpha, but the parse production code will ensure that there can be up to 3 of the same character, e.g. AAA or FF or V

The default production is the "catch all" because a doc number could start with a numeric or an alpha .... but it causes a problem in the parsing.

Any thoughts?

Anant

On Tue, 2005-03-22 at 23:24 +0100, Per Cederberg wrote:
Well, there is not really any support for a default "exception"
production. Depending on what you want though, you can create
it yourself by modifying your grammar in like this:

1. Add a default token (last) to skip any unmatched characters:
   SKIP_ANY = <<.|\n>> %ignore%

2. Add dummy productions on places where you wish to skip stuff:
   Prod = A Skippy* B ;
   Skippy = Token1 | Token2 | ... | TokenN ;

Doing this well might take some practice so that you can accept
all the "common" errors without enlarging the grammar too much.
If you really want accept any erroneous input, maybe Grammatica
isn't the perfect tool for the job.

The Grammatica error handling does something similar though,
attempting to recover from broken input by skipping tokens until
it can continue parsing. Maybe one could modify that to just
skip unrecognized input instead of stopping the parse tree
construction and logging parse errors.

/Per

On tue, 2005-03-22 at 13:40 -0700, Anant Mistry wrote:
> 
> Does grammatica have a way of defining a "catch all" production i.e.
> if your input does not meet the parsing rules of the grammar, then
> jump to a generic or default  production?
> 
> Thanks
> 
> Anant




_______________________________________________
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]