[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Grammatica-users] Question about tokens
From: |
Per Cederberg |
Subject: |
Re: [Grammatica-users] Question about tokens |
Date: |
Thu, 17 Mar 2005 23:17:00 +0100 |
Well, generally what you want to do is impossible in a context-
insensitive grammar (like the ones Grammatica handles). However,
you can implement the context-sensitive parts of the grammar in
source code form inside your Analyzer subclass. If the grammar
looks like this:
Reference = aLetter+ ;
You'd then write something like:
protected Node exitReference(Production node)
throws ParseException {
if (node.getChildCount() > 3) {
throw new ParseException(ParseException.ANALYSIS_ERROR,
"reference code too long",
node.getStartLine(),
node.getStartColumn());
}
... check that token children are identical ...
return node;
}
So, this takes away some of the nice code/grammar separation
that Grammatica attempts to uphold, but it also greatly reduces
the complexity of the grammar language itself.
Cheers,
/Per
On thu, 2005-03-17 at 10:20 -0700, Anant Mistry wrote:
>
> Hopefully, this question is not going to be a stupid as the last one I
> posted :)
>
> In my grammar definition I want to represent a part of a doc number
> that could be a sequence of the same letter (only A-Z), but not more
> than three.
>
> e.g. A or AA or AAA or B or BB or BBB
>
> So I have a token defined for every letter and then built a grammar
> like
>
> a = "A"
> b = "B"
> c = "C"
> etc.
>
> reference = a [a[a]] | b[b[b]] | c[c[c]] | .... etc.
>
> There are other places I want to use the token
>
> aLetter = <<[A-Z]>>
>
> Obviously, the two conflict. Is there a way I can define the
> requirement for multiples of the same letter just using a production
> of the aLetter token?
>
> Thanks
>
> Anant
>
> --
> Anant Mistry
> Director of Infrastructure Technology
> Information Handling Services
> 15 Inverness Way East
> Englewood
> CO 80112
> USA
>
> Confidentiality Notice: The information in this e-mail may be
> confidential
> and / or privileged. This e-mail is intended to be reviewed by only the
> individual or organization named in the e-mail address. If you are not
> the
> intended recipient, you are hereby notified that any review,
> dissemination
> or copying of this e-mail and attachments, if any, or the information
> contained herein, is strictly prohibited.
> _______________________________________________
> Grammatica-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/grammatica-users