public static ReportData GetReportData(Grammar g)
{
ReportData data = new ReportData();
data.version = Version;
data.gname = g.name;
data.gtype = g.GrammarTypeString;
data.language = (string)g.GetOption("language");
data.output = (string)g.GetOption("output");
if (data.output == null)
{
data.output = "none";
}
string k = (string)g.GetOption("k");
if (k == null)
{
k = "none";
}
data.grammarLevelk = k;
string backtrack = (string)g.GetOption("backtrack");
if (backtrack == null)
{
backtrack = "false";
}
data.grammarLevelBacktrack = backtrack;
int totalNonSynPredProductions = 0;
int totalNonSynPredRules = 0;
ICollection <Rule> rules = g.Rules;
foreach (Rule r in rules)
{
if (!r.Name.StartsWith(Grammar.SynpredRulePrefix, StringComparison.OrdinalIgnoreCase))
{
totalNonSynPredProductions += r.NumberOfAlts;
totalNonSynPredRules++;
}
}
data.numRules = totalNonSynPredRules;
data.numOuterProductions = totalNonSynPredProductions;
int numACyclicDecisions =
g.NumberOfDecisions - g.GetNumberOfCyclicDecisions();
List <int> depths = new List <int>();
int[] acyclicDFAStates = new int[numACyclicDecisions];
int[] cyclicDFAStates = new int[g.GetNumberOfCyclicDecisions()];
int acyclicIndex = 0;
int cyclicIndex = 0;
int numLL1 = 0;
int blocksWithSynPreds = 0;
int dfaWithSynPred = 0;
int numDecisions = 0;
int numCyclicDecisions = 0;
for (int i = 1; i <= g.NumberOfDecisions; i++)
{
Grammar.Decision d = g.GetDecision(i);
if (d.dfa == null)
{
//System.out.println("dec "+d.decision+" has no AST");
continue;
}
Rule r = d.dfa.NFADecisionStartState.enclosingRule;
if (r.Name.StartsWith(Grammar.SynpredRulePrefix, StringComparison.OrdinalIgnoreCase))
{
//System.out.println("dec "+d.decision+" is a synpred");
continue;
}
numDecisions++;
if (BlockHasSynPred(d.blockAST))
{
blocksWithSynPreds++;
}
//if (g.decisionsWhoseDFAsUsesSynPreds.contains(d.dfa))
// dfaWithSynPred++;
if (d.dfa.HasSynPred)
{
dfaWithSynPred++;
}
// NFAState decisionStartState = g.getDecisionNFAStartState(d.decision);
// int nalts = g.getNumberOfAltsForDecisionNFA(decisionStartState);
// for (int alt = 1; alt <= nalts; alt++) {
// int walkAlt =
// decisionStartState.translateDisplayAltToWalkAlt(alt);
// NFAState altLeftEdge = g.getNFAStateForAltOfDecision(decisionStartState, walkAlt);
// }
// int nalts = g.getNumberOfAltsForDecisionNFA(d.dfa.decisionNFAStartState);
// for (int a=1; a<nalts; a++) {
// NFAState altStart =
// g.getNFAStateForAltOfDecision(d.dfa.decisionNFAStartState, a);
// }
if (!d.dfa.IsCyclic)
{
if (d.dfa.IsClassicDFA)
{
int maxk = d.dfa.MaxLookaheadDepth;
//System.out.println("decision "+d.dfa.decisionNumber+" k="+maxk);
if (maxk == 1)
{
numLL1++;
}
depths.Add(maxk);
}
else
{
acyclicDFAStates[acyclicIndex] = d.dfa.NumberOfStates;
acyclicIndex++;
}
}
else
{
//System.out.println("CYCLIC decision "+d.dfa.decisionNumber);
numCyclicDecisions++;
cyclicDFAStates[cyclicIndex] = d.dfa.NumberOfStates;
cyclicIndex++;
}
}
data.numLL1 = numLL1;
data.numberOfFixedKDecisions = depths.Count;
data.mink = depths.DefaultIfEmpty(int.MaxValue).Min();
data.maxk = depths.DefaultIfEmpty(int.MinValue).Max();
data.avgk = depths.DefaultIfEmpty(0).Average();
data.numberOfDecisionsInRealRules = numDecisions;
data.numberOfDecisions = g.NumberOfDecisions;
data.numberOfCyclicDecisions = numCyclicDecisions;
// Map synpreds = g.getSyntacticPredicates();
// int num_synpreds = synpreds!=null ? synpreds.Count : 0;
// data.num_synpreds = num_synpreds;
data.blocksWithSynPreds = blocksWithSynPreds;
data.decisionsWhoseDFAsUsesSynPreds = dfaWithSynPred;
//
// data. = Stats.stddev(depths);
//
// data. = Stats.min(acyclicDFAStates);
//
// data. = Stats.max(acyclicDFAStates);
//
// data. = Stats.avg(acyclicDFAStates);
//
// data. = Stats.stddev(acyclicDFAStates);
//
// data. = Stats.sum(acyclicDFAStates);
//
// data. = Stats.min(cyclicDFAStates);
//
// data. = Stats.max(cyclicDFAStates);
//
// data. = Stats.avg(cyclicDFAStates);
//
// data. = Stats.stddev(cyclicDFAStates);
//
// data. = Stats.sum(cyclicDFAStates);
data.numTokens = g.TokenTypes.Length;
data.DFACreationWallClockTimeInMS = g.DFACreationWallClockTimeInMS;
// includes true ones and preds in synpreds I think; strip out.
data.numberOfSemanticPredicates = g.numberOfSemanticPredicates;
data.numberOfManualLookaheadOptions = g.numberOfManualLookaheadOptions;
data.numNonLLStarDecisions = g.numNonLLStar;
data.numNondeterministicDecisions = g.setOfNondeterministicDecisionNumbers.Count;
data.numNondeterministicDecisionNumbersResolvedWithPredicates =
g.setOfNondeterministicDecisionNumbersResolvedWithPredicates.Count;
data.errors = ErrorManager.GetErrorState().errors;
data.warnings = ErrorManager.GetErrorState().warnings;
data.infos = ErrorManager.GetErrorState().infos;
data.blocksWithSemPreds = g.blocksWithSemPreds.Count;
data.decisionsWhoseDFAsUsesSemPreds = g.decisionsWhoseDFAsUsesSemPreds.Count;
return(data);
}