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

Robert Colquhoun rjc at trump.net.au
Fri May 14 06:25:15 PDT 2004


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

<*> 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