[antlr-interest] Stack overflow error (bug)

Ilia Kantor ilia at obnovlenie.ru
Fri Dec 29 15:11:29 PST 2006


P.S in beginning cause that's general question =)  Can I somehow see parse 
tree without AntlrWorks and special logging statements after each rule ?

=========== Bug report ===============
For (latest built) Antlr 3b6:

The problem appeared in AntlrWorks after I inserted {isNextText("if")}? 
predicate, but antlr still compiled it well.

Later, I added a couple of logger.info("..."); statements you can find in 
text, and the error is now seen w/o antlrworks.


ANTLR Parser Generator  Version 3.0b6 (??)  1989-2007
Exception in thread "main" java.lang.StackOverflowError
        at java.util.HashMap$KeyIterator.<init>(HashMap.java:875)
        at java.util.HashMap$KeyIterator.<init>(HashMap.java:875)
        at java.util.HashMap.newKeyIterator(HashMap.java:889)
        at java.util.HashMap$KeySet.iterator(HashMap.java:921)
        at java.util.HashSet.iterator(HashSet.java:154)
        at 
org.antlr.analysis.DFAState.getGatedPredicatesInNFAConfigurations(DFAState.java:695)
        at 
org.antlr.codegen.CodeGenerator.canGenerateSwitch(CodeGenerator.java:1119)
        at 
org.antlr.codegen.ACyclicDFACodeGenerator.walkFixedDFAGeneratingStateMachine(ACyclicDFACodeGenerator.java:72)
        at 
org.antlr.codegen.ACyclicDFACodeGenerator.walkFixedDFAGeneratingStateMachine(ACyclicDFACodeGenerator.java:146)
        at 
org.antlr.codegen.ACyclicDFACodeGenerator.walkFixedDFAGeneratingStateMachine(ACyclicDFACodeGenerator.java:146)
        at 
org.antlr.codegen.ACyclicDFACodeGenerator.walkFixedDFAGeneratingStateMachine(ACyclicDFACodeGenerator.java:146)
.............. lots lots


============== FULL GRAMMAR ===============

grammar CommonRule;


options {
    output=AST;
   	superClass=CommonRuleParentParser; 
}



@parser::header {
    package grammar.parser;
    
	import grammar.*;	
	import grammar.parser.*;
	import grammar.parser.exception.*;

    import org.apache.log4j.Logger;
    import java.util.Stack;
    import java.util.ArrayList;
}

@rulecatch { }

@parser::members {

    private static Logger logger = Logger.getLogger(CommonRuleParser.class);    

    protected String getTokenName(Token tok) {
    	return tokenNames[tok.getType()];
    }
}



@lexer::header {
    package grammar.parser;	
    import grammar.*;
    
}


LCURL	:	'{';
RCURL	:	'}';

CONTROL	:	 '~';

RULE_CALL
	:	'#';


SEMI:	';';

DOT	:	'.';

MINUS
	:	'-';

GT	:	'>';

SPECIAL_CHAR
	:	'`' | '!' | '@' | '$' | '%' | '^' | '&' | '*' | '(' | ')' |  
	'+' | '=' | '[' | ']' | ':' | '\'' | '"' | '\\' | '|' | ',' | '<' |
	 '/' | '?';
	


fragment WS_CHAR  :
       (' '|'\r'|'\t'|'\u000C'|'\n' )
    ;
    
WS	:	WS_CHAR+;

// not SPECIAL_CHAR not WS_CHAR
WORD:	(~ ('`' | '!' | '@' | '$' | '%' | '^' | '&' | '*' | '(' | ')' |  
	'+' | '=' | '[' | ']' | ':' | '\'' | '"' | '\\' | '|' | ',' | '<' | '/' | '?'
	| '~' 
	| '{' 
	| '}'
	| '#'
	| ';'
	| '.'
	| '-'
	| '>'
	| ' '|'\r'|'\t'|'\u000C'|'\n' ) )+;




document: exprs ;


exprs:
        (expr)+
;

exprs_no_semi
        :       (expr_no_semi)+
;


exprs_simple 
        :       (expr_simple)+
        ;


expr_no_semi 
        :
                (expr_simple) | (curly_block)
        ;

/* expression without curl at start and ; */
expr_simple 
        :
        (
        command |
        rule_call |
        text
        )
;


command:
         CONTROL (
         command_eval |
         command_if  |
         text
         )	
{ 
	logger.info("command"); 
}
;


command_if
       :
       {isNextText("if")}? WORD LCURL exprs /*command_if_part_then 
(command_if_part_else)?*/ RCURL
{ 
	logger.info("command_if"); 
}
;

/*
command_if_part_else returns [String value] :
        (CONTROL ELSE exprs)
{
        $value = $exprs.value;
        logger.info("command_if_else value "+$value);
}
;

command_if_part_then returns [String value]
        :(CONTROL THEN exprs)
{
        $value = $exprs.value;
        logger.info("command_if_then value "+$value);
}
;
*/


command_eval:
        LCURL exprs RCURL
{ 
	logger.info("command_eval"); 
}
      
;




expr:
(
        (expr_no_semi) | (SEMI)
)
;


rule_call: RULE_CALL ( WORD | LCURL WORD rule_long_def_part* RCURL )
;

rule_long_def_part
	:	(MINUS GT | DOT) WORD
	;


curly_block:
        LCURL exprs RCURL
;


text:
	DOT | MINUS | WORD | WS | GT
;




More information about the antlr-interest mailing list