[il-antlr-interest: 27375] Re: [antlr-interest] hello, antlr on Ubuntu

2009-12-28 Thread Bart Kiers



Dan Kegel wrote:
> 
> ...
> 
> for recent java, else you get the error
> 
> ExprParser.java:163: warning: [unchecked] unchecked call to put(K,V)
> as a member of the raw type java.util.HashMap
> memory.put(ID2.getText(), new Integer(expr3));
>   ^
> 
> 

That's no error, just a warning. The code will compile just fine.
-- 
View this message in context: 
http://n2.nabble.com/hello-antlr-on-Ubuntu-tp4180837p4223534.html
Sent from the ANTLR mailing list archive at Nabble.com.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.




[il-antlr-interest: 27541] Re: [antlr-interest] ANTLRWorks plugin for intellij

2010-01-14 Thread Bart Kiers
I first used the plug-in with IntelliJ (v9), but found it a bit buggy: quite
a few error messages (sorry, not too concrete...). I use the stand alone
ANTLRWorks (much to my liking!).

Regards,

Bart.


On Fri, Jan 15, 2010 at 1:47 AM, Terence Parr  wrote:

> hi. how many people use AW as a plugin *inside* intellij?  it really
> complicates the code and I'm thinking of dumping it; might make it easier
> for eclipse plugins too if theyr'e not worried about intellij plugin code
> intermingled in AW.
>
> just getting an idea of how many people use it that way.  It's not the best
> integration with intellij so I use AW standalone personally.
>
> Thanks,
> Ter
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.




[il-antlr-interest: 27680] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error

2010-01-26 Thread Bart Kiers
Karljürgen,

In order to run ANTLRWorks, you do not need 'javac', but 'java'.

'javac' is the compiler that will compile java source files into byte codes
that the JRE (Java Runtime Environment) interprets/executes.

'java' is the application that executes the byte codes produced by 'javac'.
Since ANTLRWorks is already compiled, you only need 'java'.

So, on the command line, give the following command:

java -jar antlrworks-1.3.1.jar

If the above does not work, please post the exact error message(s) on the
list.

Thanks.

Bart.


On Tue, Jan 26, 2010 at 6:51 PM, Karljurgen Feuerherm wrote:

> Hello,
>
> I'm new to this product (and to modern products of this type
> generally... was a B programmer in the early 80s and trying to get
> updated!)
>
> I'm on Windows XP, and have run the JAR file to invoke ANTLRWorks.
>
> I'm trying out the Expression Evaluator Tutorial. Interpreter works
> fine, but invoking the debugger gets me
>
> "java.IO.IOException: Cannot run program "javac": CreateProcess
> error=2, the system cannot find the file specified"
>
> (Oddly, after a while, trying it again got me a different error about
> timeout, even though I'd changed nothing [Sure. Famous Last Words,
> eh?].)
>
> Not sure where to go from here... By all means be pedantic in a
> response :)
>
> Thanks!
>
> K
>
> Karljürgen G. Feuerherm, PhD
> Department of Archaeology and Classical Studies
> Wilfrid Laurier University
> 75 University Avenue West
> Waterloo, Ontario N2L 3C5
> Tel. (519) 884-1970 x3193
> Fax (519) 883-0991 (ATTN Arch. & Classics)
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27681] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error

2010-01-26 Thread Bart Kiers
On Tue, Jan 26, 2010 at 7:37 PM, Andreas Stefik  wrote:

> I think he's asking why the debugger throws errors with javac, not how to
> start antlrworks.
>
> The error you are seeing is because the antlrworks debugger, far as I
> understand it, needs a java compiler to actually debug a grammar. As such,
> you need to put the path to your javac compiler in the path field in
> antlrworks. This is straightforward to do:
>
> 1. Open up the options window. I'm on mac at the moment, which is in
> preferences, but on windows it is similar.
> 2. Go to the tab labeled compiler and look for where it says javac.
> 3. Check path under javac, then click browse and a window should appear.
> 4. Browse to where javac is located.
>
> As I'm on mac, the paths are different, but if I recall correctly, on
> windows javac is in program files, so it would be something "like"
>
> c:\program files\Java\bin\javac.exe
>
> That path might not be correct, but I don't have a windows box on me to
> give it to you exactly. Should be close though and if you browse around you
> should find it.
>
> The last detail is that, if you can't find javac, you may not have the JDK
> installed (java.sun.com), so you'll need to do that. It's just a little
> installer, so there's nothing fancy to do. You can know for sure whether you
> have it by going to the command line and typing:
>
> javac
>
> if it throws an error, you need the JDK. If it's there, you will see a
> bunch of information put out to the terminal.
>
> Hope that helps,
>
> Andreas Stefik, Ph.D.
> Assistant Professor
> Department of Computer Science
> Southern Illinois University Edwardsville
>
>
>
> On Tue, Jan 26, 2010 at 12:19 PM, Bart Kiers  wrote:
>
>> Karljürgen,
>>
>> In order to run ANTLRWorks, you do not need 'javac', but 'java'.
>>
>> 'javac' is the compiler that will compile java source files into byte
>> codes
>> that the JRE (Java Runtime Environment) interprets/executes.
>>
>> 'java' is the application that executes the byte codes produced by
>> 'javac'.
>> Since ANTLRWorks is already compiled, you only need 'java'.
>>
>> So, on the command line, give the following command:
>>
>> java -jar antlrworks-1.3.1.jar
>>
>> If the above does not work, please post the exact error message(s) on the
>> list.
>>
>> Thanks.
>>
>> Bart.
>>
>>
>> On Tue, Jan 26, 2010 at 6:51 PM, Karljurgen Feuerherm > >wrote:
>>
>> > Hello,
>> >
>> > I'm new to this product (and to modern products of this type
>> > generally... was a B programmer in the early 80s and trying to get
>> > updated!)
>> >
>> > I'm on Windows XP, and have run the JAR file to invoke ANTLRWorks.
>> >
>> > I'm trying out the Expression Evaluator Tutorial. Interpreter works
>> > fine, but invoking the debugger gets me
>> >
>> > "java.IO.IOException: Cannot run program "javac": CreateProcess
>> > error=2, the system cannot find the file specified"
>> >
>> > (Oddly, after a while, trying it again got me a different error about
>> > timeout, even though I'd changed nothing [Sure. Famous Last Words,
>> > eh?].)
>> >
>> > Not sure where to go from here... By all means be pedantic in a
>> > response :)
>> >
>> > Thanks!
>> >
>> > K
>> >
>> > Karljürgen G. Feuerherm, PhD
>> > Department of Archaeology and Classical Studies
>> > Wilfrid Laurier University
>> > 75 University Avenue West
>> > Waterloo, Ontario N2L 3C5
>> > Tel. (519) 884-1970 x3193
>> > Fax (519) 883-0991 (ATTN Arch. & Classics)
>> >
>> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> > Unsubscribe:
>> > http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>> >
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27782] Re: [antlr-interest] Noob question

2010-02-04 Thread Bart Kiers
have it processed by a language lib, which will give me the individual
> functions and var declarations listed in a tree which I can then process
> further.
>
>
>
> Attached is a file typical of what I’ll be working with. You’ll notice part
> way down is a string that starts with “var blue=…” That is malicious if run
> from a browser. All the other code is benign. So what I want is to be able
> to clean that file – just of the infectious code.
>
>
>
> Any thoughts on this would be greatly appreciated.
>
>
>
> Thank you for taking the time to respond.
>
>
>
> Thomas J. Raef
>
> e-Based Security <http://www.ebasedsecurity.com/>
>
> "You're either hardened or you're hacked!"
>
> We Watch Your Website <http://www.wewatchyourwebsite.com/>
>
> "We Watch Your Website - so you don't have to."
>
>
>
> *From:* Bart Kiers [mailto:bki...@gmail.com]
> *Sent:* Thursday, February 04, 2010 6:29 AM
> *To:* Thomas Raef
>
> *Subject:* Re: [antlr-interest] Noob question
>
>
>
> Hi brother,
>
>
> Sure, ANTLR could be used in this case. What target language are you using?
> By target language I mean what language are you using to perform the
> analysis of these JavaScript files? Check this link:
> http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets to see if
> your target language is supported.
>
> On the Wiki, there ar a couple of ECMA script grammars you can use:
> http://www.antlr.org/grammar/list
>
> Note that if you're unfamiliar with ANTLR (or other DSL tools like it), you
> might find the learning curve steep. Of course, as an ANTLR enthusiast, I
> encourage you to bite the bullet. The wiki is an excellent resource:
> http://www.antlr.org/wiki/display/ANTLR3/ANTLR+3+Wiki+Home and getting
> your hands on a copy of The Definitive ANTLR Reference,
> http://www.pragprog.com/titles/tpantlr/the-definitive-antlr-reference ,
> would be even better.
>
> Good luck!
>
> Bart.
>
>  On Thu, Feb 4, 2010 at 1:15 PM, Thomas Raef 
> wrote:
>
> I want to use ANTLR to parse potentially malicious javascript files. The
> files in question have a string or strings embedded in them that don't
> cause the javascript file to error, but I do want to separate each
> function or declaration in the .js file into an individual string, then
> I'll process them to see if they are malicious or not.
>
>
>
> Is this the right tool? And if so, is there anyone who can point me in
> the right direction to get started? I know it's a very noob question,
> but I've been trying different tools and failing at each one.
>
>
>
> Can anyone "hook a brother up?"
>
>
>
> Thank you in advance
>
>
>
> Thomas J. Raef
>
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27783] Re: [antlr-interest] Noob question

2010-02-04 Thread Bart Kiers
Hi Thomas,

Good to hear it.
Note that when converting from Java to Python that you only need to replace
the code between the '{' and '}':

@members {
  ... your python code here ...
}

sourceElement
: f=functionDeclaration { ... your python code here ... }
| s=statement   { ... your python code here ... }
;

functionBody
: '{'{ ... your python code here ... } LT!* sourceElements LT!* '}'{ ...
your python code here ... }
;

And instead of the default Java target, you need to specify that you want to
generate Python parser- and lexer-source files. Do that by adding:

language=Python;

inside the options-block of the JavaScript grammar file.

You'll be on my skills-level in no time (which is not that impressive
really) when you read through *The Definitive ANTLR Reference* you ordered.

Regards,

Bart.




On Thu, Feb 4, 2010 at 4:46 PM, Thomas Raef wrote:

