--- antlr3-3.5.3/tool/src/main/antlr3/org/antlr/grammar/v3/CodeGenTreeWalker.g 2023-09-15 20:06:39.620275234 +0200 +++ antlr3-3.5.3/tool/src/main/antlr3/org/antlr/grammar/v3/CodeGenTreeWalker.g 2023-09-16 06:38:17.929360459 +0200 @@ -53,9 +53,10 @@ import org.antlr.tool.*; import org.antlr.codegen.*; -import java.util.HashSet; +import java.util.TreeSet; import java.util.Set; import java.util.Collection; +import java.util.Collections; import org.antlr.runtime.BitSet; import org.antlr.runtime.DFA; import org.stringtemplate.v4.ST; @@ -73,7 +74,7 @@ protected ST currentBlockST = null; protected boolean currentAltHasASTRewrite = false; protected int rewriteTreeNestingLevel = 0; -protected HashSet rewriteRuleRefs = null; +protected TreeSet rewriteRuleRefs = null; public String getCurrentRuleName() { return currentRuleName; @@ -284,6 +285,7 @@ } labels.add( label ); } + Collections.sort(labels); // ensure reproducible order return labels; } @@ -1236,7 +1236,7 @@ } : ^( REWRITES ( - {rewriteRuleRefs = new HashSet();} + {rewriteRuleRefs = new TreeSet();} ^( r=REWRITE (pred=SEMPRED)? alt=rewrite_alternative) { rewriteBlockNestingLevel = OUTER_REWRITE_NESTING_LEVEL; --- antlr3-3.5.3/tool/src/main/java/org/antlr/codegen/ACyclicDFACodeGenerator.java 2023-09-15 20:06:39.623608500 +0200 +++ antlr3-3.5.3/tool/src/main/java/org/antlr/codegen/ACyclicDFACodeGenerator.java 2023-09-16 06:04:09.530338104 +0200 @@ -33,6 +33,7 @@ import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; +import java.util.Collections; import java.util.List; public class ACyclicDFACodeGenerator { @@ -114,6 +115,7 @@ // If the template wants all the label values delineated, do that if ( edgeST.impl.formalArguments.get("labels")!=null ) { List labels = edge.label.getSet().toList(); + Collections.sort(labels); List targetLabels = new ArrayList(labels.size()); for (int j = 0; j < labels.size(); j++) { Integer vI = labels.get(j); --- antlr3-3.5.3/tool/src/main/java/org/antlr/codegen/CodeGenerator.java 2023-09-15 20:06:39.623608500 +0200 +++ antlr3-3.5.3/tool/src/main/java/org/antlr/codegen/CodeGenerator.java 2023-09-16 06:02:44.522033399 +0200 @@ -587,6 +588,7 @@ BitSet bits = BitSet.of(follow.tokenTypeSet); words = bits.toPackedArray(); tokenTypeList = follow.tokenTypeSet.toList(); + Collections.sort(tokenTypeList); } // use the target to convert to hex strings (typically) String[] wordStrings = new String[words.length];