[il-antlr-interest: 27680] Re: [antlr-interest] Running ANTLRWorks 1.3.1 -- javac error
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 kfeuerh...@wlu.cawrote: 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
On Tue, Jan 26, 2010 at 7:37 PM, Andreas Stefik stef...@gmail.com 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 bki...@gmail.com 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 kfeuerh...@wlu.ca 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
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 tr...@wewatchyourwebsite.com 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: 27805] Re: [antlr-interest] Anyone have some good Python examples?
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.comwrote: 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?
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 bki...@gmail.com 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(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: 27810] Re: [antlr-interest] Anyone have some good Python examples?
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 bki...@gmail.com 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 bki...@gmail.com 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(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: 27822] Re: [antlr-interest] Parse 1 - N repeats
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 fields=2 min=0, max=20\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 ListString fieldList; final int fields; final int min; final int max; Repeat(int fields, int min, int max) { this.fieldList = new ArrayListString(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 fields=2 min=0, max=20 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: 27981] Re: [antlr-interest] C# example of lexical filter mode ??
Hi John, On Thu, Feb 18, 2010 at 7:52 PM, John Pool j.p...@ision.nl 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
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: source name=in type=String array itemtag name=patient value=Mr Hyde /T1 Hyde/item itemtag name=patient value=Mr Argan /T1 Argan/item /array /source 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
On Thu, Feb 25, 2010 at 11:27 PM, Scott Stanchfield sc...@javadude.comwrote: ... 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
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
On Tue, Mar 2, 2010 at 7:00 PM, Bart Kiers bki...@gmail.com 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?
Hi Chris, sorry, forgot to send to the list the first time! On Tue, Mar 9, 2010 at 4:41 PM, Christoph Schinko c.schi...@cgv.tugraz.atwrote: 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
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: 28276] Re: [antlr-interest] Grammar help
On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin bri...@sannas.org 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
On Tue, Mar 16, 2010 at 7:35 AM, Bart Kiers bki...@gmail.com wrote: On Tue, Mar 16, 2010 at 4:54 AM, Brian Catlin bri...@sannas.org 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
On Tue, Mar 16, 2010 at 8:10 AM, Brian Catlin bri...@sannas.org 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 bri...@sannas.org 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
On Tue, Mar 23, 2010 at 2:56 PM, Damien Urruty lepila...@hotmail.comwrote: 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
On Thu, Mar 25, 2010 at 9:19 AM, foxterri foxterri foxter...@hotmail.comwrote: 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: 28367] Re: [antlr-interest] strange MismatchedTokenException
On Thu, Mar 25, 2010 at 10:00 AM, Simon zack simonz...@gmail.com 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: 28372] Re: [antlr-interest] Lexer rule for strings with quoted strings within
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
On Thu, Mar 25, 2010 at 2:50 PM, Bart Kiers bki...@gmail.com 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: 28393] Re: [antlr-interest] (no subject)
On Sat, Mar 27, 2010 at 9:16 AM, Gouasmi Thouraya gthour...@yahoo.frwrote: 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: 28433] Re: [antlr-interest] Empty complement set?
On Wed, Mar 31, 2010 at 11:47 AM, Anton Bychkov bychkov.an...@gmail.comwrote: ... 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?
-- Forwarded message -- From: Bart Kiers bki...@gmail.com 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 bychkov.an...@gmail.comwrote: ... 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
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
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
On Fri, Apr 9, 2010 at 10:56 AM, Dietmar Schaefer dietma...@online.dewrote: ... 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: 28550] Re: [antlr-interest] Non-determinism (was: Can I force a token to have precendence in the lexer?)
On Wed, Apr 21, 2010 at 2:41 AM, Andy Hull an...@sunrunhome.com 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: 28614] Re: [antlr-interest] VHDL Target
On Mon, Apr 26, 2010 at 10:02 PM, David Blubaugh davidblubaugh2...@yahoo.comhttp://us.mc1133.mail.yahoo.com/mc/compose?to=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
On Thu, May 6, 2010 at 3:44 PM, Nishanth singh singh.nishan...@gmail.comwrote: ... 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
On Tue, May 18, 2010 at 6:04 PM, Cameron Ross cr...@kojeware.com 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
On Wed, May 19, 2010 at 2:10 AM, Ernesto Castillo hcast...@rocketmail.comwrote: 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?
On Sat, May 22, 2010 at 1:33 PM, Sameh W. Zaky sameh...@gmail.com 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: 29095] Re: [antlr-interest] .* consuming all input
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: 29296] Re: [antlr-interest] Noob Question
Hi Martin, On Fri, Jul 2, 2010 at 2:35 PM, Martin Jacobson jacobson.mar...@gmail.comwrote: I have the following error: /Users/martin/ANTLR/SVG/PathParser.g:0:0: syntax error: codegen: AST: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: 29728] Re: [antlr-interest] Filtering Java expressions
Forgot to reply to the entire group... On Fri, Aug 6, 2010 at 8:03 PM, Bill Andersen bill.ander...@mac.com 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
On Thu, Aug 12, 2010 at 7:10 AM, Victor Giordano power_gio...@yahoo.com.arwrote: ... 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: 30345] Re: [antlr-interest] cretae the inverse of a rule
On Fri, Oct 15, 2010 at 3:39 PM, Remi Marechal remi.marec...@gmail.comwrote: 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
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?
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: 30778] Re: [antlr-interest] jar file changes in version 3.3?
Hi, On Sun, Dec 5, 2010 at 10:14 AM, Chao Wang chaowan...@gmail.com 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?
On Sun, Dec 5, 2010 at 11:21 AM, Chao Wang chaowan...@gmail.com 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,nulltype) 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?
On Tue, Dec 21, 2010 at 3:05 PM, Andrzej borucki_andr...@wp.pl 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/CSharpwork 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: 31170] Re: [antlr-interest] a range as single token?
On Sat, Jan 15, 2011 at 11:43 AM, fikin nikolai.fii...@gmail.com 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?
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?
On Sat, Jan 15, 2011 at 1:23 PM, fikin nikolai.fii...@gmail.com 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
On Tue, Jan 18, 2011 at 7:41 AM, Kevin Jackson foamd...@gmail.com 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: 31241] Re: [antlr-interest] org.antlr.runtime.CommonToken cannot be cast to org.antlr.runtime.tree.Tree
On Wed, Jan 26, 2011 at 10:40 PM, Ching zchin...@gmail.com 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
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. http://stackoverflow.com/questions/4914073/partial-grammar-for-counting-class-count/4914224#4914224 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
Hi, On Tue, Feb 8, 2011 at 11:18 PM, Alex Lujan a...@apption.com 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: ANTLRInputStreamhttp://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_a_n_t_l_r_input_stream.html#cc37ee52e581d61a2efef0413ae3366f (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
On Thu, Feb 10, 2011 at 6:08 PM, Roohul roohu...@yahoo.com 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
On Fri, Feb 11, 2011 at 2:27 PM, Roohul roohu...@yahoo.com 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
On Fri, Feb 11, 2011 at 7:04 PM, Olivier Lefevre lefev...@yahoo.com 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: 31448] Re: [antlr-interest] Own Tree Class
On Mon, Feb 14, 2011 at 6:50 PM, Filip Habr habr.fi...@seznam.cz 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 habr.fi...@seznam.cz 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?
On Wed, Feb 16, 2011 at 9:18 AM, devdoer bird devdo...@gmail.com 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((a3)); 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 :: (a3) 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: 31710] Re: [antlr-interest] How to get the complete syntax tree
Hi, 2011/3/3 Juan Manuel Cámara juanm...@gmail.com ... 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 http://www.antlr.org/wiki/display/ANTLR3/Tree+constructionAnd/or: http://stackoverflow.com/questions/4931346/how-to-output-the-ast-built-using-antlr 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?
On Fri, Mar 4, 2011 at 6:53 PM, g...@novadsp.com 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?
On Fri, Mar 4, 2011 at 11:23 PM, g...@novadsp.com 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: 31800] Re: [antlr-interest] #include mechanism for grammar files?
Hi Jerry,. On Sun, Mar 13, 2011 at 3:33 PM, g...@novadsp.com 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
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
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
On Mon, Mar 28, 2011 at 5:58 PM, J. Talafous jtalaf...@gmail.com 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
On Thu, Mar 31, 2011 at 9:24 AM, piet...@agh.edu.pl 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
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. http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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
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
On Mon, Apr 11, 2011 at 6:31 PM, The Researcher researcher0...@gmail.comwrote: 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 http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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: 32209] Re: [antlr-interest] v2-v3 Skip chars in Lexer?
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?
On Mon, May 2, 2011 at 1:19 AM, Todd O'Bryan toddobr...@gmail.com 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 { ListToken tokens = new ArrayListToken(); 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.
[il-antlr-interest: 32367] Re: [antlr-interest] Inserting missing nodes
On Wed, May 4, 2011 at 4:12 PM, Jean-Sebastien Vachon jean-sebastien.vac...@wantedtech.com wrote: No one can help me with this? :S Let me know if something is not clear. I need to fix this issue as soon as I can. Thanks The fact that you didn't provide the lexer rules (although they might be straight-forward as you mentioned), and you didn't mention what input you're specifically having problems with parsing (the following is a bit vague: *... but I can't get it to parse everything I'm throwing at it ...*), might be some reasons why you haven't been answered. 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: 32381] Re: [antlr-interest] Inserting missing nodes
How about something like this: grammar MyGrammar; options { output=AST; } tokens { DEFAULT_OP; } query : andExpression EOF - andExpression ; andExpression : (orExpression - orExpression) ( AND e=orExpression - ^(AND $e $andExpression) | (orExpression)= e=orExpression - ^(DEFAULT_OP $e $andExpression) )* ; orExpression : negation (OR^ negation)* ; negation : NOT operand - ^(NOT operand) | operand ; operand : WORD | '(' andExpression ')' - andExpression ; AND : 'AND'; OR: 'OR'; NOT : 'NOT'; WORD : 'a'..'z'+; SPACE : (' ' | '\t' | '\r' | '\n') {skip();}; Test class: import org.antlr.runtime.*; import org.antlr.runtime.tree.*; import org.antlr.stringtemplate.*; public class Main { public static void main(String[] args) throws Exception { ANTLRStringStream in = new ANTLRStringStream(software engineer OR java programmer); MyGrammarLexer lexer = new MyGrammarLexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); MyGrammarParser parser = new MyGrammarParser(tokens); MyGrammarParser.query_return returnValue = parser.query(); CommonTree tree = (CommonTree)returnValue.getTree(); DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st = gen.toDOT(tree); System.out.println(st); } } Regards, Bart. On Wed, May 4, 2011 at 4:51 PM, Jean-Sebastien Vachon jean-sebastien.vac...@wantedtech.com wrote: Thanks for your input. So here is the whole thing with two use cases that are not giving me the expected results... (Sorry for the long post) INPUT = abc def zyx toto RESULT = (DEFAULT_OP abc def) (DEFAULT_OP zyx toto) EXPECTED = (DEFAULT_OP (DEFAULT_OP abc def) (DEFAULT_OP zyx toto)) INPUT = software engineer OR java programmer RESULT = (DEFAULT_OP software (OR engineer java)) programmer EXPECTED = (DEFAULT_OP (DEFAULT_OP software (OR engineer java)) programmer) I'm also having some trouble using the Interpreter within Eclipse. The same expressions are not working in the interpreter. It fails to generate the tree with a NoViableAltException at input 'abc' (for the first case). I don't think this is related to my other problem since I can't get it to generate any tree. Thanks again for your time and comments -- Grammar (validation by building a tree and trying to insert missing operators) -- grammar MyGrammar; options { language = Java; output = AST; ASTLabelType = CommonTree; } // Rules to build the tree representation of our expression... query : and_expr+ EOF! ; // Each AND expression can contain OR expressions... and_expr : (expr expr+) = default_op | (u1=or_expr (AND^ u2=or_expr)*) ; // A OR expression contains one or more expression or_expr : u1=expr (OR^ u2=expr)* ; default_op : (e1=or_expr e2=or_expr) - ^(DEFAULT_OP $e1 $e2) ; expr : (NOT^)? (operand) ; // The leafs of the tree.. Words, sentence and so on... // Note that an expression such as '-word' is rewritten in its 'NOT word' form operand : (f=FIELD^)(o=operand) | PREFIX | WORD | SENTENCE | WORDLIST | NEGATIVE(w=PREFIX|w=WORD|w=SENTENCE|w=WORDLIST) - ^(NOT $w) | MUST | LPAREN! and_expr RPAREN! ; // Lexer ... NEGATIVE: '-'; LPAREN : '(' ; RPAREN : ')' ; DOUBLEQUOTE : ''; STAR : '*'; AND : 'AND' | '+'; OR : 'OR'; NOT : 'NOT'; DEFAULT_OP : 'DEF_OP'; FIELD : ('title'|'TITLE'|'Title')(FIELDSEPARATOR); WS : (WSCHAR)+ { $channel=HIDDEN; }; PREFIX : WORDCHAR+(STAR); WORD: WORDCHAR+(('-'|'+')WORDCHAR*)*; SENTENCE: ((DOUBLEQUOTE)(~(DOUBLEQUOTE))*(DOUBLEQUOTE)); WORDLIST: ((PREFIX | WORD | SENTENCE)(','(WS)* (PREFIX | WORD | SENTENCE))+); MUST : '+'(PREFIX|WORD|SENTENCE|WORDLIST); fragment WORDCHAR : (~( WSCHAR | LPAREN | RPAREN | '-' |':' | '+' | ',' | STAR | DOUBLEQUOTE) ); fragment FIELDSEPARATOR : ':'; fragment WSCHAR : ( ' ' | '\t' | '\r' | '\n'); = END OF GRAMMAR == -Original Message- From: antlr-interest-boun...@antlr.org [mailto: antlr-interest-boun...@antlr.org] On Behalf Of Bart Kiers Sent: May-04-11 10:21 AM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Inserting missing nodes On Wed, May 4, 2011 at 4:12 PM, Jean-Sebastien Vachon jean-sebastien.vac...@wantedtech.com wrote: No one can help me with this? :S Let me know if something is not clear. I need to fix this issue as soon as I can. Thanks The fact that you didn't provide the lexer rules (although they might be straight-forward
[il-antlr-interest: 32385] Re: [antlr-interest] rules that takes rules as arguments
Both parser- and lexer rules can take parameters of any (Java) type. However, rules in ANTLR are translated to methods, and methods aren't first class objects in Java. So providing a rule (read: method) to another rule as parameter is not possible. Perhaps you can elaborate a bit and explain what problem you're trying to solve? Regards, Bart. On Tue, May 3, 2011 at 7:29 PM, Vladimir VG gordeev.vladimi...@gmail.comwrote: I'm defining some grouping rule ( '(' value ')' ) for operator precedence, and it will be helpful if I would use rules that takes other rules as arguments. Is that possible? 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: 32394] Re: [antlr-interest] Multiple Occurrence Read Out
Only at the end. You need to place the code-block *inside* the parenthesis like this: keysAndValues : ('' key '' value { // Some code to read the key(s) and value(s) out. System.out.println(key= + $key.text + , value= + $value.text); } )* ; Regards, Bart. On Fri, May 6, 2011 at 5:19 PM, Philip Mötteli philip.moett...@tele2.chwrote: Hi, I have a parser rule, that parses a kind of a property list: keysAndValues : ('' key '' value)* { // Some code to read the key(s) and value(s) out. // Is this part called for every occurrence of * or only once at the end? } ; I would like to add every key and its property to a dictionary in my program. How can I read those values out? Thanks 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: 32414] Re: [antlr-interest] Translating expressions - advice?
I get the impression you think that when creating AST's, ANTLR inserts parenthesis (brackets). This is not the case: I guess what you're seeing is just the tree's `toStringTree()` that displays these parenthesis to make the hierarchy of the tree apparent. Or am I misinterpreting your question? Regards, Bart. On Mon, May 9, 2011 at 3:10 PM, Hans-Juergen Rennau hren...@yahoo.dewrote: Hello People, being an ANTLR beginner, I would very much appreciate advice concerning good practise for a rather simple task. The task is the translation of a JPQL's (Java Persistence Query Language) where clause into a proprietary query language. The clause has the well-known expression structure: operands conncected by three operators: OR, AND and NOT, where precedence increases in that order. Example: a.x='1' AND (a.y='2' OR b.z='3') AND a.v like 'abc%' An important point is that the translation result will have a similar structure, that is, it will also be operands connected by those operators. Example: x='1' AND (y='2' OR z='3') AND v='123*' For this reason I am not sure if the classical approach for dealing with left-associative operators, as shown in the Definitve ANTLR Reference (3. A quick tour...) is the most appropriate one in this case. I mean rules like: conditional_term ('OR'^ conditional_term)* conditional_factor ('AND'^ conditional_factor)* This creates deep trees, where each operator creates a new level. That is fine for processing the operations. But a straightforward translation of the tree into a similar sequence of operands and operators yields a result which is correct but can be ugly, due to superflous brackets, example: (a OR (b OR (c AND d))) One possibility is to process the tree, removing superfluous brackets - perhaps by passing the context operator into the rule as a parameter, so that the rule can decide if to create brackets or not. This should not be too difficult, but my question is: is there a good practise for accomplishing the task? Would you recommend the approach just sketched, or a different tree representation to start with? (A tree I do want because there are other parts to be translated, not only the where clause, and a tree seems to me the way to deal with (possibly yet growing) complexity. Thank you very much for any suggestions. -- Hans-Juergen 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: 32415] Re: [antlr-interest] Translating expressions - advice?
Wait I think I misunderstood. Your example `(a OR (b OR (c AND d)))` is just an example expression, right? In that case, yes, these parenthesis are part of the token stream, but if you apply rewrite rules (or AST operators `^` and `!`) properly, these parenthesis are easily removed from your parse tree. See: http://www.antlr.org/wiki/display/ANTLR3/Tree+construction or: http://stackoverflow.com/questions/4931346/how-to-output-the-ast-built-using-antlr Regards, Bart. On Mon, May 9, 2011 at 4:10 PM, Bart Kiers bki...@gmail.com wrote: I get the impression you think that when creating AST's, ANTLR inserts parenthesis (brackets). This is not the case: I guess what you're seeing is just the tree's `toStringTree()` that displays these parenthesis to make the hierarchy of the tree apparent. Or am I misinterpreting your question? Regards, Bart. On Mon, May 9, 2011 at 3:10 PM, Hans-Juergen Rennau hren...@yahoo.dewrote: Hello People, being an ANTLR beginner, I would very much appreciate advice concerning good practise for a rather simple task. The task is the translation of a JPQL's (Java Persistence Query Language) where clause into a proprietary query language. The clause has the well-known expression structure: operands conncected by three operators: OR, AND and NOT, where precedence increases in that order. Example: a.x='1' AND (a.y='2' OR b.z='3') AND a.v like 'abc%' An important point is that the translation result will have a similar structure, that is, it will also be operands connected by those operators. Example: x='1' AND (y='2' OR z='3') AND v='123*' For this reason I am not sure if the classical approach for dealing with left-associative operators, as shown in the Definitve ANTLR Reference (3. A quick tour...) is the most appropriate one in this case. I mean rules like: conditional_term ('OR'^ conditional_term)* conditional_factor ('AND'^ conditional_factor)* This creates deep trees, where each operator creates a new level. That is fine for processing the operations. But a straightforward translation of the tree into a similar sequence of operands and operators yields a result which is correct but can be ugly, due to superflous brackets, example: (a OR (b OR (c AND d))) One possibility is to process the tree, removing superfluous brackets - perhaps by passing the context operator into the rule as a parameter, so that the rule can decide if to create brackets or not. This should not be too difficult, but my question is: is there a good practise for accomplishing the task? Would you recommend the approach just sketched, or a different tree representation to start with? (A tree I do want because there are other parts to be translated, not only the where clause, and a tree seems to me the way to deal with (possibly yet growing) complexity. Thank you very much for any suggestions. -- Hans-Juergen 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: 32430] Re: [antlr-interest] Geting all tokens from lexer / token stream
CommonTokenStream inherits getTokens() which returns a List of Tokens. You'll need to cast them to a Token (or something that extends a Token), since it's a non-generics List list: CommonTokenStream tokens = new CommonTokenStream(lexer); for(Object o : tokens.getTokens()) { Token t = (Token)o; System.out.println(t); } Regards, Bart. On Wed, May 11, 2011 at 1:40 PM, Lars von Wedel lars.vonwe...@gmail.comwrote: Hello, I am writing an interactive interpreter and I would like to obtain all tokens from a lexer of token stream to test, whether the input is complete or continued on the next line. What is the easiest approach to do this ? I tried a CommonTokenStream but I am not sure how to tell it to pull all tokens from the lexer. Thanks and Regards, Lars 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: 32449] Re: [antlr-interest] Lexer code missing @header info
Hi David, The snippet: @header { package parser; import java.util.HashMap; } is short for: @parser::header { package parser; import java.util.HashMap; } You'll need to do the following as well: @lexer::header { package parser; import java.util.HashMap; } Regards, Bart. On Fri, May 13, 2011 at 3:08 PM, David Smith david.sm...@cc.gatech.eduwrote: I'm using ANTLRWorks to generate java code form a grammar with the front-end listed below. The code generation works flawlessly producing XXXLexer.java and XXXParser.java as expected with one minor annoyance. The package parser; line makes it into XXXParser.java, but not into XXXLexer.java. I therefore have to manually edit XXXLexer.java. Not really a big issue, but is there an easy cure? __ grammar XXX; options { output=AST; ASTLabelType=CommonTree; } tokens{ STATLIST; } @header { package parser; import java.util.HashMap; } David M. Smith http://www.cc.gatech.edu/fac/David.Smith Georgia Institute of Technology, College of Computing Sent from my ASR-33 Teletype 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: 32479] Re: [antlr-interest] Parsing comment-like sequences of arbitrary characters
Hi Rajesh, Inside a parser rule, the `~` negates tokens, not characters. So if you have no lexer rule that tokenizes one of: '%', ''^' or '$', then ~SEMICOLON won't match any of such tokens/characters. Your grammar (with minor modifications): grammar Test; options { output=AST; } tokens { OPTION; OPTION_BLOCK; } query_options : OPTIONS^ option_block ; option_block : L_BRACE option_def* R_BRACE - ^(OPTION_BLOCK option_def*) ; option_def : option_name option_value - ^(OPTION option_name option_value) ; option_name : ID (DOT^ ID)* ; option_value : COLON^ (~SEMICOLON)* SEMICOLON! | option_block ; OPTIONS : 'options'; ID: (LETTER | '_') (LETTER | DIGIT | '_')*; DOLLAR: '$'; PERCENT: '%'; CARET: '^'; DOT: '.'; L_BRACE: '{'; R_BRACE: '}'; COLON: ':'; SEMICOLON: ';'; DIGIT : '0'..'9'; SL_COMMENT: '#' ~('\r' | '\n')* { skip(); }; WS: (' ' | '\f' | '\r' | '\t')+ { skip(); }; fragment LETTER : 'a'..'z' | 'A'..'Z'; parses the input: options { foo: $ % 1 2 45 ^ $ $$$; } as follows: (options (OPTION_BLOCK (OPTION foo (: $ % 1 2 4 5 ^ $ $ $ $ as you can see after running the test rig: import org.antlr.runtime.*; import org.antlr.runtime.tree.*; import org.antlr.stringtemplate.*; public class Main { public static void main(String[] args) throws Exception { ANTLRStringStream in = new ANTLRStringStream(options { foo: $ % 1 2 45 ^ $ $$$; }); TestLexer lexer = new TestLexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); TestParser parser = new TestParser(tokens); TestParser.query_options_return returnValue = parser.query_options(); CommonTree tree = (CommonTree)returnValue.getTree(); DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st = gen.toDOT(tree); System.out.println(st); System.out.println(---\n + tree.toStringTree()); } } Regards, Bart. On Wed, May 18, 2011 at 12:55 AM, Rajesh Raman r...@fb.com wrote: Hello ANTLR-ites, I'm trying to parse an options structure, like the following: options { foo { bar { ww: $32.50; xx: Jekyll Hyde; } yy.zz: @15% p/a; } } (Please ignore the non-sensical values for ww, xx and yy.zz -- I'm just making a point, which will become clearer below). This options structure will be followed by a query expression whose grammar is more complicated, and includes ints/floats, identifiers, operators, etc. etc. The grammar I have for parsing the options structure looks like the below. (The grammar for the query language is complicated and therefore omitted.) snip // ... other stuff here tokens { // ... other ad hoc token values OPTION; OPTION_BLOCK; OPTION_VALUE; } // ... query_options : OPTIONS^ option_block ; option_block : L_BRACE option_def* R_BRACE - ^(OPTION_BLOCK option_def*) ; option_def : option_name option_value - ^(OPTION option_name option_value) ; option_name : ID (DOT^ ID)* ; option_value : COLON^ (~SEMICOLON)* SEMICOLON! | option_block ; //... other stuff here //... OPTIONS: 'options'; ID: (LETTER | '_') (LETTER | DIGIT | '_')*; DOT: '.'; L_BRACE: '{'; R_BRACE: '}'; COLON: ':'; SEMICOLON: ';'; SL_COMMENT: '#' ~('\r' | '\n')* NEWLINE { skip(); }; WS: (' ' | '\f' | '\r' | '\t')+ { skip(); }; ... /snip As mentioned, the options clause is part of a larger grammar for a language that includes operators, identifiers, numbers, etc., However, within the options clause, I want the characters between the colon and the semicolon to be treated as a single string, regardless of the fact that it may contain characters that lex into other tokens used by the language. This feels like I should be able to use the same techniques as used in comment-stripping (i.e,. see the line that has COLON^...). But this doesn't seem to work: - The stray characters that are not used elsewhere in the grammar are ignored and don't show up in the parse tree (e.g., $, @, %, , in the example above) - Character sequences that form valid tokens for the rest of the language (like integers or identifiers) are lexed into those respective tokens instead of being slurped into a single string as intended. E.g., when I input a string like options { foo: $ % 1 2 45 ^ $ $$$; } and display the resulting tree.toStringTree(), I get (options (OPTION_BLOCK (OPTION foo (: 1 2 45 Any guidance you have on the above will be greatly appreciated. Thanks in advance. ++Rajesh 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
[il-antlr-interest: 32481] Re: [antlr-interest] Fragment rules inside parser rules
Hi Ben, You cannot use fragment rules inside parser rules. So yes, you need to make LKU a normal token. If you don't want that (for whatever reason), you need to include the '' in the 'NAME' rule: NAME : '' ('a'..'z')+ ; Regards, Bart. On Wed, May 18, 2011 at 3:00 PM, Ben Corne ben.co...@gmail.com wrote: Hello Do I really need to make LKU in the example below a normal token rule or is there a way to get this to work for the input 'foo;' not using literals inside the parser rule or real tokens. grammar Foo; program : (LKU NAME ';')+ ; fragment LKU : '' ; NAME : ('a'..'z')* ; = Regards Ben C. 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: 32499] Re: [antlr-interest] Can't figure this one out
Hi David, Your parser does not handle: ans = 3 * (-x + y) * 4 properly since `ans` is an ANS-token and not an IDENT-token. Therefor it does not get matched by your `assignmentStatement` rule. Also, you should probably add the EOF at the end of your `script` rule in your combined grammar. Regards, Bart. On Fri, May 20, 2011 at 3:47 AM, David Smith david.sm...@cc.gatech.eduwrote: I developed a tree parser by making minor changes to Scott Stanchfield's tutorial videos. I don't know where to start looking to explain the problem. Here are the pieces: // The grammar: grammar GTMat; options { language = Java; output=AST; ASTLabelType=CommonTree; } tokens { NEGATION; } @header { package parser; } @lexer::header { package parser; } script : statement* ; statement : assignmentStatement ; assignmentStatement : IDENT GETS^ expression SEMI? ; actualParameters : expression (COMMA expression)* ; // expressions -- fun time! term : (IDENT OPENP ) = IDENT '(' actualParameters ')' | OPENP! expression CLOSEP! | INTEGER | IDENT ; unary : (PLUS! | negation^)* term ; negation : MINUS - NEGATION ; mult : unary ((MULT^ | DIV^ ) unary)* ; add : mult ((PLUS^ | MINUS^) mult)* ; relation : add ((EQUALS^ | NOTEQ^ | LESS^ | LESSEQ^ | GT^ | GTEQ^) add)* ; expression : relation ((AND^ | OR^) relation)* ; GETS: '='; SWITCH : 'switch'; CASE: 'case'; OTHERWISE : 'otherwise'; IF : 'if'; ELSE: 'else'; ELSEIF : 'elseif'; END : 'end'; FOR : 'for'; WHILE : 'while'; ANS : 'ans'; COMMA : ','; OPENP : '('; CLOSEP : ')'; NOT : '~'; SEMI: ';'; PLUS: '+'; MINUS : '-'; MULT: '*'; DIV : '/'; EQUALS : '=='; NOTEQ : '!='; LESS: ''; LESSEQ : '='; GT : ''; GTEQ: '='; AND : ''; OR : '||'; SINGLE : '\''; fragment LETTER : ('a'..'z' | 'A'..'Z') ; fragment DIGIT : '0'..'9'; INTEGER : DIGIT+ ; IDENT : LETTER (LETTER | DIGIT)*; WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;}; COMMENT : '%' .* ('\n'|'\r') {$channel = HIDDEN;}; // The Walker Grammar: tree grammar EvaluatorWalker; options { language = Java; tokenVocab = GTMat; ASTLabelType = CommonTree; } @header { package parser; import java.util.Map; import java.util.HashMap; } @members { private MapString, Integer variables = new HashMapString, Integer(); } evaluator : assignment* EOF ; assignment : ^('=' IDENT e=expression) { variables.put($IDENT.text, e); } ; expression returns [int result] : ^('+' op1=expression op2=expression) { result = op1 + op2; } | ^('-' op1=expression op2=expression) { result = op1 - op2; } | ^('*' op1=expression op2=expression) { result = op1 * op2; } | ^('/' op1=expression op2=expression) { result = op1 / op2; } | ^(NEGATION e=expression) { result = -e; } | IDENT { result = variables.get($IDENT.text); } | INTEGER { result = Integer.parseInt($INTEGER.text); } ; // The Test Program: package parser; import org.antlr.runtime.ANTLRFileStream; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.TokenStream; import org.antlr.runtime.tree.CommonTreeNodeStream; import java.io.IOException; public class Test4 { public static void main(String[] args) throws RecognitionException, IOException { CharStream stream = new ANTLRFileStream(Test.m); GTMatLexer lexer = new GTMatLexer(stream); TokenStream tokenStream = new CommonTokenStream(lexer); GTMatParser parser = new GTMatParser(tokenStream); GTMatParser.script_return evaluator = parser.script(); System.out.println(evaluator.tree.toStringTree()); CommonTreeNodeStream nodeStream = new CommonTreeNodeStream(evaluator.tree); EvaluatorWalker walker = new EvaluatorWalker(nodeStream); walker.evaluator(); System.out.println(ok); } } // The input code: x = 8 y = 2 + 3 ans = 3 * (-x + y) * 4 // When I run it, I get this: (= x 8) (= y (+ 2
[il-antlr-interest: 32502] Re: [antlr-interest] AST Question
Hi Your rule: targetsExpr : category ('CAND' targetsExpr)* - ^('CAND' category targetsExpr*) ; is incorrect. You're always using `CAND` in your rewrite rule but that rule could just match `category` only. You'll probably want to do: targetsExpr : category ('CAND'^ targetsExpr)* ; (Note the ^ after CAND which makes it the root) Regards, Bart. On Fri, May 20, 2011 at 10:11 AM, massimiliano.m...@gmail.com massimiliano.m...@gmail.com wrote: Hello All, I'm more or less a newbie using antlr. I have a small issue on creating the AST, using rewrite rules. I'm so sorry if this is a FAQ or similar! :) I have the following productions (it's like an algebra with 3 operators with different priorities): targetsExpr : (category) ('CAND' targetsExpr)* -^('CAND' category targetsExpr*) ; category: (matchEl) ('OR' category)* - ^('OR' matchEl category* ) ; matchEl : factor ('AND' factor)* -^('AND' factor*) ; factor : matchId OPAR targetValue COMMA targetName CPAR -^('FAC' matchId targetValue targetName) The problem is that the AST created contains productions as: CAND -OR - OR- AND (FAC, FAC). The second OR is created because the ``category'' production is passed multiple times. Is there a way to not create these kind of rules? You can see a sample of the AST created in http://www.mascanc.net/~max/policy.pdf. -- Massimiliano Masi http://www.mascanc.net/~max 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: 32507] Re: [antlr-interest] AST Question
On Fri, May 20, 2011 at 9:54 PM, massimiliano.m...@gmail.com massimiliano.m...@gmail.com wrote: Hi, On Fri, May 20, 2011 at 10:55 AM, Bart Kiers bki...@gmail.com wrote: targetsExpr : category ('CAND' targetsExpr)* - ^('CAND' category targetsExpr*) ; is incorrect. You're always using `CAND` in your rewrite rule but that rule could just match `category` only. You'll probably want to do: targetsExpr : category ('CAND'^ targetsExpr)* ; Thank you for your answer! It works now! But I've another question now. When I traverse the tree using this function (is there an example to have a visitor created by antlr?) Yes, this is typically what tree grammars are for. But you can also walk it manually. See: http://www.antlr.org/article/1100569809276/use.tree.grammars.tml http://www.antlr.org/article/1170602723163/treewalkers.html 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: 32513] Re: [antlr-interest] Collecting parameters
Hi David, Every root (or leaf) in the AST must be an instance of a ` org.antlr.runtime.tree.Tree`, so you can't create a node that is a `java.util.List`. By default, ANTLR creates its AST using `org.antlr.runtime.tree.CommonTree` objects which inherits the `getChildren()` method from `org.antlr.runtime.tree.BaseTree` which returns a List. This List contains `CommonTree`'s. So your VECTOR root already has a method to get the children `1,2,3,4`. Regards, Bart. On Sat, May 21, 2011 at 7:14 PM, David Smith david.sm...@cc.gatech.eduwrote: Your contributors have been very helpful with my novice questions, and I thank them. Here's another: I am trying to build an AST that processes text like: v4 = [1 2 3 4] The following rule works: term : (OPENB .+ CLOSEB) = OPENB vals CLOSEB - ^(VECTOR vals) |OPENB CLOSEB- EMPTY_VECTOR |DOUBLE |ID |'('! expr ')'! ; vals returns [List items] : vl+=expr (COMMA? vl+=expr)* {$items = $vl;} ; but it produces tree nodes like: (= v4 (VECTOR 1 2 3 4)) but I really want (= v4 (VECTOR values)) where 'values' is some kind of Java collection like an ArrayList. How do I do that? David M. Smith http://www.cc.gatech.edu/fac/David.Smith Georgia Institute of Technology, College of Computing Sent from my ASR-33 Teletype 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: 32565] Re: [antlr-interest] question about antlr
Hi Patrick, I have a hard time understanding what it is you're trying to do. Instead of springing the entire grammar on us (or me), could you extract only those rules that are causing the problem(s)? And could you include some example input you'd like to match/parse? Regards, Bart Kiers. On Thu, May 26, 2011 at 4:04 PM, Patrick Hofman patrick.hof...@invantive.com wrote: And now the grammar From: Patrick Hofman Sent: donderdag 26 mei 2011 15:35 To: antlr-interest@antlr.org Subject: question about antlr Hi all, I have bought the ANTLR book in order to learn ANTLR better, but I still don't get how to fix one thing. I hope you can help me with that. I have a grammar that is used to parse our custom formula format to an Excel formula. So when filling an Excel worksheet the string entered is something like '$C{D,.,.,.+1}' which means 'one cell right from the current cell'. You will understand that eventually we will get something like '$C{D,.,.,.+1} + $C{D,.,.,.+2}', so add up the value of the first cell right and the second cell right (in Excel when we are at A1 this results in '=B1 + B2'. The problem is this: In the grammar I cannot find a way to 'eat up' the text between two 'eca_kolom_expressie' strings (the '$C{...}' part). I already tried 'EXCEL_FRAGMENT' in a hundred ways, but none of them seemed to work. ('TILDE (options {greedy=false;} : .) TILDE' seems to work, but when removing the TILDEs it stops working) I have included the grammar. Can you point me in the right direction? Regards, Patrick Hofman Senior Consultant Invantive B.V. 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: 32567] Re: [antlr-interest] Nasty LHS expression
Hi David, Can an `expr` match something that starts with `ID OPENP` and/or `ID GETS`? Perhaps you can post your entire grammar? Or at least the `expr` rule? Regards, Bart. On Thu, May 26, 2011 at 7:02 PM, David Smith david.sm...@cc.gatech.eduwrote: I am having a difficult time distinguishing two legal lines of code: ID = expression and ID(exp1, exp2, ...) = expression I tried this rule: stat: expr NEWLINE- expr | (ID OPENP .* CLOSEP GETS) = ID OPENP actualParameters CLOSEP GETS expr NEWLINE - ^(INDEX ID OPENP actualParameters CLOSEP expr) | ID GETS expr NEWLINE - ^(GETS ID expr) | NEWLINE - ; But it says that alternatives 2 and 3 can never be matched. How do I reactivate 2 and 3? DMS David M. Smith http://www.cc.gatech.edu/fac/David.Smith Georgia Institute of Technology, College of Computing Sent from my ASR-33 Teletype 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: 32609] Re: [antlr-interest] Do you need an ANTLR programmer?
On Mon, May 30, 2011 at 9:23 PM, ante...@freemail.hu wrote: On 5/30/2011 11:20 PM, Bart Kiers wrote: On Mon, May 30, 2011 at 9:13 PM, ante...@freemail.hu wrote: On 5/30/2011 10:41 PM, Bart Kiers wrote: Could you stop spamming the ANTLR mailing list please? Bart. You may not know that but As I was worried that that this mail can be perceived as a spam, I asked Terence Parr if it is ok, if I send a mail here. To my surprise, he said yes. How could I know? You might have included that information from the get-go. I am sure that I am not the only one being annoyed by such messages. And are you planning to spam this mailing list on a regular basis? Or just once? Bart. Now you know. Sorry for not mentioning it in the mail.. (I considered it) I am not sure if you agree with me but if it is allowed, it cannot be called spam. Well, the over-all definition of spam is this: Spam is the use of electronic messaging systems [...] to send unsolicited bulk messages indiscriminately. It _is_ unsolicited since no one asked for it. You may have gotten approval from someone, but that doesn't mean it's not unsolicited. So yes, it sure is spam. At the moment, Just once now. I really hope so. If every self-employed developer starts spamming the list, it'd become a mess. Bart. PS. I cc-ed the list so that others are aware of the fact it's now okay to advertise one selves here. Márton [1] http://en.wikipedia.org/wiki/Spam_(electronic) 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: 32611] Re: [antlr-interest] options greedy : getting the tokens consumed during the greedy match
Hi Vijay, You could grab all matched text in the `@after` block using the `getText()` method: COMMENT @init{ boolean isJavaDoc = false; System.out.println(Entering comment); } @after { System.out.println(Leaving comment, matched: + getText()); } : '/*' { if((char)input.LA(1) == '*') { isJavaDoc = true; } } (options {greedy=false;} : . )* '*/' ; Regards, Bart Kiers. On Mon, May 30, 2011 at 8:08 PM, Vijay Raj call.vijay...@yahoo.com wrote: Hi - I am trying to parse a given java file, with a code fragment that consumes comments as below: ( Code fragment got from Java.g , pasted in the antlr site, to give credit where it is due). COMMENT @init{ boolean isJavaDoc = false; System.out.println(Entering comment); } : '/*' { if((char)input.LA(1) == '*'){ isJavaDoc = true; } } (options {greedy=false;} : . )* '*/' ... ; I am trying to get all the characters mapped by the wildcard regex , as in 'options greedy' line in the grammar file and get the string into the Java world for further processing. What hidden system variables/ grammar should I use to take care of the same ? 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: 32612] Re: [antlr-interest] Do you need an ANTLR programmer?
On Mon, May 30, 2011 at 10:38 PM, Jim Idle j...@temporal-wave.com wrote: It always been OK, but there is obvious common sense involved, such as not posting such messages every week. For a start, I make a lot of my living writing professional ANTLR grammars and occasionally, you need to ask for work... which reminds me... But, in general I would shy away from appointing yourself unofficial arbitrator of the list. The list is basically whatever Ter says it is; the poster was polite enough to ask if it was OK to post and so that's that. Jim As I said: he could have posted that Terence gave him permission. Note that he send a message twice, in rapid succession. 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: 32637] Re: [antlr-interest] Accentuated chars in brazilian portuguese
Hi Nilo, The grammar: grammar Brasil; parse : WORD EOF ; WORD : ('\u00c0'..'\u00ff' | 'a'..'z' | 'A'..'Z' | '-')+ ; parses the input não just fine in ANTLRWorks. I'm not really familiar with C#, but for those who are, could you perhaps post *how* you are testing it? (post a test rig that shows the behavior you describe) Regards, Bart. On Wed, Jun 1, 2011 at 10:53 PM, Nilo Roberto C Paim nilop...@gmail.comwrote: Hi all, I'm newbie using Antlr and I'm facing a problem when trying to parse a text that contains accentuated chars in Brazilian Portuguese. I've put a word definition on my grammar as follows: WORD : ( '\u00c0'..'\u00ff' | 'a'..'z' | 'A'..'Z' | '-' )+ ; But have no success on parsing. Words like não (no in Portuguese) causes lexar throws Antlr.Runtime.NoViableAltException. I'm trying to use C#. Any hint? TIA Nilo, from Brasil... 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: 32660] Re: [antlr-interest] Any way to search the ANTLR interest archives?
Hi George, Sure, use Markmail: http://antlr.markmail.org/ http://antlr.markmail.org/Regards, Bart. On Sun, Jun 5, 2011 at 3:59 PM, George Spears geo...@woh.rr.com wrote: Hello, The ANTLR interest archives have a lot of valuable information in them.. (http://www.antlr.org/pipermail/antlr-interest/ ) Is there any way to search them? (Other than downloading everything to my local computer? If not, this would be a nice feature to have. Thanks, George Spears 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: 32685] Re: [antlr-interest] AST with optional parameters
Hi David, Try this: (ID GETS) = ID GETS expr SEMI? - ^(GETS ID expr SEMI?) Regards, Bart. On Tue, Jun 7, 2011 at 1:41 PM, David Smith david.sm...@cc.gatech.eduwrote: I'm parsing a grammar in which the semicolon on the end of a line is optional. So two of the statement rules might be: | (ID GETS expr SEMI) = ID GETS expr SEMI - ^(GETS ID expr SEMI) | (ID GETS) = ID GETS expr - ^(GETS ID expr) Since this occurs with a number of different assignment statements, I would really like to collapse this into one rule that looks something like this: | (ID GETS) = ID GETS e=expr (s=SEMI)? - ^(GETS ID $e $s) but every implementation I can think of either refuses to generate the grammar or, as in the case above, generates the grammar but decides that the variable 's' is unknown. Is there a any way to achieve this? DMS David M. Smith http://www.cc.gatech.edu/fac/David.Smith Georgia Institute of Technology, College of Computing Sent from my ASR-33 Teletype 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: 32697] Re: [antlr-interest] AST with optional parameters
Jim, From an earlier message, David wrote: *Yes, the language is Matlab and a semicolon on the end of an assignment expression suppresses display of the result of the assignment. ...* Bart. On Tue, Jun 7, 2011 at 6:30 PM, Jim Idle j...@temporal-wave.com wrote: Why do you want the SEMI in your AST? Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of David Smith Sent: Tuesday, June 07, 2011 4:41 AM To: antlr-interest@antlr.org Subject: [antlr-interest] AST with optional parameters I'm parsing a grammar in which the semicolon on the end of a line is optional. So two of the statement rules might be: | (ID GETS expr SEMI) = ID GETS expr SEMI - ^(GETS ID expr SEMI) | (ID GETS) = ID GETS expr - ^(GETS ID expr) Since this occurs with a number of different assignment statements, I would really like to collapse this into one rule that looks something like this: | (ID GETS) = ID GETS e=expr (s=SEMI)? - ^(GETS ID $e $s) but every implementation I can think of either refuses to generate the grammar or, as in the case above, generates the grammar but decides that the variable 's' is unknown. Is there a any way to achieve this? DMS David M. Smith http://www.cc.gatech.edu/fac/David.Smith Georgia Institute of Technology, College of Computing Sent from my ASR- 33 Teletype 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: 32703] Re: [antlr-interest] issue with antlr requiring a whitespace at a specific place
Well, your grammar is now quite different than the few rule you posted (more rules, and not everything is visible, so I can't test it myself). All I can say is that the interpreter from ANTLRWorks has (quite some) odd quirks, so best not use it. If something seems odd in the interpreter, either create a little test rig yourself, or use ANTLRWorks' debugger to be sure if the error lies in your grammar, or the interpreter. Good luck! Regards, Bart. On Wed, Jun 8, 2011 at 1:04 PM, Olivier Sallou olivier.sal...@irisa.frwrote: For the same, I have mismatched token. I simplified it to maximum (see first line of attached screenshot) However I see in my editor (antlrworks) in interpreter tab: Ignore rules: WHITESPACE. I wonder why, I did not ask for such ignore, and I do not see how to remove this. Maybe this occurs in generated code too. Olivier Le 6/8/11 12:58 PM, Bart Kiers a écrit : Hi Olivier, I can't reproduce it. I tested with ANTLRWorks 1.4.2 as well. See the attached screenshot. Regards, Bart. On Wed, Jun 8, 2011 at 11:23 AM, Olivier Sallou olivier.sal...@irisa.fr wrote: Hi, I have an issue with antlrworks (1.4.2), where for a specific grammar, it requires a whitespace. I upgraded from antlrworks 1.1.7 where the same did not asked for the whitespace. example: '?' string | '%' string ':' percentage=INT | ... string: '' LOWID ''; LOWID: ('a'..'z'|'\-')+; INT : ('0'..'9')+ ; If I call my example rules with: ?\acgt\ it works fine but if I call %\acgt\:30 If fails. At least if I add a whitespace between % and \acgt\, it works: % \acgt\:30 I really can't understand why a whitespace is required here, and only here Thanks for your help Olivier -- gpg key id: 4096R/326D8438 (pgp.mit.edu) Key fingerprint = 5FB4 6F83 D3B9 5204 6335 D26D 78DC 68DB 326D 8438 List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- gpg key id: 4096R/326D8438 (pgp.mit.edu) Key fingerprint = 5FB4 6F83 D3B9 5204 6335 D26D 78DC 68DB 326D 8438 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: 32770] Re: [antlr-interest] Facing NoSuchMethodError:CommonTreeNodeStream.getNodeIndex(obj) after upgrating ANTLR V3.1.1 to ANTLR v3.3
Meena, You appear to be running a v3.1 lexer parser with the run-time classes from v3.3. On Stackoverflow I recommended you generate a new lexer and parser using ANTLR v3.3 (and compile them!) which you can then use with the ANTLR v3.3 runt-time classes. Did you do that already? Bart. On Tue, Jun 14, 2011 at 1:04 PM, meena.subraman...@wipro.com wrote: Hi All, Currently I am using Antlr v3.1.1. Now I have upgraded it to Antlr v3.3 after that I am getting the following error while compiling my java files with the latest version Antlr. I am facing some compilation issues so not able to build. The error message is given below, UnexpectedException occurred: java.lang.NoSuchMethodError: Org.antlr.runtime.CommonTreeNodeStream.getNodeIndex(Ljava/lang/object;) I At *.expressoin.FocusCommonTreeNodeStream.getNodeIndex(FocusCommonTreeNodeS tream.java) Can you please suggest some solution for the above problem? Observation: As per my analysis CommonTreeNodeStream.getNodeIndex(obj) method is present till Antlr jar v3.1.2 but the releases after this version, does not contain the CommonTreeNodeStream.getNodeIndex(obj) method. So obviously v3.3 does not contain the method getNodeIndex(obj) so it is throwing NoSuchMethodError. Can you please clarify, is there any equivalent method available in the v3.3 for getNodeIndex(obj) method? Thanks in Advance!!! Regards, Meena. Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com 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: 32771] Re: [antlr-interest] Facing NoSuchMethodError:CommonTreeNodeStream.getNodeIndex(obj) after upgrating ANTLR V3.1.1 to ANTLR v3.3
Yes, you're running it all with v3.3, but did you generate a new lexer and parser from your grammar using v3.3? Bart. On Tue, Jun 14, 2011 at 1:43 PM, meena.subraman...@wipro.com wrote: Bart, Yes brat, I have did the following to use Antlr v3.3. (we are downloading the ANTLR jars from maven.) 1. I have changed my *pom.xml* as below From : dependency groupIdorg.antlr/groupId artifactIdantlr-runtime/artifactId version3.1.1/version /dependency To : dependency groupIdorg.antlr/groupId artifactIdantlr-complete/artifactId version3.3/version /dependency 2. Rename the jar FROM antlr-3.3-complete TO antlr-complete-3.3 3. Run the below maven command to install the local repository with the new jar. mvn install:install-file -DgroupId=org.antlr -DartifactId=antlr-complete -Dversion=3.3 -Dpackaging=jar -Dfile=local\Path\to\antlr-complete-3.3.jar *4. *Run the below mvn command to compile: *mvn install -DskipTests=true* After following the above steps I got the below error: Build Failure : Compilation Error: NoSuchMethodError….and in the error message it clearly indicates that *getNodeIndex(obj)* Method is missing. Thanks, Meena. *From:* Bart Kiers [mailto:bki...@gmail.com] *Sent:* Tuesday, June 14, 2011 4:38 PM *To:* Meena Subramanian (WT01 - Banking Financial Services) *Cc:* antlr-interest@antlr.org *Subject:* Re: [antlr-interest] Facing NoSuchMethodError:CommonTreeNodeStream.getNodeIndex(obj) after upgrating ANTLR V3.1.1 to ANTLR v3.3 Meena, You appear to be running a v3.1 lexer parser with the run-time classes from v3.3. On Stackoverflow I recommended you generate a new lexer and parser using ANTLR v3.3 (and compile them!) which you can then use with the ANTLR v3.3 runt-time classes. Did you do that already? Bart. On Tue, Jun 14, 2011 at 1:04 PM, meena.subraman...@wipro.com wrote: Hi All, Currently I am using Antlr v3.1.1. Now I have upgraded it to Antlr v3.3 after that I am getting the following error while compiling my java files with the latest version Antlr. I am facing some compilation issues so not able to build. The error message is given below, UnexpectedException occurred: java.lang.NoSuchMethodError: Org.antlr.runtime.CommonTreeNodeStream.getNodeIndex(Ljava/lang/object;) I At *.expressoin.FocusCommonTreeNodeStream.getNodeIndex(FocusCommonTreeNodeS tream.java) Can you please suggest some solution for the above problem? Observation: As per my analysis CommonTreeNodeStream.getNodeIndex(obj) method is present till Antlr jar v3.1.2 but the releases after this version, does not contain the CommonTreeNodeStream.getNodeIndex(obj) method. So obviously v3.3 does not contain the method getNodeIndex(obj) so it is throwing NoSuchMethodError. Can you please clarify, is there any equivalent method available in the v3.3 for getNodeIndex(obj) method? Thanks in Advance!!! Regards, Meena. Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address * Please do not print this email unless it is absolutely necessary. * The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.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
[il-antlr-interest: 32844] Re: [antlr-interest] test release of antlr 3.4
The file `/META-INF/MANIFEST.MF` is missing the 'Main-Class' attribute. Add the line: Main-Class: org.antlr.Tool to the file (inside the JAR) and all should be OK. Regards, Bart. On Mon, Jun 20, 2011 at 6:28 PM, Julien BLACHE j...@jblache.org wrote: A Z asicaddr...@gmail.com wrote: Hi, How is this jar different than 3.2? I tried the same command java -jar antlr-3.4.jar grammar.g but I get an error message: Invalid or corrupt jarfile antlr-3.4.jar Same issue here. It works when invoked this way java -cp antlr-3.4.jar org.antlr.Tool grammar.g I'll leave it up to the Java-literate to investigate/explain/fix ;) (Sun^WOracle Java 1.6.0_26 if it makes any difference) JB. -- Julien BLACHE http://www.jblache.org j...@jblache.org GPG KeyID 0xF5D65169 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: 32878] Re: [antlr-interest] Token Stream Rewriting
Is it _really_ returning a String * private String merge(String s1, List lst, String s2) {* *...* *return ...* * }* ? Not an Object _you think_ is a String: * private Object merge(String s1, List lst, String s2) {* *...* *return ...* * }* ? I ask because the stack-trace you posted: Caused by: java.lang.ClassCastException: java.util.ArrayList seems to suggest it is an ArrayList. Either way: a String or an ArrayList, both are wrong: that method needs to return a Tree. Bart. On Wed, Jun 22, 2011 at 8:39 AM, Fabien Hermenier hermenierfab...@gmail.com wrote: merge(...) is returning a String. Fabien. Le 22/06/11 00:36, Bart Kiers a écrit : Fabien, but what is the return type of this `merge(...)` method? Could you post the method? Or even better: post a SSCCE http://sscce.orgthat causes such an exception? Regards, Bart. On Wed, Jun 22, 2011 at 8:30 AM, Fabien Hermenier hermenierfab...@gmail.com wrote: In fact, I've badly readed the help. So yet, it is running a String that should be tokenized (then translated into tree I suppose) at run time. Le 22/06/11 00:28, Bart Kiers a écrit : Is your `merge(String, List, String)` method returning a java.util.ArrayList instead of a Tree? Regards, Bart. On Wed, Jun 22, 2011 at 8:04 AM, Fabien Hermenier hermenierfab...@gmail.com mailto:hermenierfab...@gmail.com wrote: Hi I have some troubles with token stream rewriting. Below is the piece of ANTLR code. I have a grammar, with an AST as output and Java as the target. I want to insert a sequence of token into the stream. I have followed the page http://www.antlr.org/wiki/display/~admin/2007/06/28/Token+stream+rewriting+with+rewrite+ruleshttp://www.antlr.org/wiki/display/%7Eadmin/2007/06/28/Token+stream+rewriting+with+rewrite+rules http://www.antlr.org/wiki/display/%7Eadmin/2007/06/28/Token+stream+rewriting+with+rewrite+rules and adapted the example that interest me. A piece of the code is following. Basically, in the alternative of 'explodedSet', I get the return values of other rules and do some stuff in the merge method. This one returns a list of String as explained in the online example. explodedSet: '{' (setContent (',' setContent)*)? '}' - ^(EXPLODED_SET setContent+) | {List l = new LinkedList();}LEFTY r1=brace_content{l.add($r1.ret);} (',' r2=brace_content{l.add($r2.ret);})* RIGHTY - { merge($LEFTY.text,l,$RIGHTY.text) }; brace_content returns [List ret]: st=number ('..' ed=number)? {$ret = new LinkedList(); for (int i = $st.val; i = $ed.val; i++) {$ret.add(i);}} | NAME {$ret = new LinkedList(); $ret.add($NAME.text);}; The code compiles well but at runtime, I've got this exception: Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.antlr.runtime.tree.Tree at org.antlr.runtime.tree.BaseTreeAdaptor.addChild(BaseTreeAdaptor.java:107) at Parser.explodedSet(Parser.java:560) So, the return value of merge does not seems to be converted into tokens nor Tree. Does someone has an idea ? Fabien. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- Fabien Hermenier Postdoctoral researcher at Flux http://sites.google.com/site/hermenierfabien/home List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- Fabien Hermenier Postdoctoral researcher at Flux http://sites.google.com/site/hermenierfabien/home 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: 32948] Re: [antlr-interest] ANTLRWorks Interpreter
The interpreter is only suitable for very small grammars (without predicates!). For more complicated grammars, use ANTLRWorks' debugger instead. Regards, Bart. On Sat, Jun 25, 2011 at 10:25 PM, Mike Kappel mkap...@appfluent.com wrote: I just downloaded ANTLRWorks and tried the example expression grammar. I type in a simple expression into the Interpreter and see the generated parse tree. Fine. I then load the SQL 2003 grammar and type in a simple Insert statement. I click the arrow and it never returns from Interpreting (Operation in progress). Can ANTLRWorks handle a more complex grammar? Dr. Michael R. Kappel mkap...@appfluent.commailto:mkap...@appfluent.com 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: 32978] Re: [antlr-interest] Someting about range (to change)
Hi Fabien, Can you post the grammar that produces the error? Bart. On Wed, Jun 29, 2011 at 5:57 AM, Fabien Hermenier hermenierfab...@gmail.com wrote: Hi I am sorry, but this is another problem related to sequence of integer. I don't understand my error(s), despite severals pass on the wiki page related to this use case. I want to parse a string with a sequence parameter into it, such as toto-[2 ..3]-toto. Here is a short version of the grammar that works perfectly: --- grammar tryout; options { k=3; } fragment Digit :'0'..'9'; DEC_NUMBER: '1'..'9' Digit*; fragment Letter:'a'..'z'|'A'..'Z'; WS:('\n'|'\r'|'\t'|' ') {$channel=HIDDEN;}; LEFTY: (Letter|Digit) (Letter|Digit|'-')* '['; RIGHTY: ']' (('-' (Letter|Digit))|Letter|Digit)* ; number :DEC_NUMBER; //HEX_NUMBER, OCT_NUMBER, ... are following but removed for this example. range: LEFTY number '..' number RIGHTY; --- This grammar accepts toto-[1..3]-toto or toto-[1 .. 3]-toto. Now, I want to be able to accept the LEFTY token or the RIGHTY token even if they contains a '.' inside (not at the beginning). So I've modified LEFTY as following: LEFTY: (Letter|Digit) ('.'|Letter|Digit|'-')* '['; Now, ANTLR does no longer accept toto-[1..3]-toto. It requires at least one space between the first number and the range. I have read the wiki page related to range, integer, and so one. But in my case, I don't see where my grammar is ambiguous as no token can start with a '.' . So it seems there is a concept I don't get. Can anyone try to help me ? Thanks in advance, Fabien. 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: 32989] Re: [antlr-interest] rule parameter question
Hi Mark, I presume you didn't see my answer on Stackoverflow: http://stackoverflow.com/questions/6529359/how-to-pass-commontree-parameter-to-an-antlr-rule ? If you did, is there anything that wasn't clear? Regards, Bart. On Thu, Jun 30, 2011 at 2:26 PM, Mark Truluck mark.trul...@cogiton.comwrote: Hello, I am trying to do what I think is a simple parameter passing to a rule in Antlr 3.3: --- grammar rule_params; options { output = AST; } rule_params : outer; outer: outer_id '[' inner[$outer_id.tree] ']'; inner[CommonTree parent]: inner_id '[' ']'; outer_id: '#'! ID; inner_id: '$'! ID ; ID : ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' )* ; - However the inner[CommonTree parent] generates the following: *** inner4=inner((outer_id2!=null?((Object)outer_id2.tree):null)); Resulting in this error: *** The method inner(CommonTree) in the type rule_paramsParser is not applicable for the arguments (Object) As best I can tell, this is the exact same as the example in the Antrl book: classDefinition[CommonTree mod] (Kindle Location 3993) - sorry I don't know the page number but it is in the middle of the book in chapter 9, section labeled Creating Nodes with Arbitrary Actions. Thanks for any help. Mark Truluck COGITON, Inc. 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.