>  HTH?
>
>
>
> Help? You did exactly what I was looking for. You rock dude.
>
>
>
> I’m going to go to work on converting that to Python code, or learn Java,
> which I’ve been putting off for some time now.
>
>
>
> My only concern is in grouping the STATEMENT lines. In your example these
> three lines work together:
>
>
>
> STATEMENT -> var blue='%3c'+'%73'+'%63'+'%72'+'%69'+' ... 74'+'%3e';
> STATEMENT -> for(z=0;z STATEMENT -> FE('%275Euetkrv%2742NCPIWCIG%275F%2744lc ... v%275G2');
>
>
>
> So, I’ll have to figure out a way to combine them, which shouldn’t be too
> difficult. That way I can test the entire malscript.
>
>
>
> You are awesome! Thank you so much.
>
>
>
> How long have you been working with ANTLR?
>
>
>
> Thomas J. Raef
>
> e-Based Security <http://www.ebasedsecurity.com/>
>
> "You're either hardened or you're hacked!"
>
> We Watch Your Website <http://www.wewatchyourwebsite.com/>
>
> "We Watch Your Website - so you don't have to."
>
>
>
> *From:* Bart Kiers [mailto:bki...@gmail.com]
> *Sent:* Thursday, February 04, 2010 9:05 AM
> *To:* Thomas Raef; antlr-interest@antlr.org interest
>
> *Subject:* Re: [antlr-interest] Noob question
>
>
>
> Hi Thomas,
>
> You're welcome of course. Sorry I forgot to put antlr-inter...@antlr.orgin 
> the To or CC line in my first reply. Not too used to mail-lists.
>
> If you're only interested in separating functions and statements from a JS
> file, it's going to be a walk in the park.
>
> Get the latest ANTLR JAR: http://www.antlr.org/download/antlr-3.2.jar
>
> Get this ECMA script grammar:
> http://www.antlr.org/grammar/1206736738015/JavaScript.g
>
> I'll give a short example in Java (I'm not too fluent in Python...).
>
> Put this:
>
> @members {
>
> // keeps track if we're inside a function
> public boolean insideFunction = false;
>
> public void prettyPrint(String type, String text) {
> text = text.replaceAll("\r?\n", " "); // remove line breaks
> if(text.length() > 55) {
> String start = text.substring(0, 40);
> String end = text.substring(text.length()-10);
> text = start+" ... "+end;
> }
> System.out.println(type+" -> "+text);
> }
> }
>
>
> above the 'program' rule (on line 15) in the JavaScript.g file.
> Replace:
>
> sourceElement
> : functionDeclaration
> | statement
> ;
>
>
> with:
>
> sourceElement
> : f=functionDeclaration { prettyPrint("FUNCTION ", $f.text.toString());
> }
> | s=statement   { if(!insideFunction) prettyPrint("STATEMENT",
> $s.text.toString()); }
> ;
>
> and replace:
>
> functionBody
> : '{' LT!* sourceElements LT!* '}'
> ;
>
>
> with:
>
> functionBody
> : '{'{insideFunction=true;} LT!* sourceElements LT!*
> '}'{insideFunction=false;}
> ;
>
>
> Now generate the parser and lexer .java files by doing:
>
> java -cp antlr-3.2.jar org.antlr.Tool JavaScript.g
>
>
> and create a small test class:
>
> import org.antlr.runtime.*;
> import java.io.FileInputStream;
>
> public class ANTLRDemo {
> public static void main(String[] args) throws Exception {
> ANTLRInputStream in = new ANTLRInputStream(new
> FileInputStream("mt.js")); // <- your JS file
> JavaScriptLexer lexer = new JavaScriptLexer(in);
> CommonTokenStream tokens = new CommonTokenStream(lexer);
> 

[il-antlr-interest: 27805] Re: [antlr-interest] Anyone have some good Python examples?

2010-02-05 Thread Bart Kiers
Thomas,

I highly recommend *carefully* reading the book.
Forgive me for saying, but I doubt that you actually read it. And if so, you
could only have skimmed through it (you have ordered it only yesterday!).

Regards,

Bart.


On Fri, Feb 5, 2010 at 10:23 PM, Thomas Raef
wrote:

> Okay. I would like to thank you all for allowing me to figure out the
> errors of my efforts. No sarcasm.
>
> I found out that since Bart was nice enough to get me started, even
> though it was a Java example, I didn't realize where my Python program
> was starting and what was antlr code.
>
> I discovered that my line: insideFunction = False; was causing the java
> compilation to complain so I moved that inside my def. I also realized
> that the code: $f.text.toString()); is java and is not part of antlr.
> Since I was using language=Python, it had no idea what I was trying to
> do.
>
> Now when I run my program, all I get is: STATEMENT ->
> (JavaScriptParser.statement_return object at 0x02168C90)
>
> What I want to see is the line of javascript code from the .js file I'm
> reading from prefaced with either STATEMENT or FUNCTION.
>
> Can anyone help me with that?
>
> I've watched the tutorials and read through the book, but I cannot for
> the life of me figure out how to get the line of javascript to print.
>
> Please help...
>
> Thomas J. Raef
>
>
>
> > -Original Message-
> > From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
> > boun...@antlr.org] On Behalf Of Thomas Raef
> > Sent: Thursday, February 04, 2010 5:29 PM
> > To: antlr-interest@antlr.org
> > Subject: [antlr-interest] Anyone have some good Python examples?
> >
> > I'm trying to get my simple program working and I keep running into
> > errors.
> >
> >
> >
> > In my JavaScript.g file I've set the language=Python;
> >
> >
> >
> > I have a @members section like:
> >
> >
> >
> > @members
> >
> > {
> >
> > insideFunction = False;
> >
> >
> >
> > def prettyPrint(type, text):
> >
> > text = text.replace("\r", '') //to remove carriage
> > returns in my javascript file (mt.js)
> >
> > text = text.replace("\n", '') // to remove new lines
> >
> > if len(text) > 55:
> >
> > start = text[:40]
> >
> > end = text[-10:]
> >
> > text = start+' ... '+end
> >
> > print type+' -> '+text
> >
> > }
> >
> >
> >
> >
> >
> > In a JavaScript.G file I have in the functionBody section:
> >
> >
> >
> > functionBody
> >
> > :  '{' {insideFunction=True;) LT!* sourceElements LT!*
> > '}' {insideFunction=False;}
> >
> > ;
> >
> >
> >
> > In sourceElement section I have:
> >
> > sourceElement
> >
> > : f=functionDeclaration { prettyPrint("FUNCTION ",
> > $f.text.toString()); }
> >
> > | s=statement { prettyPrint("STATEMENT ",
> > $s.text.toString()); }
> >
> > ;
> >
> >
> >
> > Then in python I'm doing:
> >
> > import antlr3
> >
> > from JavaScriptLexer import JavaScriptLexer
> >
> > from JavaScriptParser import JavaScriptParser
> >
> >
> >
> > char_stream = antlr3.ANTLRFileStream("mt.js")
> >
> > lexer = JavaScriptLexer(char_stream)
> >
> > tokens = antlr3.CommonTokenStream(lexer)
> >
> > parser = JavaScriptParser(tokens)
> >
> > parser.program()
> >
> >
> >
> > it barfs:
> >
> >
> >
> > prettyPrint("STATEMENT", ((s is not None) and
> > [self.input.toString(s.start, s.stop)] or [None])[0].toString());
> >
> > NameError: global name 'prettyPrint' is not defined
> >
> >
> >
> > I'm trying, but failing. Can anyone with python experience help me
> out?
> >
> >
> >
> > Thank you in advance.
> >
> >
> >
> > Thomas J. Raef
> >
> >
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27807] Re: [antlr-interest] Anyone have some good Python examples?

2010-02-05 Thread Bart Kiers
Thomas,

Especially read the paragraph 'Element Labels' on page 95 carefully: that's
what you need to print the part(s) you're interested in.

Regards,

Bart.


On Fri, Feb 5, 2010 at 10:59 PM, Bart Kiers  wrote:

> Thomas,
>
> I highly recommend *carefully* reading the book.
> Forgive me for saying, but I doubt that you actually read it. And if so,
> you could only have skimmed through it (you have ordered it only
> yesterday!).
>
> Regards,
>
> Bart.
>
>
>
> On Fri, Feb 5, 2010 at 10:23 PM, Thomas Raef  > wrote:
>
>> Okay. I would like to thank you all for allowing me to figure out the
>> errors of my efforts. No sarcasm.
>>
>> I found out that since Bart was nice enough to get me started, even
>> though it was a Java example, I didn't realize where my Python program
>> was starting and what was antlr code.
>>
>> I discovered that my line: insideFunction = False; was causing the java
>> compilation to complain so I moved that inside my def. I also realized
>> that the code: $f.text.toString()); is java and is not part of antlr.
>> Since I was using language=Python, it had no idea what I was trying to
>> do.
>>
>> Now when I run my program, all I get is: STATEMENT ->
>> (JavaScriptParser.statement_return object at 0x02168C90)
>>
>> What I want to see is the line of javascript code from the .js file I'm
>> reading from prefaced with either STATEMENT or FUNCTION.
>>
>> Can anyone help me with that?
>>
>> I've watched the tutorials and read through the book, but I cannot for
>> the life of me figure out how to get the line of javascript to print.
>>
>> Please help...
>>
>> Thomas J. Raef
>>
>>
>>
>> > -Original Message-
>> > From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
>> > boun...@antlr.org] On Behalf Of Thomas Raef
>> > Sent: Thursday, February 04, 2010 5:29 PM
>> > To: antlr-interest@antlr.org
>> > Subject: [antlr-interest] Anyone have some good Python examples?
>> >
>> > I'm trying to get my simple program working and I keep running into
>> > errors.
>> >
>> >
>> >
>> > In my JavaScript.g file I've set the language=Python;
>> >
>> >
>> >
>> > I have a @members section like:
>> >
>> >
>> >
>> > @members
>> >
>> > {
>> >
>> > insideFunction = False;
>> >
>> >
>> >
>> > def prettyPrint(type, text):
>> >
>> > text = text.replace("\r", '') //to remove carriage
>> > returns in my javascript file (mt.js)
>> >
>> > text = text.replace("\n", '') // to remove new lines
>> >
>> > if len(text) > 55:
>> >
>> > start = text[:40]
>> >
>> > end = text[-10:]
>> >
>> > text = start+' ... '+end
>> >
>> > print type+' -> '+text
>> >
>> > }
>> >
>> >
>> >
>> >
>> >
>> > In a JavaScript.G file I have in the functionBody section:
>> >
>> >
>> >
>> > functionBody
>> >
>> > :  '{' {insideFunction=True;) LT!* sourceElements LT!*
>> > '}' {insideFunction=False;}
>> >
>> > ;
>> >
>> >
>> >
>> > In sourceElement section I have:
>> >
>> > sourceElement
>> >
>> > : f=functionDeclaration { prettyPrint("FUNCTION ",
>> > $f.text.toString()); }
>> >
>> > | s=statement { prettyPrint("STATEMENT ",
>> > $s.text.toString()); }
>> >
>> > ;
>> >
>> >
>> >
>> > Then in python I'm doing:
>> >
>> > import antlr3
>> >
>> > from JavaScriptLexer import JavaScriptLexer
>> >
>> > from JavaScriptParser import JavaScriptParser
>> >
>> >
>> >
>> > char_stream = antlr3.ANTLRFileStream("mt.js")
>> >
>> > lexer = JavaScriptLexer(char_stream)
>> >
>> > tokens = antlr3.CommonTokenStream(lexer)
>> >
>> > parser = JavaScriptParser(tokens)
>> >
&

[il-antlr-interest: 27810] Re: [antlr-interest] Anyone have some good Python examples?

2010-02-05 Thread Bart Kiers
It just occurred to me that the PDF version has different page numbering...
My hard copy has 'Element Labels' on page 80.
Also see the entire chapter 6 "Attributes and Actions".

Good luck!

Bart.


On Sat, Feb 6, 2010 at 7:20 AM, Bart Kiers  wrote:

> Thomas,
>
> Especially read the paragraph 'Element Labels' on page 95 carefully: that's
> what you need to print the part(s) you're interested in.
>
> Regards,
>
> Bart.
>
>
>
> On Fri, Feb 5, 2010 at 10:59 PM, Bart Kiers  wrote:
>
>> Thomas,
>>
>> I highly recommend *carefully* reading the book.
>> Forgive me for saying, but I doubt that you actually read it. And if so,
>> you could only have skimmed through it (you have ordered it only
>> yesterday!).
>>
>> Regards,
>>
>> Bart.
>>
>>
>>
>> On Fri, Feb 5, 2010 at 10:23 PM, Thomas Raef <
>> tr...@wewatchyourwebsite.com> wrote:
>>
>>> Okay. I would like to thank you all for allowing me to figure out the
>>> errors of my efforts. No sarcasm.
>>>
>>> I found out that since Bart was nice enough to get me started, even
>>> though it was a Java example, I didn't realize where my Python program
>>> was starting and what was antlr code.
>>>
>>> I discovered that my line: insideFunction = False; was causing the java
>>> compilation to complain so I moved that inside my def. I also realized
>>> that the code: $f.text.toString()); is java and is not part of antlr.
>>> Since I was using language=Python, it had no idea what I was trying to
>>> do.
>>>
>>> Now when I run my program, all I get is: STATEMENT ->
>>> (JavaScriptParser.statement_return object at 0x02168C90)
>>>
>>> What I want to see is the line of javascript code from the .js file I'm
>>> reading from prefaced with either STATEMENT or FUNCTION.
>>>
>>> Can anyone help me with that?
>>>
>>> I've watched the tutorials and read through the book, but I cannot for
>>> the life of me figure out how to get the line of javascript to print.
>>>
>>> Please help...
>>>
>>> Thomas J. Raef
>>>
>>>
>>>
>>> > -Original Message-
>>> > From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
>>> > boun...@antlr.org] On Behalf Of Thomas Raef
>>> > Sent: Thursday, February 04, 2010 5:29 PM
>>> > To: antlr-interest@antlr.org
>>> > Subject: [antlr-interest] Anyone have some good Python examples?
>>> >
>>> > I'm trying to get my simple program working and I keep running into
>>> > errors.
>>> >
>>> >
>>> >
>>> > In my JavaScript.g file I've set the language=Python;
>>> >
>>> >
>>> >
>>> > I have a @members section like:
>>> >
>>> >
>>> >
>>> > @members
>>> >
>>> > {
>>> >
>>> > insideFunction = False;
>>> >
>>> >
>>> >
>>> > def prettyPrint(type, text):
>>> >
>>> > text = text.replace("\r", '') //to remove carriage
>>> > returns in my javascript file (mt.js)
>>> >
>>> > text = text.replace("\n", '') // to remove new lines
>>> >
>>> > if len(text) > 55:
>>> >
>>> > start = text[:40]
>>> >
>>> > end = text[-10:]
>>> >
>>> > text = start+' ... '+end
>>> >
>>> > print type+' -> '+text
>>> >
>>> > }
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > In a JavaScript.G file I have in the functionBody section:
>>> >
>>> >
>>> >
>>> > functionBody
>>> >
>>> > :  '{' {insideFunction=True;) LT!* sourceElements LT!*
>>> > '}' {insideFunction=False;}
>>> >
>>> > ;
>>> >
>>> >
>>> >
>>> > In sourceElement section I have:
>>> >
>>> > sourceElement
>>> >
>>> > : f=functionDeclaration { prettyPrint("FU

[il-antlr-interest: 27822] Re: [antlr-interest] Parse 1 - N repeats

2010-02-08 Thread Bart Kiers
Hi Adam,

You could handle it in (plain) programming logic inside your grammar.
Here's a little demo:

grammar Test;

@parser::members {
  public static void main(String[] args) throws Exception {
String text =
"FIELD1\n"+
"REPEATING_GROUP  \n"+
"FIELD2\n"+
"FIELD3\n"+
"FIELD4";
ANTLRStringStream in = new ANTLRStringStream(text);
TestLexer lexer = new TestLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
new TestParser(tokens).parse();
  }

  class Repeat {

final List fieldList;
final int fields;
final int min;
final int max;

Repeat(int fields, int min, int max) {
this.fieldList = new ArrayList(fields);
this.fields = fields;
this.min = min;
this.max = max;
}

boolean done() {
return fieldList.size() == fields;
}

public String toString() {
  return String.format("fields=\%s, min=\%d, max=\%d", fieldList, min,
max);
}
  }
}

parse
  :  (  rp=repeat {System.out.println("repeat :: "+$rp.r);}
 |  id=Identifier {System.out.println("field  :: "+$id.text);}
 )*
 EOF
  ;

repeat returns [Repeat r]
  :  Identifier '<' 'fields' '=' fields=Identifier '>' '<' 'min' '='
min=Identifier ',' 'max' '=' max=Identifier '>'
 {$r = new Repeat(Integer.valueOf($fields.text),
Integer.valueOf($min.text), Integer.valueOf($max.text));}
 (id=Identifier {$r.fieldList.add($id.text); if($r.done()) return $r;}
)*
  ;

Identifier
  :  ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' )+
  ;

WhiteSpace
  :  ( ' ' | '\t' | '\r' | '\n' ) {skip();}
  ;

As you see, whenever the size of the fieldList hits the total, $r is being
returned (and no more id=Identifier will be "eaten").
When you compile and execute the TestParser class, the following is being
printed:

field  :: FIELD1
repeat :: fields=[FIELD2, FIELD3], min=0, max=20
field  :: FIELD4

Regards,

Bart.


On Mon, Feb 8, 2010 at 1:56 PM, Adam Connelly <
adam.rpconne...@googlemail.com> wrote:

> Hi,
>
> Sorry if this is answered elsewhere, but I'm not really sure what to search
> for.
>
> I'm trying to parse a language that includes repeating groups. The problem
> is that they don't include terminators, so you can't tell the difference
> between the last item in the group, and the next section. Here's an
> example:
>
> FIELD1
> REPEATING_GROUP
>FIELD2
>FIELD3
> FIELD4
> ...
>
> "fields" specifies the number of fields contained in the group. At the
> moment I've got the following rules, but the problem is that it means that
> the repeating group rule doesn't get its fields associated with it:
>
> recordDefinition
>:RECORD (IDENTIFIER | repeatingGroup)+
>;
>
> repeatingGroup
>:IDENTIFIER
>'<' NUMBER_OF_FIELDS '=' fieldCount=NUMBER '>'
>'<' NUMBER_OF_REPEATS '=' min=NUMBER ',' max=NUMBER '>'
>;
>
> Ideally I could do something like:
>
> repeatingGroup
>:IDENTIFIER
>'<' NUMBER_OF_FIELDS '=' fieldCount=NUMBER '>'
>'<' NUMBER_OF_REPEATS '=' min=NUMBER ',' max=NUMBER '>'
>IDENTIFIER{1, $fieldCount}
>;
>
> But I know you can't do that. What would the best way be to go about
> parsing
> this? Can I build an AST then modify it to put the identifiers for the
> repeating group in the right place.
>
> Cheers,
> Adam
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27923] Re: [antlr-interest] Number of children

2010-02-15 Thread Bart Kiers
Why would it pose a problem?

AFAIK,

  OR
 /| \
A B  C

would evaluate the same as:

OR
   /  \
  OR   C
 /  \
AB

No?

Regards,

Bart.


2010/2/15 Nazim Oztahtaci 

>
> Hello,
>
> I have written a grammar based on an example on the Net to parse an
> expression like (a OR B)AND(C OR D) to a tree like
> AND
> OR   OR
> A B   C D
> It works fine but if expression has more then 2 children, like (A OR B OR
> C)AND(D OR E OR F)
> Then it creates problem because it does something like
> AND
>
> D OR
>   EF
> I want it to be like
>
> OR
> D  E  F
>
> In other words, a tree node might have capability to have more then 2 nodes
> as children. How can I set this? I work on C# but couldnt find any setter
> function in library.
> Best regards,
> Nazim
>
> _
> Yeni Windows 7: Size en uygun bilgisayarı bulun. Daha fazla bilgi edinin.
> http://windows.microsoft.com/shop
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27981] Re: [antlr-interest] C# example of "lexical filter mode" ??

