[il-antlr-interest: 32149] [antlr-interest] Error handeling in antlr 3.2
Hi, I need to report customized error when ever user input does not match our defined rules. Here is my code: grammar second1; @lexer::members { @Override public void reportError(RecognitionException e) { System.out.println(Throwing Exception: + e.getMessage()); displayRecognitionError(getTokenNames(), e); throw new IllegalArgumentException(e); } @Override public void displayRecognitionError(String[] tokenNames, RecognitionException e) { String hdr = getErrorHeader(e); String msg = getErrorMessage(e, tokenNames); System.out.println(hdr + + msg); } } @parser::members { public void reportError(RecognitionException e) { System.out.println(Throwing Exception: + e.getMessage()); displayRecognitionError(getTokenNames(), e); throw new IllegalArgumentException(e); } @Override public void displayRecognitionError(String[] tokenNames, RecognitionException e) { String hdr = getErrorHeader(e); String msg = getErrorMessage(e, tokenNames); System.out.println(hdr + + msg); } private boolean inbounds(Token t, int min, int max, String methodName) { int n = Integer.parseInt(t.getText()); if(n = min n = max) { return true; } else { System.out.println(The range for value accepted by + methodName+ is +min +- + max ); return false; } } } expr : SET attribute EOF; attribute : Value1 int1:integer1[Value1]{ System.out.println(Accepted);} | Value2 integer2 [Value2] { System.out.println(Accepted); } ; exception[int1]: catch[Exception e] {System.out.println(Error Reported for int1);} exception: catch[Exception e] {System.out.println(General error Reported);} integer1 [String methodName] : Int { inbounds($Int, 0,1000,methodName) }? ; integer2 [String methodName] : Int { inbounds($Int, 0,1,methodName) }? ; Int: '0'..'9'+; SET: 'set'; Value1 : 'value'; Value2 : 'value2'; fragment WS : (' ' | '\t') ; But while compiling this code I am getting the following errors: error(100): second1.g:26:22: syntax error: antlr: second1.g:26:22: unexpected token: int1 error(100): second1.g:29:17: syntax error: antlr: second1.g:29:17: unexpected token: : error(100): second1.g:32:10: syntax error: antlr: second1.g:32:10: unexpected token: catch error(100): second1.g:0:0: syntax error: assign.types: AST:0:0: unexpected AST node: end-of-block error(100): second1.g:0:0: syntax error: assign.types: AST:0:0: unexpected end of subtree error(100): second1.g:0:0: syntax error: define: AST:0:0: unexpected AST node: end-of-block error(100): second1.g:0:0: syntax error: define: AST:0:0: unexpected AST node: end-of-block error(100): second1.g:0:0: syntax error: define: AST:0:0: unexpected end of subtree error(106): second1.g:26:27: reference to undefined rule: integer1 error(106): second1.g:27:22: reference to undefined rule: integer2 warning(105): second1.g:27:15: no lexer rule corresponding to token: Value2 warning(105): second1.g:26:15: no lexer rule corresponding to token: Value1 warning(105): second1.g:24:15: no lexer rule corresponding to token: SET What should I do? :( I checked on the link: http://www.antlr.org/blog/antlr3/error.handling.tml , this is how we handle exception in ANTLR 3.x Why is it not working in my case then :( Please help me out. -- Regards Preeti Sharma 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: 32150] [antlr-interest] Interactive processing of input
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. Like my DSL(using ANTLR) should show the following:- 1+2 5 2+5+8 15 6/3 2 etc -- View this message in context: http://antlr.1301665.n2.nabble.com/Interactive-processing-of-input-tp6260368p6260368.html Sent from the ANTLR mailing list archive at Nabble.com. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups il-antlr-interest group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 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: 32152] Re: [antlr-interest] Interactive processing of input
Will this method allow me to process each line in an input file individually. Like if my grammar has multiple rules and I want to process each of these rules individually Something like... say my grammar has following 3 individual parser rules rule1 : rule2 : rule3: ... final : (rule1|rule2|rule3)+; //rest of the lexer and parser rules and my i/o is read input for rule1 show output for rule1 read input for rule3 show output for rule3 read input for rule1 show output for rule1 an so on, until I use something like an EOF(ctrl-z) with the method suggested by you, can I achieve this?...and if so can u plz provide a sample code for the same -- View this message in context: http://antlr.1301665.n2.nabble.com/Interactive-processing-of-input-tp6260368p6260754.html Sent from the ANTLR mailing list archive at Nabble.com. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups il-antlr-interest group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 32154] [antlr-interest] Need pointers for getting comment statements in trees produced by v3 grammer files
Hi, I am currently using .g file (v3) and working on modifying nodes for COMMENT statements for Java codes so that these statements are visible after parsing. I have noticed that the channel for comment statements is Hidden (something like $channel = HIDDEN;), because of which I can't see the COMMENTS of Java code being parsed. If anybody can provide pointers so that COMMENT statements can be seen in the tree generated after parsing, that will be grateful. Regards, Ankit 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: 32155] [antlr-interest] help
Hello. I'm using the latest grammar for PL / SQL. He took her http://www.antlr.org/grammar/list. The language I am using is C #. What changes should be made in this grammar to work correctly with C #? Thanks 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: 32156] Re: [antlr-interest] Need pointers for getting comment statements in trees produced by v3 grammer files
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 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: 32159] [antlr-interest] ST v4 2x faster than v3 in real world test
Hi. I just did speed tests with the new version of ANTLR that uses ST v4 not v3. results here: http://bit.ly/htzS15 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: 32160] [antlr-interest] Context-sensitive lexing and ANTLR v4
I see in an early 2004 workshop that I intended to handle Context-sensitive lexing: http://www.antlr.org/workshop/ANTLR2004/proceedings/ANTLR-3.0-Features.pdf Each parser decision point generates special rule in lexer with possible choices: e.g., (ID|INT) Difficulties “for”, find “fore”must say “missing for, found ID” whitespace The C++ template vs token problem simply disappears; i.e., when lexing ListListint a; nested template has in it. Lexer, without context, cannot know which to pick. Only the parser knows that it expects followed by not token Scott Stanchfield also has some thoughts along these lines http://javadude.com/articles/antlr-context-sensitive-scanner.html I'm glad I wrote that slide because I couldn't remember what the difficulties were with context-sensitive Lexing. keywords are an issue as is white space. If I remember correctly Rats has a predicate in its identifier rule that makes it fail if it finds the id is also a keyword (yep, just checked). For whitespace, it simply scarfs whitespace I think in between rule references maybe. Instead of forcing context-sensitive entry points into the lexer, I think a scannerless parser is simpler to understand conceptually. Rats is very good at combining grammars and it might be fun to come up with a scannerless version of ANTLR. It can be done easily right now by simply passing in characters as tokens and turning on backtracking with memoization. Perhaps I'll try that out. stat : 'return' e ';' | id '=' e ';' {String s = $id.text;} ; id : 'a' | 'b' | 'c' | ... ; e : int ; int : '0' | '1' | '2' ... ; yep, that should work even with that action. There is no notion of a token really. hhm...cool. Ter PS oh crap...I should be preparing to teach in 30 minutes! 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: 32162] [antlr-interest] Sample Context-sensitive Lexer in ANTLR v3
wow. it works. http://www.antlr.org/wiki/display/~admin/2011/04/11/Sample+Context-sensitive+Lexer+in+ANTLR+v3 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.