[antlr-interest] how to skip/read next n Characters (n is read form input)

Jim Idle jimi at temporal-wave.com
Thu Nov 15 18:31:16 PST 2012

- I suggest that you take a step back and read through all the examples.
- Read the getting started Wiki articles
- antlr.markmail.org may well be your new friend.
- When you are new to the game, I suggest that you do not use 'literals'
in your parser grammars.
- val=. In a parser will capture every token, not any character, hence it
is not usually useful


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Thomas Ruschival
Sent: Friday, November 16, 2012 4:17 AM
To: cd.barth at t-online.de
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] how to skip/read next n Characters (n is
read form input)

Hi Claus-Dieter,
I am running antlr v3 with anltworks 1.4.3 and java 1.7.0_1.

It seems the problem has 2 aspects.
1st) no list object is created, only declared (List b_list = null;)
2nd) Nothing matches, not (b+=CHAR)+, not (b+=CHAR|DIGIT|'E')+ not even
not (b+=.)+

What really surprised me (remember I am still newbie) is that ANTLR
generates Lexer tokens for characters form parser rules and that these
tokens do no longer match the generic CHAR lexer rule.
For instance the 'C' or 'E' from the grammar below do not match if I
replace (val=.) by (val=CHAR) in the rule print.

Best Regards

I stripped down my grammar to share:

grammar JPosEscape;
    private boolean escBool = false;



escapecmd :
    ( bold
     | underline
     | readNchars

bold :
          escBool = false;
    ('b' 'C')
               System.out.println("Selecting Bold:" + escBool);

underline :
    ullines = (DIGIT)*
          escBool = false;
    ('u' 'C')
               System.out.println("Selecting UNDERLINE:" + escBool +
"using # "+ $ullines.text + "lines");

readNchars :
        b +=  ( CHAR|DIGIT|'E' )
    {$b.size() <= Integer.parseInt($NUMBER.text)}?
readNChars #" + $b.size());

expr :

print :
    ('@' '|') => ('@' '|')
    | (val = . )

Am 15.11.2012 04:46, schrieb cd.barth at t-online.de:
> Hi Thomas,
> the sample from ANTLR v3 reference is not (yet?) running with ANTLR
> (b+=CHAR)+ {$b.size()<=Integer.parseInt($NUM.text)}?
> I see that {System.out.println(((StartContext)_localctx).b.size());}
> is a workaround for the counter but synpred is not working for me too.
> It would be nice getting therefor a solution from Ter in the final
> Regards Claus-Dieter

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

More information about the antlr-interest mailing list