2010-02-18 Thread Bart Kiers
Hi John,


On Thu, Feb 18, 2010 at 7:52 PM, John Pool  wrote:

> ...
>
> Question: how do I 'execute' such a grammar lexer in C# without feeding it
> into a parser?
>
>
You probably meant to instantiate a FuzzyLexer instead of a FuzzyParser
(unless your lexer grammar is called FuzzyParser, of course...).
Try this:

ANTLRStringStream in = new ANTLRStringStream("...some source
as a String...");
FuzzyLexer lexer = new FuzzyLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
for(Object obj : tokens.getTokens()) {
Token token = (Token)obj;
System.out.println(token);
}

Although the code above is Java, the C# variant can't be that much
different.

For a complete example how to use such a lexer, see the first answer from
this post on Stackoverflow:
http://stackoverflow.com/questions/2284571/how-to-match-a-comment-unless-its-in-a-quoted-string




>
> I tried downloading http://www.antlr.org/download/examples-v3.tar.gz, as
> suggested in the book, but that URL won't open.
>

No problem here: I can download that file just fine.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 27992] Re: [antlr-interest] Fwd: Mapping ANTLR grammar to XML

2010-02-19 Thread Bart Kiers
On Fri, Feb 19, 2010 at 5:13 PM, Ketan Maheshwari <
ketancmaheshw...@gmail.com> wrote:

> ...
>
> For instance the following assignment statement :
>
> in = ["t1 hyde"%patient:"mr hyde", "t1 argan"%patient:"mr argan"]
>
> is equivalent to the following xml:
>
> 
> 
> T1 Hyde
> T1 Argan
> 
> 
>
> The tagnames and elementnames are not important as such but the fact that
> they map as per the tree structure and the process is automated.
>

Have a look at "rewrite rules":
http://www.antlr.org/wiki/display/~admin/2008/04/11/Rewrite+rules

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28087] Re: [antlr-interest] help: using antlr

2010-02-25 Thread Bart Kiers
On Thu, Feb 25, 2010 at 11:27 PM, Scott Stanchfield wrote:

> ...
>
> See http://javadude.com/misc/astvis.mp4 for the basic idea (the
> stuttering is only due to the vid capture - the animation itself runs
> smoothly). Edgar and I are thinking of integrating this into ANTLR IDE
> once it's really cooked and has some nice breakpoint capability.
> -- Scott
>

NICE!
This might be the first time I regret switching to IntelliJ : )

Regards,

Bart.

@Smiley, sorry for the OT post!

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28142] Re: [antlr-interest] behaviour of lexer

2010-03-02 Thread Bart Kiers
On Tue, Mar 2, 2010 at 5:25 PM, Philippe Frankson <
philippe.frank...@frsglobal.com> wrote:

> ...
> @int('444') is a function converting a string into integer.
> If I don't have parentheses, then it is not a function, it is only a column
> name. Ex.: @test, @integer, @in, 
>
> Here is a part of lexer rules:
>
> fragment DIGIT  : ('0'..'9');
> fragment ALPHA  : ('a'..'z'|'A'..'Z'|'_');
>
> OB  : '(';
> INTTOKEN: ('@int' OB)=> '@int'; // so I check if there is an open
> parenthesis to return INTTOKEN.
> AT  : '@';
> NAME: ALPHA (ALPHA | DIGIT)*;   ...
>

Why not just include the OB in your lexer rule?
Something like this:

INT_METHOD  : AT 'int' OB; // or: AT 'int' OB STRING CB;
COLUMN  : AT NAME;

OB  : '(';
AT  : '@';
NAME: ALPHA (ALPHA | DIGIT)*;

fragment DIGIT  : ('0'..'9');
fragment ALPHA  : ('a'..'z'|'A'..'Z'|'_');

and because lexer rules are matched from top to bottom, '@int' will be
matched as 'AT NAME'.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28143] Re: [antlr-interest] behaviour of lexer

2010-03-02 Thread Bart Kiers
On Tue, Mar 2, 2010 at 7:00 PM, Bart Kiers  wrote:

>
>
> On Tue, Mar 2, 2010 at 5:25 PM, Philippe Frankson <
> philippe.frank...@frsglobal.com> wrote:
>
>> ...
>>
>> @int('444') is a function converting a string into integer.
>> If I don't have parentheses, then it is not a function, it is only a
>> column name. Ex.: @test, @integer, @in, 
>>
>> Here is a part of lexer rules:
>>
>> fragment DIGIT  : ('0'..'9');
>> fragment ALPHA  : ('a'..'z'|'A'..'Z'|'_');
>>
>> OB  : '(';
>> INTTOKEN: ('@int' OB)=> '@int'; // so I check if there is an open
>> parenthesis to return INTTOKEN.
>> AT  : '@';
>> NAME: ALPHA (ALPHA | DIGIT)*;   ...
>>
>
> Why not just include the OB in your lexer rule?
> Something like this:
>
> INT_METHOD  : AT 'int' OB; // or: AT 'int' OB STRING CB;
> COLUMN  : AT NAME;
>
> OB  : '(';
>
> AT  : '@';
> NAME: ALPHA (ALPHA | DIGIT)*;
>
> fragment DIGIT  : ('0'..'9');
> fragment ALPHA  : ('a'..'z'|'A'..'Z'|'_');
>
> and because lexer rules are matched from top to bottom, '@int' will be
> matched as 'AT NAME'.
>
> Regards,
>
> Bart.
>

But, maybe better, move the "responsibility" to the parser instead of the
lexer:

parse   :  method | column;

method  : AT NAME OB STRING CB;
column  : AT NAME;

STRING  : '"' ~('"')* '"';
OB  : '(';
CB  : ')';
AT  : '@';
NAME: ALPHA (ALPHA | DIGIT)*;

fragment DIGIT  : ('0'..'9');
fragment ALPHA  : ('a'..'z'|'A'..'Z'|'_');

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28217] Re: [antlr-interest] Unexpected behavior - Error?

2010-03-09 Thread Bart Kiers
Hi Chris, sorry, forgot to send to the list the first time!


On Tue, Mar 9, 2010 at 4:41 PM, Christoph Schinko
wrote:

>  Hi Bart!
>
> Thanks for the quick answer! Adding an EOF to the rule solves the issue in
> the toy example. Unfortunately we are using custom token label types and are
> now getting a ClassCastException. It seems that we now have the problem
> mentioned here:
>
> http://www.antlr.org/pipermail/antlr-interest/2009-November/036712.html
>
> Any thoughts on that?
>
>
Unfortunately, I don't... I presume you read that entire thread, if not, a
(possible) solution is given here:
http://www.antlr.org/pipermail/antlr-interest/2009-November/036719.html

Best of luck!

Regards,

Bart.



>
> On 09.03.2010 15:04, Bart Kiers wrote:
>
> Hi Chris,
>
> Since the input '<<<<<<< .mine' does not contain any illegal tokens, the
> parser just stops parsing since (statement)* will also match nothing. You'll
> want to "tell" your parser to continue parsing all the way to the end of
> your token stream. Do that by adding an EOF to the end of your entry-point:
> presumably the source parser rule:
>
> source
>   : (statement)* EOF
>   ;
>
> Regards,
>
> Bart.
>
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28220] Re: [antlr-interest] MismatchedTokenException in simple grammar

2010-03-09 Thread Bart Kiers
FYI:
http://stackoverflow.com/questions/2412440/antlr-mismatchedtokenexception-on-simple-grammar

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28242] Re: [antlr-interest] Java arrays in "returns" ?

2010-03-13 Thread Bart Kiers
2010/3/12 Marcin Rzeźnicki 

> Hi
> I've got an awkward question. How can I return an array from rule?
> "rule_name returns [Object[] sth] " obviously does not work because syntax
> checker thinks that closing bracket of Object[] closes returns. I could not
> find anywhere how to escape it. Thx for any 
> help.
>

This message from 2007 indicates it is not possible to have nested brackets
inside "rule return statements":
http://www.antlr.org/pipermail/antlr-interest/2007-March/019712.html
and AFAIK, this still is not possible.

You will have to do something like:

@parser::members {

  class Wrapper {

String[] array;

Wrapper(String[] a) {
  array = a;
}
  }

}

parse
  :  rule {String s = $rule.wrapper.array[2];}
  ;

rule returns [Wrapper wrapper]
  :  ... {$wrapper = new Wrapper(new String[]{"a", "b", "c"});}
  ;


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28276] Re: [antlr-interest] Grammar help

2010-03-15 Thread Bart Kiers
On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin  wrote:

>
> When I compile the grammar with ANTLR, I get the following:
>
>
>
> warning(149): Commands.g:0:0: rewrite syntax or operator with no output
> option; setting output=AST
>


Hi Brian,

The '!' and '^' are tree-rewrite operators, so ANTLR is telling you here
that you're trying to rewrite something without specifying you're building a
tree. Doing a CRL+F I found this rule:

commands
  :  ( script_command
 | dump_command
! show_command // <- !
 )*
  ;

Notice the '!' (exclamation mark) that should be a '|' (pipe):

commands
   :  ( script_command
 | dump_command
| show_command // <- |
 )*
  ;

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28277] Re: [antlr-interest] Grammar help

2010-03-15 Thread Bart Kiers
On Tue, Mar 16, 2010 at 7:35 AM, Bart Kiers  wrote:

> On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin  wrote:
>
>>
>> When I compile the grammar with ANTLR, I get the following:
>>
>>
>>
>> warning(149): Commands.g:0:0: rewrite syntax or operator with no output
>> option; setting output=AST
>>
>
>
> ...
>

The same goes for:

qualifier
  : ALL
  ! CODE   // should be a '|' instead of a '!'
  | TABLE
  ;

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28279] Re: [antlr-interest] Grammar help

2010-03-16 Thread Bart Kiers
On Tue, Mar 16, 2010 at 8:10 AM, Brian Catlin  wrote:

> While that gets rid of those warnings (why don't the warnings print a
> reasonable line number?  I would call that a BUG),


Note that the '!' is a valid operator inside your grammar, ANTLR just
assumes that you're building trees. So, you're not doing anything wrong.
But, yes, a warning with the line number of the improper use of rewrite
operators would be nice.


 On Tue, Mar 16, 2010 at 8:10 AM, Brian Catlin  wrote:

> the fundamental problem
> of being able to parse (or otherwise capture the file name) still exists.
>
> Any ideas?
>

The error message is telling that your FILE_NAME is ambiguous. When matching
one or more characters from:

~('|' | '<' | '>' | '*' | '?')+

then line breaks will also be matched, yet after that, the following could
be matched:

('\r'? '\n')

which has already been "eaten" by the previous part of your rule. You could
fix that by adding line breaks to that first part of your rule, like this:

FILE_NAME:  ~('|' | '<' | '>' | '*' | '?'| '\r' | '\n')+ (('\r'? '\n') |
EOF);

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28344] Re: [antlr-interest] Parse assignments and method calls

2010-03-23 Thread Bart Kiers
On Tue, Mar 23, 2010 at 2:56 PM, Damien Urruty wrote:

>
> Hello
> I have been working on the Java grammar,...


What is "the Java grammar" here? A ANTLR grammar you found on the net, or on
one of ANTLR's wiki pages[1]? If so, you might want to tell which one
(there's more than one on the wiki). Or do you mean the grammar from the
JLS[2]?

Regards,

Bart.

[1] http://www.antlr.org/grammar/list
[2] http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28362] Re: [antlr-interest] Mutual left recursive problem

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 9:19 AM, foxterri foxterri wrote:

