Fwd: [antlr-interest] Cobol number question

Jose Ventura jose.ventura.roda at gmail.com
Thu Apr 6 00:30:07 PDT 2006


I'm working in a parser for cobol grammar too. I don't have the better
solutions for the problem what I was found, but ...


PUNTO
 : {!ultPic }?
   '.' {_ttype = FIN_TODO;}
   (
    (DIGITO)+ {_ttype=NUM;}
    )?
  ;

This rule have the definition of number, ident, lit_pic (literal after PIC
word)


IDENT_NUM  options {testLiterals=true;}
 :{ ultPic }?
('+'|'-'|'$'|'b'|','|'e'|('0'..'9')|'x'|'s'|'v'|'z'|'*'|'('|')'|
                {LA(2)!=' '&&LA(2)!='\n'&&LA(2)!='\r'}? '.')+
  {$setType (LIT_PIC);}
 |('x' '\'') => 'x' '\''( ~('\''|'\n'|'\r'|'\t') )* '\''
  {$setType (LIT_HEXADECIMAL);}
 | LETRA (LETRA|DIGITO|'-'|'_')*
  {String s = $getText;
   if (s.equals("IS"))
    $setType(Token.SKIP);
   else
    $setType(IDENT);
  }
 |((DIGITO)+ (LETRA|'-'|'_')) =>(DIGITO)+ (LETRA|'-'|'_')
(LETRA|DIGITO|'-'|'_')*
  {$setType (IDENT);}
 |((DIGITO)+ '/' )=> (DIGITO)+ '/' (DIGITO|'/')+
  {$setType (FECHA);}
 | (DIGITO)+  ({LA(2)!=' '&&LA(2)!='\n'&&LA(2)!='\r'}? ',' (DIGITO)+)?
  {$setType (NUM);}
 | '_' (LETRA|DIGITO|'_')*
  {$setType (IDENT);}
 ;
I believe you must to use predicates also  {LA(2)!='
'&&LA(2)!='\n'&&LA(2)!='\r'}? '.' for know the element after the point.

I hope this could help you.
Regards,
José Ventura.

---------- Forwarded message ----------
From: Putrycz, Erik <Erik.Putrycz at nrc-cnrc.gc.ca>
Date: 06-abr-2006 1:48
Subject: [antlr-interest] Cobol number question
To: antlr-interest at antlr.org

 I'm currently working on a COBOL grammar and I'm stuck with the following
case:

COMPUTE M-INTEREST = INTEREST / 12.

The DOT at the end is the end of the instruction not a decimal dot.

I based my grammar on the python one (that has nice indentation handling)
and my numbers rule is the following:

NUMBER

            :

            (           NonZeroDigit (Int)?

                        (           FloatTrailer {$setType(FLOAT);}

                                    |           {$setType(INT);}

                        )

            )

    |   '.' {$setType(DOT);} // DOT (non number; e.g., field access)

            ;



protected

FloatTrailer

            :           '.' Int

            ;



The FloatTrailer fails with unexpected char: 0xA at the end of the line…
Obviously the second alternative of the NUMBER is not considered… I'm not
sure how to handle this properly. I would like to keep in the parser that
the instruction ends with a DOT.



Anyone would have an idea?



Thanks,



*Erik** **Putrycz**, **Ph.D** - Research Associate / **
erik.putrycz at nrc-cnrc.gc.ca* <erik.putrycz at nrc-cnrc.gc.ca>* / **(613) 990
0681*

Institute for Information Technology - Software Engineering Group

National Research Council, Canada - Building M-50, 1200 Montreal Road

Ottawa, Ontario, CANADA K1A 0R6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060406/6973f7c5/attachment-0001.html


More information about the antlr-interest mailing list