Close
jGuru Forums
Posted By: Robert_Paterson Posted On: Friday, November 21, 2003 06:45 AM
I'm trying to develop a lexer for Oracle 9i PL/SQL.
I'm struggling with the lexical rule for PL/SQL numbers. My grammar works for all examples except for a real number that starts with a decimal point, e.g. .123 . All my attempts to cater for this run into ambiguity problems with the component selector operator ('.') and the range operator ('..').
Can anyone tell me what I should 'tweak' in this grammar thatI've adapted from the ADA one on the Antlr site.
************************************************ NUMBER : ( DIGIT )+ ( { LA(2)!='.' && LA(3)!='.' }? ( '.' ( DIGIT )* ( EXPONENT )? | EXPONENT ) )? ; protected EXPONENT : ('e') ('+'|'-')? ( DIGIT )+ ; // a couple protected methods to assist in matching the various numbers protected DIGIT : ( '0'..'9' ) ; // Operators COMPSEL : '.' ; RANGE : ".." ; ******************************************* From the PL/SQL User Guide and Reference: "Two kinds of numeric literals can be used in arithmetic expressions: integers and reals. An integer literal is an optionally signed whole number without a decimal point. Some examples follow: 030 6 -14 0 +32767 A real literal is an optionally signed whole or fractional number with a decimal point. Several examples follow: 6.6667 0.0 -12.0 3.14159 +8300.00 .5 25. PL/SQL considers numbers such as 12.0 and 25. to be reals even though they have integral values."
Re: PL/SQL Numbers
Posted By: Monty_Zukowski Posted On: Monday, November 24, 2003 08:25 AM