>
> Hi
>
> I have this left recursive problem which i cannot figure out how to solve
> and ANTLR WORKS cannot recognize the left recursive problem.
>

There is no "left recursive" rule in the part of your grammar you posted.
Can you post, or attach, the complete grammar?

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28365] Re: [antlr-interest] Mutual left recursive problem

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 9:56 AM, foxterri foxterri wrote:

>
> The complete grammer is attached, it is not completely done, but should
> give a good overview of it.
>
> debugging it in eclipse gives the following error:
>
> error(210): The following sets of rules are mutually left-recursive
> [primaryNoNewArray, arrayAccess, methodInvocation, primary, fieldAccess]
>

That grammar still contains errors, but after commenting them out, I can
spot the left recursive rules.
I presume you know what left recursive rules are? If not, here's one in your
grammar: an 'arrayAccess' first part can be a 'primaryNoNewArray' whose
first part can be a 'methodInvocation' whose first part can be a 'primary'
whose first part can be a 'primaryNoNewArray'. The 'primaryNoNewArray' makes
it left recursive. Note that by "first part", I mean the left-most part of a
rule.

arrayAccess
 primaryNoNewArray <---+
  methodInvocation |
   primary | left recursive
primaryNoNewArray <+

Checkout ANTLR's wiki about this in more detail and how to remove them:
http://www.antlr.org/wiki/display/ANTLR3/Left-Recursion+Removal

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28367] Re: [antlr-interest] strange MismatchedTokenException

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 10:00 AM, Simon zack  wrote:

> hi,
>
> I'm new to antler
> tried writing a little grammer, but it tells me MismatchedTokenException
> when I interpret namespace_specification
> using the string:
> "hello.world"
>
>
Then you start interpreting "hello.world" with the 'exception_info' rule,
which only matches the string '.exception'. You probably meant to start
interpreting with the 'namespace_specification' rule, whcih matches "hello."
from "hello.world".

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28369] Re: [antlr-interest] NoViableAltException this time

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 1:27 PM, Simon zack  wrote:

> tried using namespace_specification to interpret the string, but the error
> still shows up
>
> I changed the code a little, but a new exception pops up
>
> this only works when I remove the exception_info, however adding it messes
> up things
>

Both your first grammar:

exception_info
  :  '.exception'
  ;

namespace_specification
  :  ns_id1 = IDENTIFIER '.'
  ;

IDENTIFIER
  :  LETTER (LETTER|'0'..'9')*
  ;

LETTER
  :  '$'
  |  'A'..'Z'
  |  'a'..'z'
  |  '_'
  ;


and your second grammar:

exception_info
  :  '.exception'
  ;

namespace_specification
  :  ns_id1 = IDENTIFIER ('.' ns_idx = IDENTIFIER)*
 //ns_id1 = IDENTIFIER ( '.' ns_idx = IDENTIFIER)*
  ;

IDENTIFIER
  :  LETTER (LETTER|'0'..'9')*
  ;

fragment LETTER
  :  '$'
  |  'A'..'Z'
  |  'a'..'z'
  |  '_'
  ;

interpret the string "hello.world" just fine. See the attached output of
ANTLRWorks v1.3.1.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
<><>-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28372] Re: [antlr-interest] Lexer rule for strings with quoted strings within

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 2:01 PM, Anders Sollander <
anders.sollan...@mathworks.de> wrote:

> Hi,
>
> I've been trying to write a lexer rule for strings with strings in them,
> like
>
>"This has a ""quoted string"" within"
>
> Is there a simple lexer rule for this, or do I need some kind of look
> ahead?
>
>
You could enable the `backtrack` option:

String
options { backtrack = true; }
  :  '"' ('""' | ~'"')+ '"'
  ;

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28373] Re: [antlr-interest] Lexer rule for strings with quoted strings within

2010-03-25 Thread Bart Kiers
On Thu, Mar 25, 2010 at 2:50 PM, Bart Kiers  wrote:

>
>
> On Thu, Mar 25, 2010 at 2:01 PM, Anders Sollander <
> anders.sollan...@mathworks.de> wrote:
>
>> Hi,
>>
>> I've been trying to write a lexer rule for strings with strings in them,
>> like
>>
>>"This has a ""quoted string"" within"
>>
>> Is there a simple lexer rule for this, or do I need some kind of look
>> ahead?
>>
>>
> You could enable the `backtrack` option:
>
> String
> options { backtrack = true; }
>   :  '"' ('""' | ~'"')+ '"'
>   ;
>
> Regards,
>
> Bart.
>
>

Sorry, I should first test what I propose, it doesn't seem to work...

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28392] Re: [antlr-interest] (no subject)

2010-03-27 Thread Bart Kiers
On Sat, Mar 27, 2010 at 9:15 AM, Gouasmi Thouraya wrote:

> Hello,
> I have to develop a tool which makes the generation of a
> specification in CSP-Z from a specification Z, It is possible to use
> your tool ANTLR to introduce the grammar of language Z and the grammar
> of language CSP-Z and rules which I have already defined textuellement
> and what is that I obtain a code or this tool makes the generation he
> even?
> please answer me it rather possible
> please
> thanks
>

http://antlr.markmail.org/search/?q=csp#query:csp%20from%3A%22Gouasmi%20Thouraya%22+page:1+mid:odfowxsgqufl4zvm+state:results

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28393] Re: [antlr-interest] (no subject)

2010-03-27 Thread Bart Kiers
On Sat, Mar 27, 2010 at 9:16 AM, Gouasmi Thouraya wrote:

> Hello,
> I have to develop a tool which makes the generation of a
> specification in CSP-Z from a specification Z, It is possible to use
> your tool ANTLR to introduce the grammar of language Z and the grammar
> of language CSP-Z and rules which I have already defined textuellement
> and what is that I obtain a code or this tool makes the generation he
> even?
> please answer me it rather possible
> please
> thanks
>

http://antlr.markmail.org/search/?q=csp#query:csp%20from%3A%22Gouasmi%20Thouraya%22+page:1+mid:odfowxsgqufl4zvm+state:results

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28417] Re: [antlr-interest] expressing URL in ANTLR grammar

2010-03-30 Thread Bart Kiers
On Tue, Mar 30, 2010 at 2:18 PM, Ketan Maheshwari <
ketancmaheshw...@gmail.com> wrote:

> ...
>
> Actually this is my lame attempt to ask if someone can help me express URL
> in ANTLR grammar. :-)
>
>
I'd start by reading the specs of a URL:
http://www.w3.org/Addressing/URL/url-spec.txt , and then try to convert that
in an ANTLR grammar.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28431] Re: [antlr-interest] Empty complement set?

2010-03-31 Thread Bart Kiers
On Wed, Mar 31, 2010 at 11:20 AM, Anton Bychkov wrote:

> Hi.
>
> The following grammar does not generate target code.
> It says "error(139): skipper.g: set complement is empty".
>

Try adding the lexer rules:

LParen : '(';
RParen : ')';

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28433] Re: [antlr-interest] Empty complement set?

2010-03-31 Thread Bart Kiers
On Wed, Mar 31, 2010 at 11:47 AM, Anton Bychkov wrote:

> ...
> There is also a strange thing in rule view, it looks like antlr does
> not see LParen and RParen in twiddle operator.
> I attached screenshot with it.
>

Ah, I see. There are no other tokens than '(' and ')' defined, so
~(LParen|RParen) is wrong. Try adding a "fall through" DOT in your lexer
grammar:

skipper
   @init {
   int braceCount = 1;
   }
   : (
   LParen
   {
   braceCount ++;
   }
   | RParen
   {
   braceCount --;
   if(braceCount == 0)
   {
   LTOKEN = EOF_TOKEN;
   }
   }
   | Other
   ) *
   ;

LParen : '(' ;
RParen : ')' ;
Other  :  .  ;

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28434] [antlr-interest] Fwd: Empty complement set?

2010-03-31 Thread Bart Kiers
-- Forwarded message --
From: Bart Kiers 
Date: Wed, Mar 31, 2010 at 12:01 PM
Subject: Re: [antlr-interest] Empty complement set?
To: antlr-interest@antlr.org




On Wed, Mar 31, 2010 at 11:47 AM, Anton Bychkov wrote:

> ...
>
> There is also a strange thing in rule view, it looks like antlr does
> not see LParen and RParen in twiddle operator.
> I attached screenshot with it.
>

Ah, I see. There are no other tokens than '(' and ')' defined, so
~(LParen|RParen) is wrong. Try adding a "fall through" DOT in your lexer
grammar:

skipper
   @init {
   int braceCount = 1;
   }
   : (
   LParen
   {
   braceCount ++;
   }
   | RParen
   {
   braceCount --;
   if(braceCount == 0)
   {
   LTOKEN = EOF_TOKEN;
   }
   }
   | Other
   ) *
   ;

LParen : '(' ;
RParen : ')' ;
Other  :  .  ;

Or like this:

LParen : '(';
RParen : ')';
Other  : ~(LParen | RParen);

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28462] Re: [antlr-interest] posting

2010-04-01 Thread Bart Kiers
On Thu, Apr 1, 2010 at 11:05 AM, Kumar, Amitesh <
amitesh.ku...@standardbank.com> wrote:

> Hi im trying to post to the antlr interest group but it seems I get
> bouced everytime
>

Not any more: this one went through just fine.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28466] Re: [antlr-interest] Syntax of rewrite rule

2010-04-01 Thread Bart Kiers
On Thu, Apr 1, 2010 at 1:21 PM, Christian Mayer <
christian.ma...@bsse.ethz.ch> wrote:

> I am wondering how to transform the rewrite rule
>
> Expr:   mul_expr ( ( PLUS | MINUS )^ mul_expr )*;
>
> Into the explicit form with the arrow
>
> Expr:   a=mul_expr (  op=( PLUS | MINUS ) b=mul_expr )*   ->   ? ;
>
> For later use in an AST tree parser.
>
> What is the proper way to do this? I checked ² The definitive ANTL
> reference²/online documentation but could not find anything about the
> syntax.
>

I did not test it, but I believe this would work:

Expr
  :  (a=mul_expr   -> $a   )
 (op=(PLUS | MINUS) b=mul_expr -> ^($op $a $b) )*
  ;

Also see Chapter 7, section "Constructing AST's with rewrite rules"
paragraph "Rewrite Rules in Subrules" from "The definitive ANTLR reference".

Kind regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28567] Re: [antlr-interest] need some advice

2010-04-09 Thread Bart Kiers
On Fri, Apr 9, 2010 at 10:56 AM, Dietmar Schaefer wrote:

> ...
> DefSequence L { -- }   works
>
> DefSequence L { A1200}  gives me MismatchedTokenException: line 1:16
> mismatched input 'A1200' expecting '\u0006'
>

When stumbling upon the 'A' from 'A1200', the lexer tries to complete an
ID-rule. Try moving the VALUE-rule before the ID-rule:

grammar Test;

scenario
  :  statement
  ;


statement
  :  sequenceStatement
  ;

sequenceStatement
   :  'DefSequence' ID '{' VALUE '}' ';'?
   ;

VALUE
  :  ('A' | 'B' | 'C') DIGIT DIGIT DIGIT DIGIT
  |  ('-')*
  ;

ID
  :  LETTER (LETTER | DIGIT | '_')*
  ;

fragment
DIGIT
  :  '0'..'9'
  ;

fragment
LETTER
  :  'a'..'z' | 'A'..'Z'
  ;

WHITESPACE
  :  ('\t' | ' ' | '\n' | '\r')+ {$channel = HIDDEN;}
  ;

But note that your ID's can then not start with 'A', 'B' or 'C'! If you want
that, look into semantic predicates:
http://www.antlr.org/doc/glossary.html#Predicate,_semantic

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28540] Re: [antlr-interest] trouble running Antlr on grammar file

2010-04-20 Thread Bart Kiers
On Tue, Apr 20, 2010 at 7:51 PM, Kumar, Rajesh (Systems) UTRC <
kum...@utrc.utc.com> wrote:

> ...
>
> When I run "java antlr.Tool Expression.g" I get the following
>
> ANTLR Parser Generator   Version 2.7.7 (20060906)   1989-2005
> Expression.g:1:1: unexpected token: grammar
> error: Token stream error reading grammar(s):
> Expression.g:11:13: expecting ''', found '>'
> Expression.g:1:1: rule grammar trapped:
> Expression.g:1:1: unexpected token: grammar
> TokenStreamException: expecting ''', found '>'
> ...



I can't reproduce that.
Using ANTLR 3.2 and the grammar from your post, I get the following:

b...@hades:~/Temp/antlr$ java -cp antlr-3.2.jar org.antlr.Tool Expression.g
warning(200): Expression.g:11:9: Decision can match input such as "'&&'"
using multiple alternatives: 2, 4
As a result, alternative(s) 4 were disabled for that input
warning(200): Expression.g:11:9: Decision can match input such as "'->'"
using multiple alternatives: 1, 4
As a result, alternative(s) 4 were disabled for that input
warning(200): Expression.g:11:9: Decision can match input such as "'||'"
using multiple alternatives: 3, 4
As a result, alternative(s) 4 were disabled for that input


Note that the above are mere warnings, not errors (not that they shouldn't
be resolved of course...).

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28550] Re: [antlr-interest] Non-determinism (was: Can I force a token to have precendence in the lexer?)

2010-04-20 Thread Bart Kiers
On Wed, Apr 21, 2010 at 2:41 AM, Andy Hull  wrote:

