Trans.: RE: [antlr-interest] Beginer's question, not fitting in subject

Alexandre antlr at alxp.gr
Sat Apr 9 09:28:24 PDT 2005


Thank you for your answer.

So I suppose this means that my feeling was right, to let Java checking it...

But the problem is a litte bit more tricky. The syntax I have is imposed, and is
different of what I gave. It is precisely this :
V= [4,5,6]
sr1 ac1	T
sr1 ac1	NT
sr1 ac2	NT
sr2 ac1	T
sr2 ac1	NT
sr2 ac2	T
sr2 ac2	NT
(It represents a CSP constraint if it does mean something to you, V are the
variables, then follow the values that they are allowed to have, in the same
order). Of course lines do not have more importance than spaces or tabs. I
could have
V= [4,5,6] sr1 ac1 T sr1 ac1 NT
which is right, but
V= [4,5,6] sr1 ac1 T sr1 ac1
or
V= [4,5,6] sr1 ac1 T sr1 ac1 NT sr1
are wrong...

So I should have a rule only for each value (sr1, NT, ...), then put Java
instructions to build dynamically the (here) three elements collections, as
Tokens come, and throw an error if something is missing. In fact this syntax is
simpler, we don't need RegEx's (maybe that's why I've been given it). Do you
think that's good, or have other suggestion ?

Thank you again,

Alexandre

Selon Scott Stanchfield <scott at javadude.com>:

> I should note that I meant to use the RegEx for each line after reading the
> line using the BufferedReader.
>
> Later,
> - Scott
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org
> > [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Scott
> > Stanchfield
> > Sent: Saturday, April 09, 2005 11:29 AM
> > To: 'Alexandre'; antlr-interest at antlr.org
> > Subject: RE: [antlr-interest] Beginer's question, not fitting
> > in subject
> >
> > Seriously... I think ANTLR is overkill for items like this.
> >
> > Whenever you have line-oriented input and all lines have the
> > same format, I'd recommend using good old BufferedReader to
> > read the lines and StringTokenizer to separate them.
> >
> > If you want a little more checking to see if the parens and
> > commas are actually there, then you'll want to use a Java
> > regular expression (Pattern +
> > Matcher) if you can use Java 1.4 or later.
> >
> > Hope this helps!
> > -- Scott
> >
> > > -----Original Message-----
> > > From: antlr-interest-bounces at antlr.org
> > > [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Alexandre
> > > Sent: Saturday, April 09, 2005 11:23 AM
> > > To: antlr-interest at antlr.org
> > > Subject: [antlr-interest] Beginer's question, not fitting in subject
> > >
> > > Hello,
> > >
> > > I have a classic, I guess, question. The language I am trying to
> > > define cannot be represented by a grammar, as it is of the form
> > > (a)n(b)n. What my file must do is something like defining
> > tuples, that
> > > is series of elements. Suppose that the syntax to define a serie of
> > > values a serie of variables can have is something like :
> > > (X1, X2, X3)
> > > (1, 2, 3)
> > > (4, 5, 6)
> > >
> > > Of course the number of variables is totally arbitrary, but for a
> > > given number, the number the values in each following tuple
> > of values
> > > must be the same. How can I make that with antlr ? I
> > thought about not
> > > having antlr detecting it, that is to accept any list of the form
> > > (..,..) for the values, and then treat (in Java) the result
> > of each,
> > > and throwing if necessary an exception. But that isn't pretty
> > > beautiful.
> > >
> > > Do you have any suggestion ?
> > >
> > > Thank you,
> > >
> > > Alexandre
> > >
> >
> >
> >
> >
>
>
>
>
>



----- Fin du message transféré -----




More information about the antlr-interest mailing list