[antlr-interest] Composite grammar and memoize

Indhu Bharathi indhu.b at s7software.com
Thu Apr 2 10:28:06 PDT 2009


Hi,

It looks like memoize at rule level doesn't work in composite grammar. I 
get the error message '!!!!!!!!! memo array is null for ParserPart.g'. 
'state.ruleMemo' is always null.

Also, it looks like this is a known issue. Has this been fixed or is 
there a workaround?

I tried turning on memoize at grammar level and turn it off in the rules 
that doesn't require it. Even that doesn't seem to work.

Here are the files I used:

LexerPart.g
lexer grammar LexPart;

SET    :    'set'
    ;
       
EQ    :    '='
    ;
   
SEMICOLON   
    :    ';'
    ;
   
COLON
    :    ':'
    ;       
   
LPAREN    :    '('
        ;
       
RPAREN    :    ')'
        ;
   
PLUS
    :    '+'
    ;
   
ID    :    'a'..'z'+
    ;
   
INTLIT    :    '0'..'9'+
    ;
   
WS    :    (' ' | '\t'  | '\r') {$channel = HIDDEN;}
    ;
   



ParserPart.g
parser grammar ParserPart;


s   
options {
    backtrack = true;
    memoize = true;
}
    :    r
    |    expr ID
    ;

r
options {
    backtrack = true;
    memoize = true;
}
    :    expr SEMICOLON
    |    expr COLON
    ;
   
expr
        : LPAREN expr RPAREN
        | INTLIT
        ;
   


Child1.g
grammar Child1;

import LexPart, ParserPart;

@header {
    import java.util.LinkedList;
    import org.antlr.runtime.*;
   
}

test    : PLUS
        ;
       

Any pointers?


Thanks, Indhu



More information about the antlr-interest mailing list