> Wow, thanks for the article. I was able to redefine the language to avoid
> the problem in order to keep the parser as simple as possible (now using
> "to" instead of "..." ).
>
> My parser needs to be able to handle nested array expressions like so
>
> {1,2,{5 to 10}, {3,6,9}, 4}
>
> I have the following grammar:
>
> arrayExpression
> :   LEFT_BRACKET! arrayInitializer? RIGHT_BRACKET!;
> arrayInitializer
> :  (e+=expression (',' e+=expression)*)+ -> ^(ELEMENTLIST $e*)
> |  expression AUTO expression -> ^(AUTO expression expression)
> ;
>
> expression
> : arrayExpression
> /* | other types of expression */
> ;
>
> with the expected non-LL(*) grammar because "arrayInitializer" depends on
> the recursive rule expression. Setting backtrack to true doesn't resolve
> this as I expected.
>
> x={1,2,3,4};
>
> yields the correct tree but...
>
> x={1 to 3};
>
> yields the error:
>
> BR.recoverFromMismatchedToken
> line 1:5 mismatched input 'to' expecting RIGHT_BRACKET
>
> arrayInitializer behaves as expected when it contains only a single subrule
> (either the element list or the range initializer).
>
> Is backtracking the right solution to the non-determinism? I am doing
> something wrong?
>

How about something like this:

grammar Test;

parse
  : array ';' EOF
  ;

array
  :  '{' (arrayAtom (',' arrayAtom)*)? '}'
  ;

arrayAtom
  :  Number
  |  array
  |  range
  ;

range
  :  Number 'to' Number
  ;

Number
  :  '0'..'9'+
  ;

Space
  :  (' ' | '\t' | '\r' | '\n') {skip();}
  ;

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28589] Re: [antlr-interest] Parsing floats and unary minus

2010-04-24 Thread Bart Kiers
On Sat, Apr 24, 2010 at 4:25 AM, Rick Mann  wrote:

> float returns [float val]
>:   { $val = Float.parseFloat($FLOAT.text); }
>;
>

Note that you never use your 'float' rule.


On Sat, Apr 24, 2010 at 4:25 AM, Rick Mann  wrote:

> INT :   '0'..'9'+
>;
>
> FLOAT
>:   ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
>|   '.' ('0'..'9')+ EXPONENT?
>|   ('0'..'9')+ EXPONENT
>;
>

Try placing FLOAT before INT in your grammar.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28591] Re: [antlr-interest] Parsing floats and unary minus

2010-04-24 Thread Bart Kiers
On Sat, Apr 24, 2010 at 1:05 PM, Rick Mann  wrote:

>
> On Apr 24, 2010, at 01:34:08, Bart Kiers wrote:
>
> > On Sat, Apr 24, 2010 at 4:25 AM, Rick Mann 
> wrote:
> > float returns [float val]
> >:   { $val = Float.parseFloat($FLOAT.text); }
> >;
> >
> > Note that you never use your 'float' rule.
>
> Yeah, I go back and forth, trying to make it work.
>

Okay, but you showed a grammar where you did not use your float-rule, but
mentioned you had problems with that rule. Could you post the grammar you're
actually having problems with?


>
> > INT :   '0'..'9'+
> >;
> >
> > FLOAT
> >:   ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
> >|   '.' ('0'..'9')+ EXPONENT?
> >|   ('0'..'9')+ EXPONENT
> >;
> >
> > Try placing FLOAT before INT in your grammar.
>
> That's straight from the ANTLRWorks grammar creation wizard. Is it
> incorrect?
>
> --
> Rick
>


If you haven't changed anything about the order, then itmust be correct.

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28606] Re: [antlr-interest] VHDL Target

2010-04-26 Thread Bart Kiers
On Mon, Apr 26, 2010 at 10:02 PM, David Blubaugh <
davidblubaugh2...@yahoo.com> wrote:

> To All,
>
> Has anyone developed a VHDL target within ANTLR??


Hi, do you really mean a VHDL-target (being able to generate VHDL
sourcefiles from a given grammar?), or did you mean a VHDL-grammar?

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28614] Re: [antlr-interest] VHDL Target

2010-04-26 Thread Bart Kiers
>
>
>
>  On Mon, Apr 26, 2010 at 10:02 PM, David Blubaugh <
> davidblubaugh2...@yahoo.com
> > wrote:
>
>> To All,
>>
>> Has anyone developed a VHDL target within ANTLR??
>
>
> Hi, do you really mean a VHDL-target (being able to generate VHDL
> sourcefiles from a given grammar?), or did you mean a VHDL-grammar?
>
> Regards,
>
> Bart.
>
>
> >
> Both
>
> Thank You
>
> David


The examples section has a couple of VHDL grammars:
http://www.antlr.org/grammar/list

I'm not familiar with the language itself, but I doubt there is a VHDL
target around (if even possible since it is some sort of of
hardware-modeling language). Why do you need a VHDL-target? What problem are
you trying to solve? Some more info cuold clarify things.

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28747] Re: [antlr-interest] antlr doubt

2010-05-06 Thread Bart Kiers
On Thu, May 6, 2010 at 3:44 PM, Nishanth singh wrote:

> > ...
> > This is the error I get when I try to compile:
> >
> > $ javac locoTokensLexer.java
> > locoTokensLexer.java:3: package org.antlr.runtime does not exist
> > import org.antlr.runtime.*;
> > ^
> > locoTokensLexer.java:8: cannot find symbol
> > symbol: class Lexer
> > public class locoTokensLexer extends Lexer {
> >  ^
> >
> >
> > Then I get a lot of other errors.
>
> Please some one help me out.
>
> Regards,
> Nishanth.
>

Nishanth, don't take this the wrong way, but this mailing list is not the
best place to ask your question. It seems you're struggling with the very
basics of Java (the classpath specifically). When compiling Java source
files from your command, you either must have all classes your source
file(s) use already in your classpath, or must provide all of them through
the command line parameter when invoking javac. I highly recommend doing
some basic tutorials:
http://java.sun.com/docs/books/tutorial/getStarted/index.html
and/or Google a bit about classpath issues. If you don't get past it, I
suggest you ask your question on a less specific forum (Stackoverflow.com is
hot these days), and post back here if you have specific ANTLR questions.

Best of luck!

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28877] Re: [antlr-interest] Custom lexer and parser constructors

2010-05-18 Thread Bart Kiers
On Tue, May 18, 2010 at 6:04 PM, Cameron Ross  wrote:

> Hi,
>
> Is there a way to define custom constructors for ANTLR lexers and parsers?
>

Sure, you can create custom methods, c-tors and attributes in:

@parser::members {
  // here
}

or

@lexer::members {
  // here
}

Regards,

Bart Kiers.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28890] Re: [antlr-interest] help please

2010-05-18 Thread Bart Kiers
On Wed, May 19, 2010 at 2:10 AM, Ernesto Castillo
wrote:

> hello everybody my name is Ernesto and i am calling for help on antlr
> programming, i am a newby in this and  i am in my second semester  master ,
> after 12 years ago that finish my degree in computer science but because the
> circumstance never work  in the computer  field, but planning to get into,
> so this semester i am taking compiler, and my first  programming assignment
> was really bad because i am not clear how put together the java with the
> antlr. i know how Java work because my first semester i took Java and i used
> it with eclipse . Now i thing i have properly installed the antlr 3.2
> nevertheless  i do not know if i have to install antlrwork because the IDE ,
> i was trying to do the main java with eclipse to invoke antlr but never work
> . so i feel lost in the sea and i have the antlr book but look like is the
> old version. my computer is Mac . i would appreciate the help thanks
>
>
Scott  Stanchfield has written some excellent video tutorials starting from
the very basics (setting up ANTLR with Eclipse). Have a look at them:
http://javadude.com/articles/antlr3xtut/<%20http://javadude.com/articles/antlr3xtut/>

Kind regards,

Bart Kiers.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28951] Re: [antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?

2010-05-22 Thread Bart Kiers
On Sat, May 22, 2010 at 1:33 PM, Sameh W. Zaky  wrote:

> Greetings,
>
> I am still an ANTLR beginner..
>
> I run a software where I generate the .g grammar file automatically. So I
> would love to know how to generate the lexer and parser at runtime given
> the
> .g file?
>

When generating lexers/parser on the command line, you'd do something like
this:

java -cp .:antlr-3.2.jar org.antlr.Tool /path/to/your/grammar.g

(the Tool class has a static main method taking a command line parameter!)
So generating them in your own code would look like:

String yourGrammarFile = "/path/to/your/grammar.g";
org.antlr.Tool.main(new String[]{yourGrammarFile});

Kind regards,

Bart.
**

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 28958] Re: [antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?

2010-05-22 Thread Bart Kiers
>
> But now I need to change my question because I found out that Parser.java
> generated from this action is different than Parser.java generated when I
> click 'Run..' in ANTLRWorks and give it an input text..
>

Please explain what "different" means. And what do you mean by "input text"?


Kind regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29095] Re: [antlr-interest] .* consuming all input

2010-06-03 Thread Bart Kiers
On Thu, Jun 3, 2010 at 11:09 AM, Oliver Zeigermann <
oliver.zeigerm...@gmail.com> wrote:

> Hi, I am pretty sure wildcards are *greedy* by default and ...


+ and * are normally greedy, except when preceded by a DOT. From "the
Definitive ANTLR reference":

*What you really want to type, though, and what you will see in other*

*systems, is the terse notation: ’.*’ and ’.+’. Unfortunately, following the
> *

*usual convention that all subrules are greedy makes this notation useless.*

*Such greedy subrules would match all characters until the end of*

*file. Instead, ANTLR considers them idioms for “Match any symbol until*

*you see what lies beyond the subrule.” ANTLR automatically makes*

*these two subrules nongreedy. So, you can use ’.*’ instead of manually*

*specifying the option.*


See chapter 4, *Extended BNF Subrules*, page 86.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29105] Re: [antlr-interest] Grammar not detecting extraneous input at end

2010-06-03 Thread Bart Kiers
Hi,

On Thu, Jun 3, 2010 at 8:38 PM, Karim Chichakly  wrote:

> Hi,
>
> I have a grammar that does not give an error (in ANTLR 3.2) if there are
> extraneous characters at the end of the input.  For example, I would expect
> "(a+b))" to generate an error, but it does not.  "(a+b)" is parsed fine and
> the extra ")" at the end is just ignored.
>

Since "(a+b))" does not contain any illegal tokens, the parser simply stops
after it (successfully) parses "(a+b)". You'll want to "force" the parser to
go through the entire token stream by adding an 'EOF' after your 'equation'
rule:

equation
  :  expr EOF
  ;


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29107] Re: [antlr-interest] Grammar not detecting extraneous input at end

2010-06-03 Thread Bart Kiers
On Thu, Jun 3, 2010 at 8:46 PM, Kirby Bohling wrote:

> Channeling Jim Idle:
>
> Remember to use antlr.markmail.org, this is a very common question,
> and has been answered many times.
>

True, but I can imagine one would not know what to search for, in this case.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29214] Re: [antlr-interest] [OT]Hello!

2010-06-21 Thread Bart Kiers
On Mon, Jun 21, 2010 at 8:09 AM, Borneq  wrote:

> Is anyone on this mailing list?
>
>

Yes, lots of people.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29296] Re: [antlr-interest] Noob Question

2010-07-02 Thread Bart Kiers
Hi Martin,

On Fri, Jul 2, 2010 at 2:35 PM, Martin Jacobson
wrote:

> I have the following error:
>
> /Users/martin/ANTLR/SVG/PathParser.g:0:0: syntax error: codegen:
> :0:0: unexpected end of subtree
>
> What does this indicate?
>

Not sure. If, after search the below link, you're still stuck, could you
post the grammar?



> Is there a searchable archive I can trawl through?
>

Yes: http://antlr.markmail.org/

Regards,

Bart Kiers.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29442] Re: [antlr-interest] Fwd: Error in ANTLR v2 to v3 converter

2010-07-17 Thread Bart Kiers
On Sat, Jul 17, 2010 at 10:26 PM, Borneq  wrote:

> > When I compile source from v2v3-0.2.tar.gz  I get error, no defined
>
> has anyone such prblem?
>
>
A word of advice: I think most of your questions don't get (m)any responses
because your questions are full of spelling errors and the level of details
you put into your questions is often to cry about: it's like going to the
doctor and the only thing you tell the good (wo)man is that you don't feel
too good. Your problem description "I get error, no defined" is far to
little for anyone to give you a hand. Note that there is no need to write
perfect English, but make an effort: things like 'prblem' is just sheer
laziness. Consider installing an English spell-checker in your web browser,
which spots typo's while you write your message (I couldn't live without
one!).

Best of luck.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29728] Re: [antlr-interest] Filtering Java expressions

2010-08-07 Thread Bart Kiers
Forgot to reply to the entire group...


On Fri, Aug 6, 2010 at 8:03 PM, Bill Andersen  wrote:

>
> Is there a good way to do a partial parse of Java code to pick out
> declarations (or any other structure).  If it helps, I'm limiting this to
> pretty vanilla Java assignment and declaration expressions - no class defs.
>
>

You could create a lexer that parses only those tokens you define by adding:

@options { filter = true; }


at the top of your lexer.

For example, the following lexer:

lexer grammar Foo;

@options { filter = true; }

Int : '0'..'9'+ ;


will only create tokens consisting of one or more digits and will ignore the
rest of the input.

Note that you cannot (!) create a combined grammar (parser & lexer), only a
lexer-grammar.

Good luck!

Regards,
Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 29813] Re: [antlr-interest] Using Own classes to recolect or parse the data withing the grammar

2010-08-11 Thread Bart Kiers
On Thu, Aug 12, 2010 at 7:10 AM, Victor Giordano
wrote:

> ...
>
> The question is: How i can do this, without definig the class inside the
> @menbers section. That class, in fact, is one of my program.. so i only
> want to reuse that. ...
>

Hi Victor,

Define a class LinearExpr like this:

package foo;

public class LinearExpr {

// ... the rest of your class...
}


and in your grammar, import that class like this:

grammar LinearExpression;

@header {
import foo.LinearExpression;
}

// ... the rest of your grammar ...


@header will automatically put everything you define in there at the start
of your parser class. It does the same as:

@parser::header {
import foo.LinearExpression;
}


// ... the rest of your grammar ...


If you want your lexer and parser to be in the same package, say foo.parse for
example, do something like this:

grammar LinearExpression;

