[antlr-interest] Tree rewriting (filter=true, output=ast)

Sam Barnett-Cormack s.barnett-cormack at lancaster.ac.uk
Sat Mar 21 16:45:08 PDT 2009


Gavin Lambert wrote:

> valueListValue
> scope { bool hasOther; bool hasNameNum; }
> @init { $valueListValue::hasOther = false; $valueListValue::hasNameNum =
> false; }
>   : ^(VLIST
>     ( v+=nameAndNumberForm { $valueListValue::hasNameNum = true; }
>     | (v+=externalValueReference | v+=LCID | v+=NUMBER)
>     | . { $valueListValue::hasOther = true; }
>     )+
>     ( { $valueListValue::hasNameNum && $valueListValue::hasOther) }? {
> raise error; }
>     | { $valueListValue::hasNameNum }? -> ^(OBJID $v+)
>     )?
>   ;
> 
> (I'm a little unsure about the specific syntax for that last bit.  But I
> think something like that ought to do the trick.)
> 

On a separate note, trying to compile the tree grammar with these
adjustments doesn't give me any antlr errors, but it does seem to
produce a java exception. Here's the report output (generated by default
by antlr-IDE in Eclipse):

ANTLR Grammar Report; Stats Version 4
Grammar: ASN_1_tree_pass1
Type: tree
Target language: Java
Output: AST
Grammar option k: none
Grammar option backtrack: false
Rules: 5
Productions: 5
Decisions: 3
Cyclic DFA decisions: 0
LL(1) decisions: 1
Min fixed k: -1
Max fixed k: 5
Average fixed k: 1.6666666666666667
Standard deviation of fixed k: 3.055050463303893
Min acyclic DFA states: 0
Max acyclic DFA states: 15
Average acyclic DFA states: 6.666666666666667
Standard deviation of acyclic DFA states: 7.637626158259733
Total acyclic DFA states: 20
Min cyclic DFA states: 0
Max cyclic DFA states: 0
Average cyclic DFA states: 0.0
Standard deviation of cyclic DFA states: 0.0
Total cyclic DFA states: 0
Vocabulary size: 170
DFA creation time in ms: 14
Number of semantic predicates found: 2
Number of manual fixed lookahead k=value options: 0
Number of nondeterministic decisions: 2
Number of nondeterministic decisions resolved with predicates: 1
Number of DFA conversions terminated early: 0
Number of errors: 0
Number of warnings: 0
Number of infos: 0
Number of syntactic predicates found: 0
Decisions with syntactic predicates: 0
Decision DFAs using syntactic predicates: 0
Decisions with semantic predicates: 1
Decision DFAs using semantic predicates: 0
Backtracking report:
Number of decisions that backtrack: 0

Grammar: ASN_1_tree_pass1
Error creating resources for ASN_1. Cause java.lang.ClassCastException:
org.antlr.stringtemplate.StringTemplate cannot be cast to java.util.List


It's that bit at the bottom that bothers me. This should be ANTLR 3.1.2.

Sam

PS: I'm intrigued by the fact the k=-1 in some cases, though.


More information about the antlr-interest mailing list