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

Thomas Ruschival thomas at ruschival.de
Wed Oct 31 09:47:00 PDT 2012

I am a humble EE with little grammar experience, please forgive my 
ignorance and give me a hint how professionals would do the trick.

I came up with a grammar for detecting commands "escape-sequences" in a 
input text (for a UnifiedPOS printer)
that reads numbers and boolean argumets for escape sequence commands 
from the input stream.
I can read numeric arguments and use them as function parameters, which 
function to be called is parsed correctly.
For instance "ESC|#rF" means "print feed revers # lines"

The question is how to treat "ESC|#E" which means "send the next # 
bytes untreated to the pinter" in other words:

How can I use a number N that I detected on the input stream to read 
and consume the next N characters
'un-lexed' and 'un-parsed' as string/byte array?

I was thinking using something like this in a parse action using the 
'input' member of the parser:

for (int i=0; i<N; i++){

But it doesn't seem very professional to me. Furthermore this gives me 
tokens and not plain bytes....
Can you give me a hint?

Thanks in advance

More information about the antlr-interest mailing list