@parser::header {
package foo.parse;
import foo.LinearExpression;
}

@lexer::header {
package foo.parse;
import foo.LinearExpression;
}

// ... the rest of your grammar ...


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30135] Re: [antlr-interest] ANTLR first time user getting error

2010-09-11 Thread Bart Kiers
On Sun, Sep 12, 2010 at 1:51 AM, Dibyendu Majumdar
wrote:

> Hi,
>
> I am trying to use ANTLR for the first time, and am getting an error when
> trying to run the grammar shown below; I would be grateful for any help in
> identifying what the issue is.
>
> The test input I am using is:
>
> package test;
>
> I am using the Eclipse ANTLR IDE plugin and when I try to interpret above,
> I
> get:
> MimatchedTokenException: Line 1:7 mismatched input '' expecting '\u0006'
>
>

Here's the same grammar except with a little main method in the parser:

grammar Problematic;

@members {
public static void main(String[] args) throws Exception {
String source = "package test;";
ANTLRStringStream in = new ANTLRStringStream(source);
ProblematicLexer lexer = new ProblematicLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ProblematicParser parser = new ProblematicParser(tokens);
parser.compilationUnit();
}
}

compilationUnit
   :   packageDeclaration
   ;

packageDeclaration
   :   PACKAGE qualifiedName SEMI
   ;

qualifiedName
   :   IDENTIFIER (DOT IDENTIFIER)*
   ;

WS
   :   (' '
   |'\r'
   |'\t'
   |'\u000C'
   |'\n'
   )
   {
   skip();
   }
   ;

PACKAGE
   :   'package'
   ;

SEMI
   :   ';'
   ;

DOT
   :   '.'
   ;

IDENTIFIER
   :   ('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
   ;


and when generating a parser/lexer from the grammar, and running the
parser (under Windows, replace the colons in the commands below by
semi-colons.):

java -cp antlr-3.2.jar org.antlr.Tool Problematic.g
javac -cp .:antlr-3.2.jar *.java
java -cp .:antlr-3.2.jar ProblematicParser


there are no problems whatsoever.
So there must be something wrong with your Eclipse plugin and not with ANTLR
itself.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30232] Re: [antlr-interest] antlr translation doubts

2010-10-01 Thread Bart Kiers
On Fri, Oct 1, 2010 at 7:35 PM, vijay e  wrote:

> Hello
> I am doing  a code translator , where i just need to find certain patterns
> in my C code and change few lines in tht pattern, is there any way where i
> can do this translation without writin my entire C Grammar, because i am
> interested in only very few patterns, so without writin the grammar for
> other patterns , is thr a way to do the translation
>


No, you don't need to write an entire grammar for the C language. You can do
something called "fuzzy parsing" as it's called in 'the Definitive ANTLR
reference'. An example can be found here:

http://stackoverflow.com/questions/2277130/using-antlr-to-parse-a-log-file

Of course you could grab a full C grammar from the ANTLR wiki and adjust it
to your needs.

http://www.antlr.org/grammar/list

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30240] Re: [antlr-interest] antlr translation doubts

2010-10-02 Thread Bart Kiers
On Fri, Oct 1, 2010 at 7:51 PM, vijay e  wrote:

> Thanks for ur reply,
> Ya i followed ur idea, but the problem i am getting in using filter is ,
> when i set the filter as true, my common token stream contains only the
> tokens of my interst, , i can do all modifications in those tokens only
> ,but, how can i make those token changes reflect in my original file with
> all the other non intersted tokens untouched


Every CommonToken has the following methods:

int getLine ()
int getCharPositionInLine ()


which should give you enough information to modify the original source file.

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30345] Re: [antlr-interest] cretae the inverse of a rule

2010-10-15 Thread Bart Kiers
On Fri, Oct 15, 2010 at 3:39 PM, Remi Marechal wrote:

> if i create a rule like
>
> LETTER: 'a'..'z' ;


With the '~' (tilde):

NON_LETTER
  :  ~LETTER
  ;

Note that the negation only works on single characters (or lexer rules that
match a single character). For example, you can't negate the rule:

FOO
  :  'foo'
  ;

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30355] Re: [antlr-interest] Tree grammar: How to handle rule arguments

2010-10-15 Thread Bart Kiers
On Sat, Oct 16, 2010 at 1:16 AM, Stephanie Balzer <
stephanie.bal...@gmail.com> wrote:

>
> ... What is the meaning of id+= above?
>
>
A java.util.List is defined at the start of the rule and
all Identifier-tokens are added to it.

Token id=null;
List list_id=null; *// <- !!!*

try {
// Test.g:17:3: (id+= Identifier ( ',' id+= Identifier )* )
// Test.g:17:6: id+= Identifier ( ',' id+= Identifier )*
{
id=(Token)match(input,Identifier,FOLLOW_Identifier_in_ids80);
if (list_id==null) list_id=new ArrayList();  *// <- !!!*
list_id.add(id);  *// <- !!!*
...

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30388] Re: [antlr-interest] Very high runtime and memory usage caused by trivial grammar => Is it my mistake?

2010-10-21 Thread Bart Kiers
On Thu, Oct 21, 2010 at 9:13 AM, Cremerius Ralf (DGS-EC/ECC3) <
ralf.cremer...@de.bosch.com> wrote:

> ...
>
> SOMETOKEN
>:   ('a')*;
>
> ...
>
> public static void main(String[] args) throws Exception
> {
>ANTLRStringStream   input   = new ANTLRStringStream("<");
>problemLexerlexer   = new problemLexer(input);
>CommonTokenStream   tokens  = new CommonTokenStream(lexer);
>problemParser   parser  = new problemParser(tokens);
>parser.main_rule();
> }
>
>
> 
>
> => Did I make some beginner's error and I'm just not able to see it?
>
>
The rule:

SOMETOKEN
  :  ('a')*
  ;



matches empty strings, and there are an infinite amount of them before your
input "<". This is probably the cause of the behavior you're
witnessing. Change it into 'a'+ and see if things run differently.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30390] Re: [antlr-interest] Very high runtime and memory usage caused by trivial grammar => Is it my mistake?

2010-10-21 Thread Bart Kiers
Hi Ralf,


>"line 1:0 required (...)+ loop did not match anything at character
> '<'"
>
> Up to this point I thought, I got it. I assume, that the above output line
> is generated by the lexer. I defined only one lexer token in my grammar,
> which is wouldn't match an empty string anymore. So why doesn't the lexer
> stop after unsuccessfully trying to match the string - and runs on instead?


No, the error comes from the parser. Try creating a lexer only and you'll
see no error is printed to the console.

If you want the lexer to produce an error/exception for invalid tokens, see:

*How can I make the lexer exit upon first lexical error?*
http://www.antlr.org/wiki/pages/viewpage.action?pageId=5341217

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30778] Re: [antlr-interest] jar file changes in version 3.3?

2010-12-05 Thread Bart Kiers
Hi,

On Sun, Dec 5, 2010 at 10:14 AM, Chao Wang  wrote:

> only an antlr-3.3-complete.jar file in the lib folder. The compiling failed
> with only this file in classpath.
>

Can you post the stack trace? Can you post the grammar (assuming things go
wrong when generating a lexer/parser...)?

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30779] Re: [antlr-interest] jar file changes in version 3.3?

2010-12-05 Thread Bart Kiers
On Sun, Dec 5, 2010 at 11:21 AM, Chao Wang  wrote:

> here is the stack trace:
>
> localhost:output mac$ javac TLexer.java  TParser.java  Test.java
> Test.java:8: cannot find symbol
> symbol  : constructor ANTLRFileStream(java.io.InputStream)
> location: class org.antlr.runtime.ANTLRFileStream
> TLexer lex = new TLexer(new ANTLRFileStream(System.in));
> ^
> Test.java:11: cannot find symbol
> symbol  : constructor
> TParser(org.antlr.runtime.CommonTokenStream,int,)
> location: class TParser
> TParser g = new TParser(tokens, 49100, null);
> ^
> 2 errors
>
>
The compiler can't find the .class file for the ANTLR runtime. Try:

$ java -cp antlr-3.2.jar org.antlr.Tool T.g
$ javac -cp antlr-3.2.jar *.java
$ java -cp .:antlr-3.2.jar Main


instead.

I tested it with ANTLR 3.2 (the site is down so couldn't download 3.3) with
the following class:

import org.antlr.runtime.*;

public class Main {
public static void main(String[] args) throws Exception {
ANTLRStringStream in = new ANTLRStringStream("call f;");
TLexer lexer = new TLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TParser parser = new TParser(tokens);
parser.r();
}
}


Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 30928] Re: [antlr-interest] How work wih C# target?

2010-12-21 Thread Bart Kiers
On Tue, Dec 21, 2010 at 3:05 PM, Andrzej  wrote:

> I know that in .g must be:
> options {
>language=CSharp2;
> }
>
>  From where I can download C# runtime to compile cs files?
>
>
The ones from:

http://www.antlr.org/download/CSharp

<http://www.antlr.org/download/CSharp>work with CSharp2.

Regards,

Bart Kiers.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31139] Re: [antlr-interest] Protocol message recognition - an amateur grammar question

2011-01-12 Thread Bart Kiers
On Wed, Jan 12, 2011 at 5:02 PM, Alex Lujan  wrote:

> I am trying Antlr v3 for message recognition, which must comply to a custom
> define protocol.
>
> I find myself unable to express the following rule (written in a
> non-standard notation):
>
> data: count number{count.value}
>
> What I am expecting to find in the input is a numerical value (which Ive
> labeled count), followed by as many numerical values as the value of count.
>
> Examples of valid input:
>
> 3 10 12 15
> 2 6 9
>
> Examples of invalid input:
>
> 3 10 12
> 2 4 5 6
>
>
You could use a 'validating semantic predicate'. A small demo:

*grammar Test;*
*
*
*parse*
*  :  line+ EOF*
*  ;*
*
*
*line*
*  :  n=number {int c = $n.value;} (number {--c;})* {c==0}? LineBreak*
*  ;*
*
*
*number returns [int value]*
*  :  Int {$value = Integer.parseInt($Int.text);}*
*  ;*
**
*Int*
*  :  '0'..'9'+ *
*  ;*
*
*
*LineBreak*
*  :  '\r'? '\n'*
*  |  '\r'*
*  ;*
**
*Space*
*  :  (' ' | '\t') {skip();}*
*  ;*



Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31141] Re: [antlr-interest] Protocol message recognition - an amateur grammar question

2011-01-12 Thread Bart Kiers
On Wed, Jan 12, 2011 at 6:17 PM, Alex Lujan  wrote:

> Hi Bart,
>
> Thank you for your response.
>
> Will the validating semantic predicate verify the amount of matches after
> the first number, or will it instruct the parser to stop consuming tokens
> after the Nth occurrence? The second option is what I need.
>
> I provided a bit more context in a previous email, in answer to Michael's
> proposal. The short version is:
>
> The protocol is more complex, and the sequence can be followed by more
> data.
>
> Using the same non-standard notation, as I dont know a proper way to
> express this:
>
> protocol: data+
>
> data: count number{count.value}
>
> Therefore, the following sequence needs to be valid:
>
> *3* 10 12 15 *2* 4 5
>
> I need to instruct the parser to only match 3 numeric values after matching
> the 3, and so on.
>
> From implementing your proposal, Bart, it seems it does not achieve what I
> am looking for (again, my bad for not giving enough context at the
> beginning)
>
> Cheers!


In that case, using a "gated semantic predicate" before the "validating
predicate" is more appropriate:

*grammar Test;*
*
*
*parse*
*  :  line+ EOF*
*  ;*
*
*
*line*
*  :  n=number {int c = $n.value;} ({c > 0}?=> number {--c;})* {c == 0}?*
*  ;*
*
*
*number returns [int value]*
*  :  Int {$value = Integer.parseInt($Int.text);}*
*  ;*
**
*Int*
*  :  '0'..'9'+ *
*  ;*
**
*Space*
*  :  (' ' | '\t' | '\r' | '\n') {skip();}*
*  ;*


Tested with the following class:

*import org.antlr.runtime.*;*
*
*
*public class Main {*
*public static void main(String[] args) throws Exception {*
*ANTLRStringStream in = new ANTLRStringStream(*
*"3 10 12 15\n" +*
*"2 6 9 3 1 1 111 \n"*
*);*
*TestLexer lexer = new TestLexer(in);*
*CommonTokenStream tokens = new CommonTokenStream(lexer);*
*TestParser parser = new TestParser(tokens);*
*parser.parse();*
*}*
*}*


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31170] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers
On Sat, Jan 15, 2011 at 11:43 AM, fikin  wrote:

> most likely this is obviously stupid question, pardon me in advance please.
>
> what exactly is wrong with this grammar?
>
> lines   :   line (NEWLINE line)*;
> line:   '\u0020'..'\u007F'*;
> NEWLINE :   '\r'? '\n';
>

The range operator works differently inside a parser-rule.
For example, the rule *foo*:

foo
  :  A..C
  ;

A : 'a';
Z : 'z';
C : 'c';


will match one of the tokens A, Z or C (not one of the characters 'a', 'b'
or 'c'!).

Just as the `.` (DOT meta character) that has a different meaning depending
in which rule it is used: it means 'any character' inside lexer rules, while
it means 'any token' inside parser rules.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31172] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers
>
> i also noticed that following works just fine:
> lines   :   line (NEWLINE line)*;
> line:   CHAR*;
> NEWLINE :   '\r'? '\n';
> CHAR:   '\u0020'..'\u007F';


Yes, because you are now using the range operator inside a lexer rule (I
presume you know the difference between parser- and lexer rules?).



> is there a way i can make a rule token is a sequence of values as
> opposing a sequence of tokens?
>

I don't know what you mean by that.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31173] Re: [antlr-interest] a range as single token?

2011-01-15 Thread Bart Kiers
On Sat, Jan 15, 2011 at 1:23 PM, fikin  wrote:

> right. is there a way to make the lexer provide "line" content as
> single token as opposing to a container of "char" tokens?
>

