[il-antlr-interest: 27794] [antlr-interest] Question regarding stringtemplate usage design
Hi, I have a antlr parser that is using stringtemplates to translate the input. Im having problems when i want to reorder the output from the input, when this spans multiple rules down. Simplified example: (this is what i have, but its obviously not working) prog: a b=ID - progTempl(a={$a.st}, b={$b.text}); a: x=ID y=ID - aTempl(x={$x.text}, y={$y.text}); I would like the output to be: a.y b a.x So the question is basically, how do i return multiple string from a stringtemplate? Since im using $a.st in the prog rule i get the entire text, but i would want it in 2 chunks. So i can insert b between the 2 chunks. Best Regards Gustaf 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: 27795] Re: [antlr-interest] Question regarding stringtemplate usage design
hi, you'd have to return multiple ST manually with returns [...]. T On Feb 5, 2010, at 2:31 AM, Gustaf Johansson wrote: Hi, I have a antlr parser that is using stringtemplates to translate the input. Im having problems when i want to reorder the output from the input, when this spans multiple rules down. Simplified example: (this is what i have, but its obviously not working) prog: a b=ID - progTempl(a={$a.st}, b={$b.text}); a: x=ID y=ID - aTempl(x={$x.text}, y={$y.text}); I would like the output to be: a.y b a.x So the question is basically, how do i return multiple string from a stringtemplate? Since im using $a.st in the prog rule i get the entire text, but i would want it in 2 chunks. So i can insert b between the 2 chunks. Best Regards Gustaf 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: 27796] [antlr-interest] Why can't I use $stop in an @after action?
I've read and reread the documentation on the $stop attributes of rules, but I can't for the life of me figure out how to use it to get the last matched node. Here's what I want to do: impliedQualifiedName returns [Tree idNode] @after { $idNode = $stop; // I also tried $impliedQualifiedName.stop } : Identifier | ^( BYFIELD qn=impliedQualifiedName Identifier ) ; But I get the error attribute is not a token, parameter, or return value: stop. Instead I have to do: impliedQualifiedName returns [Tree idNode] : Identifier { $idNode = $Identifier; } | ^( BYFIELD qn=impliedQualifiedName Identifier ) { $idNode = $Identifier; } ; What am I doing wrong? Chris 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: 27797] [antlr-interest] Simple Parser Problem?
Hi there, I hope this is not a too simple problem, but I am searching for hours for a solution. The grammar is: headerword :(HEADERWORDCHAR | WORDCHAR) (DIGIT | HEADERWORDCHAR | WORDCHAR)*; DIGIT: '0'..'9' ; WORDCHAR: ('a'..'z' | 'A'..'Z'); HEADERWORDCHAR : ( '$' | '' | '(' | ')' | ',' | '.' | '+' | '[' | ']' | '\''); And everey time I try to match (137394948) or (137394948)7 I get a NoViableAltException. Could anyone explain to me what I am doing wrong here? Cheers, Timm 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: 27800] [antlr-interest] ANTLR v4 thoughts on tree pattern matchers
Hi, I have finished the first semantic error checking phase and have some nice things report about tree pattern matchers: http://www.antlr.org/wiki/display/~admin/Enforcing+semantics Ter 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: 27803] Re: [antlr-interest] Anyone have some good Python examples?
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 -- 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: 27804] Re: [antlr-interest] Real simple grammar - newbie help?!
Hi James, I don't think this grammar is that simple. This is not a context-free grammar: The meaning of '.' depends on what follows it. In other words when the Lexer looks at the dot in '.NET' you expect a KEYWORD production, but when it sees the dot in 'work.' you expect no token. This is a problem. Can you redesign this language? Cheers ./m James Crowley wrote: hey guys, I've got a really simple grammar that I'm trying to get working, but failing miserably at the moment. Would really appreciate some pointers on this... root : (keyword|ignore)*; keyword : KEYWORD; ignore : IGNORE; KEYWORD : ABBRV|WORD; fragment WORD : ALPHA+; fragment ALPHA : 'a'..'z'|'A'..'Z'; fragment ABBRV : WORD?('.'WORD); IGNORE : .{ Skip(); }; With the following test input: some ASP.NET and .NET stuff. that work. I'm wanting a tree that is just a list of keyword nodes, some, ASP.NET, and, .NET, stuff, that, work At the moment I get some, ASP.NET, and, .NET, stuff. that, (for some reason . appears within the last keyword, and it misses work If I change the ABBRV clause to fragment ABBRV : ('.'WORD); then that works fine, but I get keyword (asp) and keyword (.net) - seperately - but I need them as a single token. Any help you can give would be much appreciated. Many thanks James List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately. 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: 27806] Re: [antlr-interest] Real simple grammar - newbie help?!
Hi Michael, Thanks for the response. Sadly not - the language is English ;-) But just hoping to do some basic tokenization of paragraphs of text (essentially just extracting keywords) - thought it would be faster/easier to use a tool like ANTLR than using regex or attempting to roll my own. Am I being foolish for even attempting this? James On 5 February 2010 21:29, Michael Matera mike.mat...@xilinx.com wrote: Hi James, I don't think this grammar is that simple. This is not a context-free grammar: The meaning of '.' depends on what follows it. In other words when the Lexer looks at the dot in '.NET' you expect a KEYWORD production, but when it sees the dot in 'work.' you expect no token. This is a problem. Can you redesign this language? Cheers ./m James Crowley wrote: hey guys, I've got a really simple grammar that I'm trying to get working, but failing miserably at the moment. Would really appreciate some pointers on this... root : (keyword|ignore)*; keyword : KEYWORD; ignore : IGNORE; KEYWORD : ABBRV|WORD; fragment WORD : ALPHA+; fragment ALPHA : 'a'..'z'|'A'..'Z'; fragment ABBRV : WORD?('.'WORD); IGNORE : .{ Skip(); }; With the following test input: some ASP.NET and .NET stuff. that work. I'm wanting a tree that is just a list of keyword nodes, some, ASP.NET, and, .NET, stuff, that, work At the moment I get some, ASP.NET, and, .NET, stuff. that, (for some reason . appears within the last keyword, and it misses work If I change the ABBRV clause to fragment ABBRV : ('.'WORD); then that works fine, but I get keyword (asp) and keyword (.net) - seperately - but I need them as a single token. Any help you can give would be much appreciated. Many thanks James List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately. 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: 27809] Re: [antlr-interest] ANTLR Lexer stops reading the file
OK. I understood, even though i have been looking at the generated token EOF in the source code, never thought of using it directly. On Fri, Feb 5, 2010 at 5:16 PM, Gokulakannan Somasundaram gokul...@gmail.com wrote: Jim, No i haven't used EOF anywhere explicitly. Is that the reason for the lexing to stop? Thanks, Gokul. On Thu, Feb 4, 2010 at 8:00 PM, Jim Idle j...@temporal-wave.com wrote: Does your parsing rule end in EOF? Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Gokulakannan Somasundaram Sent: Thursday, February 04, 2010 6:19 AM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] ANTLR Lexer stops reading the file I found the problem. It was a semicolon, at the end of the line, that i missed to match in the rule. It stopped the lexing without emitting an error. Is it an expected behavior? Gokul. On Thu, Feb 4, 2010 at 7:22 PM, Gokulakannan Somasundaram gokul...@gmail.com wrote: Hi, I am faced with a problem, where in some of the statements that have to get parsed are not getting parsed. When i tried the remote debugging, it is saying the input has terminated, whereas there are further lines in the file to be read and parsed. I am attaching the source of the Lexer, Parser(with Templates) and the input file and Main.java. I tried remote debugging the stuff and the tokens are not getting generated after a point. In the input file test.bdf, there is a portion like this dclform THROBBER_SERVLET001: loading := true; */* Things are terminating here */* THROBBER_SERVLET002: loading := true; Can anyone help me on this? When i ran it like java Main test.bdf, i am facing this issue. Thanks, Gokul. 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.