[antlr-interest] output unparsed code

Jim Idle jimi at temporal-wave.com
Wed Jun 13 01:13:58 PDT 2012


firstrule: body EOF ;



Will force ANTLR to keep going, but I doubt that you will have much success
with .* EOL as the .* will make any rule with optional trailing tokens
immediately preceding the EOL ambiguous. However, if you put that at the
end, you might make it work given that you are including the EOL



firstrule: body* EOF ;



body

: b1part1 b1part2 b1part3? cleaneol

| b2part1 b2part2 cleaneol

;



cleaneol

: ( t=. {System.out.println($t.text); /* or something */})* EOL

;



Depending on your rules, you might be able to do  (body? cleaneol)* EOF and
take cleaneol out of body.



Jim



-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:
antlr-interest-bounces at antlr.org] On Behalf Of Corina Herman
Sent: Wednesday, June 13, 2012 2:50 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] output unparsed code



Hello everybody!



I'm new to ANTRL and I'm trying to define a grammar for some specific
sentences and outputed as tree in C sharp. My problem is that when the
parser receives a phrase that doesn't fit to any rules I defined it simply
stops, I would like to go further meaning to output the line as it is
without transformation and going to the next sentence in the input.



I tried to add in my grammar at the end something like this, meaning no
matter what else it gets to put an unknown node in the tree but it's not
working.

unknown : .* EOL -> ^(UNKNOWN);



I also tried to figured out (with no succes) a way to complete this task in
generated lexer and parser.



Can you give me a hint or what should I do? Thank you in advance.



Corina Herman



List: http://www.antlr.org/mailman/listinfo/antlr-interest

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


More information about the antlr-interest mailing list