Sure, like this:

lines   :   CHARS (NEWLINE CHARS)*;
NEWLINE :   '\r'? '\n';
CHARS   :   '\u0020'..'\u007F'+;


And if there can be empty lines, do:

lines   :   CHARS? (NEWLINE CHARS?)*;


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31189] Re: [antlr-interest] Strangeness when parsing strings and spaces

2011-01-17 Thread Bart Kiers
On Tue, Jan 18, 2011 at 7:41 AM, Kevin Jackson  wrote:

> Hi,
>
> I know that this is a problem with my lexer and I'm doing something
> stupid, but I have a problem with simple k,v pairs of the format:
>
> [String "quoted string with spaces and non-alhpa chars"]
>
> My grammar
> --
>
> LEFT_SQUARE: '[';
> RIGHT_SQUARE: ']';
> STRING: 'a'..'z'|'A'..'Z';
> TEXT: ('a'..z'|'A'..'Z'|' '|',')+
>
>
Your STRING and TEXT have too much in common. Better let TEXT also include
the double quotes. Also, you could just skip the spaces outside you quoted
text and your STRING rule only matches a single character, which is probably
a mistake.

Try something like:

pair
  :  LEFT_SQUARE IDENTIFIER QUOTED_TEXT RIGHT_SQUARE
  ;

LEFT_SQUARE  : '[';
RIGHT_SQUARE : ']';
IDENTIFIER   : ('a'..'z'|'A'..'Z')+;
QUOTED_TEXT  : '"' ('a'..'z' | 'A'..'Z' | ' ' | ',' | '-')+ '"';
SPACES   : (' ' | '\t')+ {skip();};


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31191] Re: [antlr-interest] Strangeness when parsing strings and spaces

2011-01-17 Thread Bart Kiers
On Tue, Jan 18, 2011 at 8:28 AM, Kevin Jackson  wrote:

> Hi,
>
> > pair
> >   :  LEFT_SQUARE IDENTIFIER QUOTED_TEXT RIGHT_SQUARE
> >   ;
> >
> > LEFT_SQUARE  : '[';
> > RIGHT_SQUARE : ']';
> > IDENTIFIER   : ('a'..'z'|'A'..'Z')+;
> > QUOTED_TEXT  : '"' ('a'..'z' | 'A'..'Z' | ' ' | ',' | '-')+ '"';
> > SPACES   : (' ' | '\t')+ {skip();};
>
> Thanks for the reply.  This nearly works!  However I don't want to
> retain the '"' (quotes) in the rewrite rule, so although the
> IDENTIFIER has fixed the first problem, I now have a problem with the
> QUOTED_TEXT.
>
> I should have mentioned that I suppose.
>
> Thanks,
> Kev
>

Try something like this:

QUOTED_TEXT
  :  '"' ('a'..'z' | 'A'..'Z' | ' ' | ',' | '-')+ '"'
{setText(getText().substring(0, getText().length()-1));}
  ;


to strip the quotes in the lexing-stage.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31193] Re: [antlr-interest] Strangeness when parsing strings and spaces

2011-01-17 Thread Bart Kiers
>
> A further question which I cannot find the answer too:
>
> What is the difference between 'a'..'z'+ and ('a'..'z')+ ??
>

In ANTLR v3.x, there is no difference (I seem to recall that in v2 of ANTLR,
the parenthesis were mandatory, in this case).

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31241] Re: [antlr-interest] org.antlr.runtime.CommonToken cannot be cast to org.antlr.runtime.tree.Tree

2011-01-26 Thread Bart Kiers
On Wed, Jan 26, 2011 at 10:40 PM, Ching  wrote:

> Can anyone tell me why I got this exception? My output is AST. Thanks.
>
>
Err, that error is pretty self-explanatory: you're trying to cast
a org.antlr.runtime.CommonToken to a org.antlr.runtime.tree.Tree, which is
illegal. As you can see from ANTLR's class hierarchy:
http://www.antlr.org/api/Java/hierarchy.html
the two can't be cast (either CommonToken->Tree or Tree->CommonToken).

Perhaps you don't understand where this happens in your grammar? In that
case, please show your grammar as well.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31371] Re: [antlr-interest] Partial grammar for class counting

2011-02-06 Thread Bart Kiers
>
> Il 06/02/2011 17:04, Pavel Martynov ha scritto:
> > Hi!
> > 
> > with best regards, Pavel Martynov
> >
>

Answered here:
http://stackoverflow.com/questions/4914073/partial-grammar-for-counting-class-count/4914224#4914224
as
well.


HTH,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31387] Re: [antlr-interest] Unicode input

2011-02-08 Thread Bart Kiers
Hi,

On Tue, Feb 8, 2011 at 11:18 PM, Alex Lujan  wrote:

> Im having an issue with parsing an input that contains unicode characters.
>
> This is the code Im using to test the parser (messageBytes is an array
> created by reading bytes from a binary file):
>
> private static void parseMessage(byte[] messageBytes) throws IOException{
>
>ByteArrayInputStream input = new ByteArrayInputStream(messageBytes);
>ANTLRInputStream in = new ANTLRInputStream(input);
>  ...


You'll probably want to set the *encoding* of the input using:

ANTLRInputStream
 (InputStream input, String encoding)


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31402] Re: [antlr-interest] Ident with ending In or Out word

2011-02-10 Thread Bart Kiers
On Thu, Feb 10, 2011 at 6:08 PM, Roohul  wrote:

> Hi,
>
> I am working on a grammar which have some variables ending with In or Out
> which is treated as the connector between two components. I do not know how
> to handle this.
>
> For example:
> real abcIn
> real abcOut
>
> these are treated as connectors. while abcI or abcOu will be treated as
> normal variables.
>

You could handle this on a "lexer level" like this:

REAL
  :  'real'
  ;

CONNECTOR
  :  Alpha+ ('In' | 'Out')
  ;

VARIABLE
  :  Alpha+
  ;

fragment
Alpha
  :  'a'..'z'
  |  'A'..'Z'
  ;


(the order of the rules is important here!)

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31408] Re: [antlr-interest] Ident with ending In or Out word

2011-02-11 Thread Bart Kiers
On Fri, Feb 11, 2011 at 2:27 PM, Roohul  wrote:

> Hi,
> This is my sample grammar.. this did not work.. another thing is that my
> variables and connectors both can have digits so I created Alpha : LETTER
> (LETTER | DIGIT)*; for this but it also give an error.
>
>
The problem descriptions *"did not work"* and *"also give an error"* do not
tell much. Care to elaborate?

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31417] Re: [antlr-interest] [SPAM] [SPAM] Re: [SPAM] [SPAM] Optional expression rule alternative

2011-02-11 Thread Bart Kiers
On Fri, Feb 11, 2011 at 7:04 PM, Olivier Lefevre  wrote:

> Great! Not to abuse but would you know in which section of
> "The Definitive ANTLR Reference" this mentioned? I couldn't
> find it. What is this syntax called?
>

It's called a "validating semantic predicate" which is explained in chapter
12 and 13.


But in my real-world problem it was actually not a choice
> between rule1 and rule2 but a question of whether to allow
> an extra alternative in the z case without too much
> verbatim repetition, i.e. (again in pseudo-code):
>
> rule[boolean z] :
>   rule1 | rule2 | ... | rule23 | (z ? rule24 : nothing) ;
>
> That is, allow rule24 if z otherwise stop at rule23.


You can still do that:

rule [boolean z]
  :  {z}? (rule1 | rule2 | rule3 | ... | rule23 | rule24)
  |   (rule1 | rule2 | rule3 | ... | rule23)
  ;


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31430] Re: [antlr-interest] Getting the wrong token during lexing with Antlr 3.3

2011-02-12 Thread Bart Kiers
On Sat, Feb 12, 2011 at 7:33 PM, Bernardo Elayda  wrote:

> Hi,
>
>
Hi, could you attach your entire grammar? Or at least the lexer-grammar of
lexer rules?

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31448] Re: [antlr-interest] Own Tree Class

2011-02-14 Thread Bart Kiers
On Mon, Feb 14, 2011 at 6:50 PM, Filip Habr  wrote:

> Hello, can you help me somebody? I wrote ExpressionParser in ANTLR, which
> parse
> math expression to a tree. I was using CommonTree class as a target. Now I
> need
> to create my own tree class, because I have to create additional methods.
> Is
> there any way to create own tree class, which could be used by ANTLR
> grammar as
> a target tree class.
>
> options {
>language=CSharp2;
>output=AST;
>ASTLabelType=MY_OWN_CLASS;
>}
>
> Best help for me would be an advice, how to write class like CommonTree,
> because
> the code of CommonTree methods is not visible of course. Every class, i
> have
> written doesn't work. Thanks a lot




On Mon, Feb 14, 2011 at 6:50 PM, Filip Habr  wrote:

> Hello, can you help me somebody? I wrote ExpressionParser in ANTLR, which
> parse
> math expression to a tree. I was using CommonTree class as a target. Now I
> need
> to create my own tree class, because I have to create additional methods.
> Is
> there any way to create own tree class, which could be used by ANTLR
> grammar as
> a target tree class.
>
> options {
>language=CSharp2;
>output=AST;
>ASTLabelType=MY_OWN_CLASS;
>}
>
> Best help for me would be an advice, how to write class like CommonTree,
> because
> the code of CommonTree methods is not visible of course. Every class, i
> have
> written doesn't work. Thanks a lot
>
>

Besides writing your own CommonTree subclass and adding `` to your
`options{...}` section, you should write your own CommonTreeAdaptor that
actually creates instances of your custom tree(s).

A little demo. Specifically note the lines that have `// !!!` after them:

// file://BooleExp.g
grammar BoolExp;

options {
  output=AST;
  ASTLabelType=BoolExpTree;   // !!!
}

parse
  :  exp EOF -> exp
  ;

exp
  :  orExp
  ;

orExp
  :  andExp (Or^ andExp)*
  ;

andExp
  :  atom (And^ atom)*
  ;

atom
  :  '(' exp ')' -> exp
  |  True
  |  False
  ;

Or: 'OR' | '||';
And   : 'AND' | '&&';
True  : 'true';
False : 'false';
Space : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;};

// file://Main.java
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;

public class Main {

private static void walk(BoolExpTree tree, int depth) {
if(tree == null) {
return;
}
for(int i = 0; i < depth; i++) {
System.out.print(". ");
}
System.out.println(tree);
walk(tree.left(), depth + 1);
walk(tree.right(), depth + 1);
}

public static void main(String[] args) throws Exception {
ANTLRStringStream in = new ANTLRStringStream("true AND (false ||
true && (true OR false))");
BoolExpLexer lexer = new BoolExpLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
BoolExpParser parser = new BoolExpParser(tokens);
parser.setTreeAdaptor(new BoolExpTreeAdaptor());
  // !!!
BoolExpParser.parse_return returnValue = parser.parse();
CommonTree tree = (BoolExpTree)returnValue.getTree();
walk((BoolExpTree)tree, 0);
}
}

class BoolExpTree extends CommonTree {

public BoolExpTree(Token token) {
super(token);
}

public BoolExpTree left() {
return super.getChildCount() > 0 ? (BoolExpTree)super.getChild(0) :
null;
}

public BoolExpTree right() {
return super.getChildCount() > 1 ? (BoolExpTree)super.getChild(1) :
null;
}

@Override
public String toString() {
return "BoolExpTree[" + super.toString() + "]";
}
}

class BoolExpTreeAdaptor extends CommonTreeAdaptor {

@Override
public Object create(Token token) {
return new BoolExpTree(token);
}
}


When generating a lexer/parser, compiling all .java source files, and
running the main class:

java -cp antlr-3.2.jar org.antlr.Tool BoolExp.g
javac -cp .:antlr-3.2.jar *.java
java -cp .:antlr-3.2.jar Main


you will see the following output:

BoolExpTree[AND]
. BoolExpTree[true]
. BoolExpTree[||]
. . BoolExpTree[false]
. . BoolExpTree[&&]
. . . BoolExpTree[true]
. . . BoolExpTree[OR]
. . . . BoolExpTree[true]
. . . . BoolExpTree[false]


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31476] Re: [antlr-interest] [begginer question] could somebody help me to see this simple grammar?

2011-02-16 Thread Bart Kiers
On Wed, Feb 16, 2011 at 9:18 AM, devdoer bird  wrote:

> ...
> As you see, the last ')'  is missed.
> So what's wrong with my grammar?
>

Nothing.

Given your grammar (and adding a `parse` rule to it):

grammar T;

parse
  :  logicExp EOF {System.out.println("parsed :: " + $logicExp.text);}
  ;

logicExp
  :  FIELDNAME ( '>' | '<' ) (CONST_INT | CONST_STRING)
  | '(' logicExp')'
  ;

fragment DIGIT : '0'..'9';
fragment LOWER  : 'a'..'z';
fragment UPPER  : 'A'..'Z';
FIELDNAME : LOWER (LOWER|DIGIT)*  ;
CONST_INT : DIGIT+;
CONST_STRING : '"' (LOWER|UPPER|DIGIT)* '"';


and creating the test class:

import org.antlr.runtime.*;

public class Main {
public static void main(String[] args) throws Exception {
ANTLRStringStream in = new ANTLRStringStream("(a>3)");
TLexer lexer = new TLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TParser parser = new TParser(tokens);
parser.parse();
}
}


I generated a lexer & parser, compiled all .java files and ran the main
class:

java -cp antlr-3.2.jar org.antlr.Tool T.g
javac -cp antlr-3.2.jar *.java
java -cp .:antlr-3.2.jar Main


which produced the output:

parsed :: (a>3)


So, if ANTLRWorks produces something different, there's something wrong with
it.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31613] Re: [antlr-interest] Antlr newbie trying to make Sloc counter with antlr

2011-02-25 Thread Bart Kiers
Hi Troy,

On Fri, Feb 25, 2011 at 4:36 PM, tjtaill36  wrote:

