[antlr-interest] Help for a newbie please!

Peter Seban pseban12 at gmail.com
Thu Jun 26 02:19:05 PDT 2008


Dear All,

Thanks for expert answers, I'm corrected my grammar, It' s OK.

Best regards!

Peter

2008/6/25 <antlr-interest-request at antlr.org>:

> Send antlr-interest mailing list submissions to
>        antlr-interest at antlr.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://www.antlr.org/mailman/listinfo/antlr-interest
> or, via email, send a message with subject or body 'help' to
>        antlr-interest-request at antlr.org
>
> You can reach the person managing the list at
>        antlr-interest-owner at antlr.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of antlr-interest digest..."
>
>
> Today's Topics:
>
>   1. Help for a newbie please! (Peter Seban)
>   2. GUnit for CSharp (Thomas Karcher)
>   3. Re: Help for a newbie please! (Raphael Reitzig)
>   4. ANTLR3 Maven2 plugin, strange errors (Jeroen Steenbeeke)
>   5. Advice on ANTLR 2.7.3 enabling position of token (Ruslan Zasukhin)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 25 Jun 2008 17:28:33 +0200
> From: "Peter Seban" <pseban12 at gmail.com>
> Subject: [antlr-interest] Help for a newbie please!
> To: antlr-interest at antlr.org
> Message-ID:
>        <f8e54d5f0806250828y43d5a63anc12eab13921dd447 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Dear All,
>
> I'm a newbie in antlr.
> I have tried this example grammar by input text:
>
> apples= 100 * peaches;             // this is a simple expression
> *apples= 100 * peaches;           //  this is a comment line
>
> , but it doesn't work.
>
> The grammar:
> --------------------
>
>
> grammar expr_test;
> options{
>   output=AST;
>   ASTLabelType=CommonTree;
> }
> query  :
>          ex1=expr1  { System.out.println("[EXPRESSION_1] \n"+$ex1.text); }
>        | ex2=expr2  { System.out.println("[EXPRESSION_2] \n"+$ex2.text); }
>       ;
> expr1
>       :
>       terms '=' terms multiplication terms ';'
>       ;
>
> expr2
>       :
>       asterisk ~('\r'|'\n')* ';'
>       ;
> terms  :
>       WCHAR*
>       ;
> asterisk
>       :
>       {input.LT(-1).getText().toLowerCase().equals("\n")}?
>       {input.LT(0).getText().toLowerCase().equals(";")}?
>       {input.LT(1).getText().toLowerCase().equals("*")}? '*'
>       ;
>
> multiplication
>       :
>       {input.LT(1).getText().toLowerCase().equals("*")}? '*'
>       ;
>
> WS     : (' '|'\t'|'\r'|'\n')+ {skip();};
> WCHAR  : ~('*'|'='|'('| ')'|'"'|' '|'\t'|'\n'|'\r'|'#'| ';')*;
>
> /*
> Test it :
> ---------
> apples= 100 * peaches;
> *apples= 100 * peaches;
> */
>
> The generated output is:
> -----------------------------------
>
> [EXPRESSION_1]
> apples=100*peaches;
>
> Why do'nt generated:
> ------------------------------
> [EXPRESSION_2]
> *apples=100*peaches;
>
> too?
>
> Thank you all for your kind tips!
> Peter
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20080625/38deda6b/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Wed, 25 Jun 2008 18:26:16 +0200
> From: Thomas Karcher <thkarcher at gmx.de>
> Subject: [antlr-interest] GUnit for CSharp
> To: antlr-interest at antlr.org
> Message-ID: <1214411177.4033.49.camel at localhost>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi,
>
> is there something like gunit (i. e. grammar unit tests) for the CSharp
> target?
>
> If not, I guess "normal" C# unit tests like NUnit will do it ...
>
>
> Thanks,
> Thomas
>
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 189 bytes
> Desc: Dies ist ein digital signierter Nachrichtenteil
> Url :
> http://www.antlr.org/pipermail/antlr-interest/attachments/20080625/b6481609/attachment-0001.bin
>
> ------------------------------
>
> Message: 3
> Date: Wed, 25 Jun 2008 18:27:51 +0200
> From: Raphael Reitzig <r_reitzi at cs.uni-kl.de>
> Subject: Re: [antlr-interest] Help for a newbie please!
> To: antlr-interest at antlr.org
> Message-ID: <ef853a55f65763f642fa7b4d71e67b6d at mail.frhk.de>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi Peter!
>
> You do not have any recursion in your grammar. The first expression
> matches, but then, there is no rule available for the second line.
>
> Try adding something like that as starting rule:
>
> querylist : query (('\r'|'\n'|'\r\n')* query)* EOF;
>
> Good luck
>
> Raphael
>
> On Wed, 25 Jun 2008 17:28:33 +0200, "Peter Seban" <pseban12 at gmail.com>
> wrote:
> > Dear All,
> >
> > I'm a newbie in antlr.
> > I have tried this example grammar by input text:
> >
> > apples= 100 * peaches;             // this is a simple expression
> > *apples= 100 * peaches;           //  this is a comment line
> >
> > , but it doesn't work.
> >
> > The grammar:
> > --------------------
> >
> >
> > grammar expr_test;
> > options{
> >    output=AST;
> >    ASTLabelType=CommonTree;
> > }
> > query  :
> >           ex1=expr1  { System.out.println("[EXPRESSION_1] \n"+$ex1.text);
> > }
> >         | ex2=expr2  { System.out.println("[EXPRESSION_2] \n"+$ex2.text);
> > }
> >        ;
> > expr1
> >        :
> >        terms '=' terms multiplication terms ';'
> >        ;
> >
> > expr2
> >        :
> >        asterisk ~('\r'|'\n')* ';'
> >        ;
> > terms  :
> >        WCHAR*
> >        ;
> > asterisk
> >        :
> >        {input.LT(-1).getText().toLowerCase().equals("\n")}?
> >        {input.LT(0).getText().toLowerCase().equals(";")}?
> >        {input.LT(1).getText().toLowerCase().equals("*")}? '*'
> >        ;
> >
> > multiplication
> >        :
> >        {input.LT(1).getText().toLowerCase().equals("*")}? '*'
> >        ;
> >
> > WS     : (' '|'\t'|'\r'|'\n')+ {skip();};
> > WCHAR  : ~('*'|'='|'('| ')'|'"'|' '|'\t'|'\n'|'\r'|'#'| ';')*;
> >
> > /*
> > Test it :
> > ---------
> > apples= 100 * peaches;
> > *apples= 100 * peaches;
> > */
> >
> > The generated output is:
> > -----------------------------------
> >
> > [EXPRESSION_1]
> > apples=100*peaches;
> >
> > Why do'nt generated:
> > ------------------------------
> > [EXPRESSION_2]
> > *apples=100*peaches;
> >
> > too?
> >
> > Thank you all for your kind tips!
> > Peter
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 25 Jun 2008 19:02:19 +0200
> From: Jeroen Steenbeeke <jeroen at pbemengine.nl>
> Subject: [antlr-interest] ANTLR3 Maven2 plugin, strange errors
> To: antlr-interest at antlr.org
> Message-ID: <48627A1B.9000108 at pbemengine.nl>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hey everyone,
>
> I am currently in the process of generating the source for a Tree
> Grammar for Java (basically Dieter Habelitz' grammar with my own
> processing stuff added in code blocks).
>
> When using the command line or when running the generation through Ant
> (with <java> tasks) everything works out fine, but for some reason I
> can't get it to work with the ANTLR3 plugin for Maven2.
>
> I've added the pom.xml file and Maven's output as attachments. For some
> reason the ANTLR plugin manages to get into an infinite recursion that
> causes OutOfMemoryErrors. I've tried increasing the available heapspace
> with the -Xmx JVM option but to no avail - the generator simply freezes
> even with over 1GB of heap space.
>
> What could be causing these problems? Is Maven perhaps using an
> incorrect version of ANTLR?
>
> Or would it be better to simply report this as a bug to the Maven2
> plugin developers?
>
> Cheers,
>
> Jeroen Steenbeeke
> -------------- next part --------------
> An embedded and charset-unspecified text was scrubbed...
> Name: error.txt
> Url:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20080625/23a3fc34/attachment-0001.txt
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: pom.xml
> Type: text/xml
> Size: 1139 bytes
> Desc: not available
> Url :
> http://www.antlr.org/pipermail/antlr-interest/attachments/20080625/23a3fc34/attachment-0001.xml
>
> ------------------------------
>
> Message: 5
> Date: Wed, 25 Jun 2008 21:45:40 +0300
> From: Ruslan Zasukhin <sunshine at public.kherson.ua>
> Subject: [antlr-interest] Advice on ANTLR 2.7.3 enabling position of
>        token
> To: "antlr-interest at antlr.org" <antlr-interest at antlr.org>
> Message-ID: <C4886D04.9E2F8%sunshine at public.kherson.ua<C4886D04.9E2F8%25sunshine at public.kherson.ua>
> >
> Content-Type: text/plain;       charset="US-ASCII"
>
> Hi All,
>
> Let me remind that we develop SQL parser for our Valentina database engine.
> We still using ANTLR 2.x (waiting for release of ANTLR 3.1 to switch).
>
> I know that in ANTLR 3.x added handy feature that each token know its
>    styrt/end position in the original text.
>
> Is it possible implement this feature for ANTLR 2.x ?
>
> We have long time wait for 3.x switch but not catch urgent case to solve it
> using 2.x.
>
>
> Problem is that when we parse string that contains FEW SQL commands, we
> sometimes must be able get command itself to store it. We need this for
> Stored Procedures and Triggers for example.
>
> So when I have single string as
>
> "
> CREATE PROCEDURE proc1
> BEGIN
>   // some text of procedure 1
> END
>
>
> CREATE PROCEDURE proc1
> BEGIN
>   // some text of procedure 2
> END
> "
>
>
> I must be able get from parser only
>
> CREATE PROCEDURE proc1
> BEGIN
>   // some text of procedure 1
> END
>
>
> Any clues how I can improve ANTLR 2.x for this?
>    * may be add own subclass of Token ?
>        and self store there position when Lexer create token?
>
>
> --
> Best regards,
>
> Ruslan Zasukhin
> VP Engineering and New Technology
> Paradigma Software, Inc
>
> Valentina - Joining Worlds of Information
> http://www.paradigmasoft.com
>
> [I feel the need: the need for speed]
>
>
>
>
>
> ------------------------------
>
> _______________________________________________
> antlr-interest mailing list
> antlr-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-interest
>
>
> End of antlr-interest Digest, Vol 43, Issue 54
> **********************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080626/e503b457/attachment-0001.html 


More information about the antlr-interest mailing list