[antlr-interest] Antwort: RE: Interactive interpreter and line continuationcharacters
lars.vonwedel at bayertechnology.com
lars.vonwedel at bayertechnology.com
Tue Oct 28 06:50:31 PDT 2008
Thanks a lot, that worked out very well !
Freundliche Grüße / Best Regards
Lars von Wedel
_________________________________________
Bayer Technology Services GmbH
"Sam Harwell" <sharwell at pixelminegames.com>
23.10.2008 18:26
An
<lars.vonwedel at bayertechnology.com>, <antlr-interest at antlr.org>
Kopie
Thema
RE: [antlr-interest] Interactive interpreter and line
continuationcharacters
Keep a flag (bool) in the lexer that sets whether or not the input it was
fed (could be multiple lines) represents a complete statement. Make sure
that the lexer can lex a single line without bombing ? you should have a
rule similar to the one below. After enter is pressed, lex the input from
the start of the current statement (not line) through the end of the last
line of the statement entered. Then check the lexer?s statement completed
flag; if true send the input to the parser, otherwise discard those
results and wait for another line of text to be entered. Since an
interactive shell?s individual lexer inputs are short, there will be
little overhead for repeatedly lexing the lines of a multi-line input.
// Very last rule of the lexer to stop troublesome NoViableAltException
ANYCHAR
: .
;
Sam
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of
lars.vonwedel at bayertechnology.com
Sent: Thursday, October 23, 2008 5:18 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Interactive interpreter and line
continuationcharacters
Hello,
I am trying to build an interactive interpreter shell for an application.
A simple approach is obviously to read a line from the command line and
send it to the lexer/parser. However, the input language permits line
continuation by special characters. If a line ends with a ';' or ',' it is
supposed to be continued on the next line.
To make things worse, some valid statements can end with multiple ','
characters. In this case, a special statement termination character '!' is
used(and can be followed by arbitrary input to be disregarded).
My current line of thinking is to send a line entered by the user to the
lexer, let it skip anything beyond '!' and then look at the last token. If
that is a ';' or ',' then obtain another line and concatenate the token
streams before actually running the parser.
Are there any better ideas how to deal with this ?
Freundliche Grüße / Best Regards
Lars von Wedel
_________________________________________
Bayer Technology Services GmbH
E-mail: lars.vonwedel at bayertechnology.com
Web: www.bayertechnology.com
Geschäftsführer: Achim Noack
Aufsichtsratsvorsitzender: Dr. Wolfgang Plischke
Sitz der Gesellschaft: Leverkusen | Eintragung: Amtsgericht Köln, HRB
49896
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081028/7c51cdd0/attachment.html
More information about the antlr-interest
mailing list