> Bart,
>
> Thanks for answering a sloc is a logical line of code in a c base language
> that is pretty much the number of non commented semi colons.
>
>
Ah, I see.



> this is my test code and it says there is 0 slocs when it should answer two
>
> package code.metrics;
>
> import java.io.IOException;
>
> import org.antlr.runtime.ANTLRStringStream;
> import org.antlr.runtime.CommonTokenStream;
> import org.antlr.runtime.RecognitionException;
>
>
> public class CountSlocs {
> public static void main(String[] args) throws IOException,
> RecognitionException {
>
> StringBuilder file = new StringBuilder();
> file.append("package code.metrics;\n");
> file.append("/* ml comment */\n");
> file.append("class Whatever {\n");
> file.append("\tpublic static void main(String[] args){\n");
> file.append("\t\tSystem.out.println(\"Hello World!\");\n");
> file.append("\t}\n");
> file.append("}\n");
>
> ANTLRStringStream in = new ANTLRStringStream(file.toString());
> Slocs lexer = new Slocs(in);
>
> CommonTokenStream tokens = new CommonTokenStream(lexer);
>
> tokens.getTokens();
>
> System.out.println(lexer.slocs);
> }
>
> }
>
> Troy


When I run your code, I get this:

$ java -cp antlr-3.2.jar org.antlr.Tool Slocs.g
$ javac -cp antlr-3.2.jar *.java
$ java -cp .:antlr-3.2.jar CountSlocs
2


which is the expected output...

Note that since you're using the `filter=true` option, you don't need to
account for anything except those token you're interested in. So all the
`.*` stuff can be omitted. The following grammar also produces "2" being
printed to the console:

lexer grammar Slocs;

// options

// members

COMMENT
  :  '/*' .* '*/'
  |  '//' ~('\r' | '\n')*
  ;

// string and char-literals here

SLOC
  :  ';' {slocs++;}
  ;



Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31710] Re: [antlr-interest] How to get the complete syntax tree

2011-03-03 Thread Bart Kiers
Hi,

2011/3/3 Juan Manuel Cámara 

> ...
> The Parser works fine, but its return is a flat tree, all tokens are childs
> of the root.
>
> Is this the normal use?
> Can someone guess what I'm doing wrong, or tell me the way to get the
> complete tree? ...
>

_You_ need to tell how the tree looks like.

See: http://www.antlr.org/wiki/display/ANTLR3/Tree+construction
And/or:
http://stackoverflow.com/questions/4931346/how-to-output-the-ast-built-using-antlr


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31722] Re: [antlr-interest] Tree grammar for expression subrules?

2011-03-04 Thread Bart Kiers
On Fri, Mar 4, 2011 at 6:53 PM, g...@novadsp.com  wrote:

> Is there a pattern to follow for creating tree grammars for subrules?
>
> // parser rule. this works.
> expression
> : (a=term -> $a) ( ( '|' b=term -> ^(OR $expression $b)
>| '|'-> ^(OR $expression EPSILON)
>)
>  )*
> ;
>


I'd expect that to become the tree-grammar rule:

expression
  :  term
  |  ^(OR expression term)
  |  ^(OR expression EPSILON)
  ;



instead of:


>
> // tree grammar 1, based on CMinus example in the book.Throws a
> MismatchedTreeNodeException complaining about lack of
> // 'UP' at SEQUENCE_EXPR
> expression
> : IF_ACTION
> | ID
> | ID ATTRIBUTES
> | STRINGLITERAL
> | EPSILON
> | ^(GROUPED_EXPR expression)
> | ^(OPTIONAL_EXPR expression)
> | ^(SEQUENCE_EXPR expression)
> ;
>
>
Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31735] Re: [antlr-interest] Tree grammar for expression subrules?

2011-03-05 Thread Bart Kiers
On Fri, Mar 4, 2011 at 11:23 PM, g...@novadsp.com  wrote:

>
> On 04/03/2011 19:13, Bart Kiers wrote:
>
>  I'd expect that to become the tree-grammar rule:
>>>
>>>expression
>>>   :  term
>>>   |  ^(OR expression term)
>>>   |  ^(OR expression EPSILON)
>>>   ;
>>>
>>
> Hello Bart
>
> Once again, extremely useful input. Thanks. My question though still
> stands. Cannot discern any pattern in writing the tree rules as, for
> example, this seems to violate cardinality ... or does it?
>
>
>
Hi, I'm starting to hesitate. Could you send your combined- or
parser-grammar that produces the AST? I'll have a look at it to see if I can
create a tree grammar (with a bit of comments).

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31764] Re: [antlr-interest] Tree Pattern Matching with Rewrite Rules

2011-03-08 Thread Bart Kiers
On Tue, Mar 8, 2011 at 6:36 PM, Matt Fowles  wrote:

> All~
>
> I have a trivial antlr grammar for expressions like `a.b.c + d.e.f`
> (Test.g).  Now I want to define a pattern matcher over this grammar
> that turns `a.b.c` into `0.1.2`, so I define a Tree Pattern Matcher
> (TestWalker.g) and put together a small test program (Main.java).
>
> When I run this program with basic input, I see surprising results:
> `a.b.c` -> `0.b.c`
> `a.b + d.e` -> `0.b + 0.e`
> and so on.
> ...


FYI:
http://stackoverflow.com/questions/5236089/antlr-tree-pattern-matching-with-rewrite-rules/5237962#5237962

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31800] Re: [antlr-interest] #include mechanism for grammar files?

2011-03-13 Thread Bart Kiers
Hi Jerry,.

On Sun, Mar 13, 2011 at 3:33 PM, g...@novadsp.com  wrote:

> Sorry! Must remember  to post plain-text only.
>
> It would be useful to be able to #include a file in a grammar. use case:
> grammar is generated by another tool but the lexer definitions are not.
>
> i.e.
>
> grammar auto
> ...
>
> #include auto_lexer.g
>
> Is there a way to do this with the grammar spread over 2 files?
>

Yes, in ANTLR this is called "composite grammars".
Have a look at: http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31846] Re: [antlr-interest] problem with characters in grammar

2011-03-19 Thread Bart Kiers
On Sat, Mar 19, 2011 at 8:14 PM, Wojciech Tomasz Cichon <
wtcic...@googlemail.com> wrote:

> i decided to extend my grammar for characters
> and i added:
>
> factor  :  '-'? (NUMBER )
>| character
>   ;
> character : AP (LETTER | NUMBER) AP;
> AP : '\'';
> LETTER :  'A'..'Z' | 'a'..'Z';
>

There's a capital Z after the `a`..

Try a lower case.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31944] Re: [antlr-interest] problems getting a simple grammar to accept it's input

2011-03-24 Thread Bart Kiers
On Thu, Mar 24, 2011 at 4:08 PM, Florian Franzmann <
siflf...@hawo.stw.uni-erlangen.de> wrote:

> ...
> As I understand it the parser consumes 'Model' as IDENTIFIER and goes into
> state block. It ignores a WS, then finds a '{'. This should be recognized
> as
> BLOCK_BEGIN, which is the next token expected in block---any idea what I'm
> doing wrong?
>
> best regards
> Florian Franzmann
>
>
Fragment rules can only be "seen" by other lexer rules. There will never be
a token `BLOCK_BEGIN ` created, so it can't be used inside parser rules.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 31988] Re: [antlr-interest] NPE at DefineGrammarItemsWalker.java:94

2011-03-28 Thread Bart Kiers
On Mon, Mar 28, 2011 at 5:58 PM, J. Talafous  wrote:

> Why am I getting an NPE on the following test grammar?  Thanks.
> I am having a hard time getting the @header into my grammar without
> getting a NPE error.  What am I doing wrong?  Thanks for the help.
>
>
For ANTLR 3.x, the following order should be held:

grammar GrammarName;

options { ... }

tokens { ... }

@header { ... }

@members { ... }

parser/lexer rules ...


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32031] Re: [antlr-interest] Fwd: F77 grammar

2011-03-31 Thread Bart Kiers
On Thu, Mar 31, 2011 at 9:24 AM,  wrote:

> Hi,
>
>   I have problem with running this grammar (downloaded from ANTLR website).
> Someone familiar with it?
>
>
I'm not, but the first line of the grammar says: *"Fortran 77 grammar for
ANTLR 2.7.5". *So, my question to you is: are you uainf ANTLR v2.7? ANTLR
3.x will not cope with the syntax from that grammar. If you *are* using
version 2.7, I suggest you explain your actual problem.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32091] Re: [antlr-interest] Grammar not detecting stray syntax after certain valid blocks

2011-04-05 Thread Bart Kiers
>
> This is enough to demonstrate the problem. When I create a program such as:
>
> state hello
> {
>
> }
> }
>
> The trailing close bracket is not detected as an error.
> 


Try to "anchor" it by adding an EOF at the end of your entry-rule:

public prog
  :  globalStmt+ EOF
  ;


That way, you force the parser to go through the entire token stream, and
not stop prematurely.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32151] Re: [antlr-interest] Interactive processing of input

2011-04-11 Thread Bart Kiers
On Mon, Apr 11, 2011 at 8:49 AM, NeoPhyte <20neophyt...@gmail.com> wrote:

> Does ANTLR give me an option for interactive processing of input.  ie
> Processing every line of input one by one
> >From whatever I know till now, it starts processing after it encounters an
> EOF.
> Is there some way I can make it process my input by some other means, say
> when it reads a "enter" etc.


The parser can only get started after it receives the input, so the answer
is no: you can't let the parser "do things" if only part of the tokens are
known.

Why not line simply create a new lexer/parser for each line and process the
input (and evaluate it).

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32157] Re: [antlr-interest] Need pointers for getting comment statements in trees produced by v3 grammer files

2011-04-11 Thread Bart Kiers
On Mon, Apr 11, 2011 at 6:31 PM, The Researcher wrote:

> > Hi Ankit,
>
>
> If I understand the question correctly,
> then have you tried removing {$channel=HIDDEN;} from the lexer rule?
>
> i.e.
> LINE_COMMENT
>   :   '//' ~('\n' | '\r')* '\r'? '\n' {$channel=HIDDEN;}
>   ;
>
> should be
>
>  LINE_COMMENT
>   :   '//' ~('\n' | '\r')* '\r'? '\n'
>   ;
>
> Eric
> 
>

But then (one of) the parser rules should also include this LINE_COMMENT
somewhere, of course.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32158] Re: [antlr-interest] Interactive processing of input

2011-04-11 Thread Bart Kiers
On Mon, Apr 11, 2011 at 11:19 AM, NeoPhyte <20neophyt...@gmail.com> wrote:

> Will this method allow me to process each line in an input file
> individually.
> Like if my grammar has multiple rules and I want to process each of these
> rules individually
> Something like...
>
> say my grammar has following 3 individual parser rules
>
> rule1 : 
> rule2 : 
> rule3: ...
>
> final : (rule1|rule2|rule3)+;
>
> //rest of the lexer and parser rules
>
> and my i/o is
>
> read input for rule1
> show output for rule1
>
> read input for rule3
> show output for rule3
>
> read input for rule1
> show output for rule1
>
> an so on, until I use something like an EOF(ctrl-z)
>
> with the method suggested by you, can I achieve this?...and if so can u plz
> provide a sample code for the same



Hmm, I really don't know what you mean...

As long as you invoke the `final` method on your parser (which matches one
of: `rule1`, `rule2` or `rule3`), you're okay, AFAIK.

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32209] Re: [antlr-interest] v2->v3 Skip chars in Lexer?

2011-04-16 Thread Bart Kiers
On Sat, Apr 16, 2011 at 12:06 PM, Ruslan Zasukhin <
ruslan_zasuk...@valentina-db.com> wrote:

> ...
>
> How to remove that quotes in v3?  :-)
>
>
Here's a way:

DELIMITED
  @init {
String q = null;
  }
  @after {
String text = getText();
// remove the first and last quote, replace all 2 quotes with a single
quote
setText(text.substring(1, text.length()-1).replace(q+q, q));
  }
  :  ( DQUOTE (~DQUOTE | DQUOTE DQUOTE)+ DQUOTE {q = $DQUOTE.text;}
 | BQUOTE (~BQUOTE | BQUOTE BQUOTE)+ BQUOTE {q = $BQUOTE.text;}
 ) { $type = IDENT; }
  ;


or create your own token that handles the replacements internally:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1844

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



[il-antlr-interest: 32357] Re: [antlr-interest] Lexer too quick to grab a token?

2011-05-02 Thread Bart Kiers
On Mon, May 2, 2011 at 1:19 AM, Todd O'Bryan  wrote:

> ...
>
>
> Does this make any sense? Is there some way to deal with it?
>  ...


You could let '/]]' be matched in the 'R_TAG' rule and emit another token as
per the instructions described here:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=3604497

A demo:

lexer grammar TLexer;

@members {

  List tokens = new ArrayList();

  private void emit(String text, int type) {
Token token = new CommonToken(type, text);
token.setType(type);
emit(token);
  }

  @Override
  public void emit(Token token) {
state.token = token;
tokens.add(token);
  }

  @Override
  public Token nextToken() {
super.nextToken();
if(tokens.size() == 0) {
  return Token.EOF_TOKEN;
}
return (Token)tokens.remove(0);
  }
}

L_TAG
  :  '[/'
  ;

R_TAG
  :  '/]]' {emit("/", ANY); emit("]]", R_BRACKET);}
  |  '/]'
  ;

L_BRACKET
  :  '[['
  ;

R_BRACKET
  :  ']]'
  ;

SPACE
  :  (' ' | '\t' | '\r' | '\n') {skip();}
  ;

ANY
  :  .
  ;

which can be tested with the class:

import org.antlr.runtime.*;

public class Main {
  public static void main(String[] args) throws Exception {
String source = "[/ foo /] [[/ bar /]]";
ANTLRStringStream in = new ANTLRStringStream(source);
TLexer lexer = new TLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
for(Object o : tokens.getTokens()) {
  Token t = (Token)o;
  System.out.println("text=" + t.getText() + ", type=" + t.getType());
}
  }
}


Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.



  1   2   3   >