[antlr-interest] Lexing colons again (consume and getColumn)

Anthony Youngman Anthony.Youngman at ECA-International.com
Fri May 14 07:54:28 PDT 2004


Hi Rob.

Cracked it! It looks like the bit of code you quoted was lifted pretty
much from your grammar ... but I was correct in saying "consume" added
the consumed token to the text. And the reason I was seeing it was
because the label "123" matches the INT rule, not the IDENT rule. Your
get/set length code was never getting touched because of the "start in
column 1" guard rule I'd implemented.

Anyway, I've now modified my INT rule to add a colon if it's a label and
there's no colon, and I've taken out the get and set length lines in the
IDENT rule. That means all user-defined labels must, internally, end in
colons (so I'll have to fix GOTO and GOSUB to add them if the user
doesn't :-). And all my internally generated labels don't end in a colon
so I'm guaranteed separate namespaces :-)

So here's to GOTO, and then on to argument lists. And isn't there a
function that uses ';' instead of ',' somewhere? Yuck :-(

Anyway, what's wrong with COBOL (which I've never used?). It's far
better than spaghetti (if you're programming, that is), though not
better than pizzas in most peoples' minds, I expect :-) As I said, the
Pr1me rule is "implement the good stuff, not the braindead stuff :-)

Cheers,
Wol

-----Original Message-----
From: Robert Colquhoun [mailto:rjc at trump.net.au] 
Sent: 14 May 2004 14:25
To: antlr-interest at yahoogroups.com
Subject: RE: [antlr-interest] Lexing colons again (consume and
getColumn)

Hello Anthony,

At 10:45 PM 14/05/2004, Anthony Youngman wrote:
>It probably is familiar ... although I don't think I've literally
copied
>anything.
>
>As for "is truncated to the original length dropping the trailing
>colon", why then does my tracking code in the parser (this code is in
>the lexer) still have the colon as part of the text? The parser
displays
>the label text as "123:" or "456", which matches exactly what I've got
>in my source. (Actually, I might decide to go the other way, and
>forcibly add a colon, but that's going to be fun too :-)

You did not show the whole rule, you must have done something further
down.

Perhaps insert a before and after print statement ie
         if (state == STATEMENT) {
                 if (LA(1) == ':' && getColumn() == 1) {
                                 System.err.println("text = " + text);
                                 int len=text.length();
                                 consume();
                                 text.setLength(len);
                                 System.err.println("text = " + text);
                                 _ttype = LABEL;


>And reading the UniVerse manual on labels it says "A statement label
can
>be put either in front of a BASIC statement or on its own line. The
>label must be first on the line - that is it cannot start with a
space."
>
>I read that as that a label MUST start in column 1 of a line ...
>(although I admit it is ambiguous).

Its up to you, if you want to reinvent cobol go right ahead...;-)

If you really want to use getColumn(), then you will need to subtract
off 
the matched token length

ie getColumn() - $getText.length() == 1

>If other MVBasics allow labels in the middle of a line, I don't care.
>None of the ones I know permit it ... And I'm inclined to follow the
>Pr1me engineering philosopy - if it don't make sense, leave it out.
Like
>I intend to do with implicit formats! If someone else wants it bad
>enough, they can add it themselves :-)

Labels at the beginning of any logical  line and the implicit format are

both supported in the grammar i linked previously.

  - Robert



 
Yahoo! Groups Links



 





****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list