Thomas Ruschival
2012-10-31 16:47:00 UTC
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++){
output.append(input.LA(1));
input.consume();
}
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
Thomas
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
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++){
output.append(input.LA(1));
input.consume();
}
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
Thomas
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address