[antlr-interest] COBOL
Sinan
sinan.karasu at boeing.com
Wed May 29 08:55:03 PDT 2002
Balvinder Singh wrote:
>
> Hi all,
>
> I'm writing cobol parser only for WORKING STORAGE AREA of data division.
> I'm using grammar rule and lexical rule for WORKING STORAGE AREA from VS
> COBOL II (http://adam.wins.uva.nl/~x/grammars/vs-cobol-ii/)
>
> I have converted lexical rule to ANTLR format, but I'm getting conflicts for
> some of the rules, rules are as follows :
>
> Literal : NonNumeric | Numeric
> ;
>
> protected
> NonNumeric : '"' ( (~'"') | '"' '"' )* '"'
> | '\'' ( (~'\'') | '\'' '\'')* '\''
> | ('X' 'x') '"' HexDigits '"'
> | ('X' 'x') '\'' HexDigits '\''
> ;
Factor this:
NonNumeric : '"' ( (~'"') | '"' '"' )* '"'
| '\'' ( (~'\'') | '\'' '\'')* '\''
| ('X' 'x')( '"' HexDigits '"' | '\'' HexDigits '\'')
;
> AphabeticUserDefinedWord : (('0'.. '9')+ ('-')*)* ('0' .. '9')* ('A' ..
> 'Z' 'a' .. 'z') ('A' .. 'Z' 'a' .. 'z' '0' .. '9')* (('-')+ ('A' .. 'Z' 'a'
> .. 'z' '0' .. '9')+)*
> ;
This is infinite lookahead. since you can have 9- , 99- etc...
Fix it by saying
AphabeticUserDefinedWord : ((('0'.. '9')+ ('-')*)=> ('0'.. '9')+
('-')*)* ('0' .. '9')* ('A' ..
'Z' 'a' .. 'z') ('A' .. 'Z' 'a' .. 'z' '0' .. '9')* (('-')+ ('A' .. 'Z'
'a'
.. 'z' '0' .. '9')+)*
;
Sinan
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list