⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profiler.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		System.out.println("rewind @ index "+stopIndex);		int depth = stopIndex - startingIndex.intValue();		System.out.println("depth of lookahead for synpred: "+depth);		decisionMaxSynPredLookaheads.add(			new Integer(depth)		);	}	*/	public void recognitionException(RecognitionException e) {		numberReportedErrors++;	}	public void semanticPredicate(boolean result, String predicate) {		if ( inDecision() ) {			numSemanticPredicates++;		}	}	public void terminate() {		String stats = toNotifyString();		Stats.writeReport(RUNTIME_STATS_FILENAME,stats);		System.out.println(toString(stats));	}	public void setParser(DebugParser parser) {		this.parser = parser;	}	// R E P O R T I N G	public String toNotifyString() {		TokenStream input = parser.getTokenStream();		for (int i=0; i<input.size()&&lastTokenConsumed!=null&&i<=lastTokenConsumed.getTokenIndex(); i++) {			Token t = input.get(i);			if ( t.getChannel()!=Token.DEFAULT_CHANNEL ) {				numHiddenTokens++;				numHiddenCharsMatched += t.getText().length();			}		}		numCharsMatched = lastTokenConsumed.getStopIndex() + 1;		decisionMaxFixedLookaheads = trim(decisionMaxFixedLookaheads, numFixedDecisions);		decisionMaxCyclicLookaheads = trim(decisionMaxCyclicLookaheads, numCyclicDecisions);		StringBuffer buf = new StringBuffer();		buf.append(Version);		buf.append('\t');		buf.append(parser.getClass().getName());		buf.append('\t');		buf.append(numRuleInvocations);		buf.append('\t');		buf.append(maxRuleInvocationDepth);		buf.append('\t');		buf.append(numFixedDecisions);		buf.append('\t');		buf.append(Stats.min(decisionMaxFixedLookaheads));		buf.append('\t');		buf.append(Stats.max(decisionMaxFixedLookaheads));		buf.append('\t');		buf.append(Stats.avg(decisionMaxFixedLookaheads));		buf.append('\t');		buf.append(Stats.stddev(decisionMaxFixedLookaheads));		buf.append('\t');		buf.append(numCyclicDecisions);		buf.append('\t');		buf.append(Stats.min(decisionMaxCyclicLookaheads));		buf.append('\t');		buf.append(Stats.max(decisionMaxCyclicLookaheads));		buf.append('\t');		buf.append(Stats.avg(decisionMaxCyclicLookaheads));		buf.append('\t');		buf.append(Stats.stddev(decisionMaxCyclicLookaheads));		buf.append('\t');		buf.append(numBacktrackDecisions);		buf.append('\t');		buf.append(Stats.min(toArray(decisionMaxSynPredLookaheads)));		buf.append('\t');		buf.append(Stats.max(toArray(decisionMaxSynPredLookaheads)));		buf.append('\t');		buf.append(Stats.avg(toArray(decisionMaxSynPredLookaheads)));		buf.append('\t');		buf.append(Stats.stddev(toArray(decisionMaxSynPredLookaheads)));		buf.append('\t');		buf.append(numSemanticPredicates);		buf.append('\t');		buf.append(parser.getTokenStream().size());		buf.append('\t');		buf.append(numHiddenTokens);		buf.append('\t');		buf.append(numCharsMatched);		buf.append('\t');		buf.append(numHiddenCharsMatched);		buf.append('\t');		buf.append(numberReportedErrors);		buf.append('\t');		buf.append(numMemoizationCacheHits);		buf.append('\t');		buf.append(numMemoizationCacheMisses);		buf.append('\t');		buf.append(numGuessingRuleInvocations);		buf.append('\t');		buf.append(numMemoizationCacheEntries);		return buf.toString();	}	public String toString() {		return toString(toNotifyString());	}	protected static String[] decodeReportData(String data) {		String[] fields = new String[NUM_RUNTIME_STATS];		StringTokenizer st = new StringTokenizer(data, "\t");		int i = 0;		while ( st.hasMoreTokens() ) {			fields[i] = st.nextToken();			i++;		}		if ( i!=NUM_RUNTIME_STATS ) {			return null;		}		return fields;	}	public static String toString(String notifyDataLine) {		String[] fields = decodeReportData(notifyDataLine);		if ( fields==null ) {			return null;		}		StringBuffer buf = new StringBuffer();		buf.append("ANTLR Runtime Report; Profile Version ");		buf.append(fields[0]);		buf.append('\n');		buf.append("parser name ");		buf.append(fields[1]);		buf.append('\n');		buf.append("Number of rule invocations ");		buf.append(fields[2]);		buf.append('\n');		buf.append("Number of rule invocations in \"guessing\" mode ");		buf.append(fields[27]);		buf.append('\n');		buf.append("max rule invocation nesting depth ");		buf.append(fields[3]);		buf.append('\n');		buf.append("number of fixed lookahead decisions ");		buf.append(fields[4]);		buf.append('\n');		buf.append("min lookahead used in a fixed lookahead decision ");		buf.append(fields[5]);		buf.append('\n');		buf.append("max lookahead used in a fixed lookahead decision ");		buf.append(fields[6]);		buf.append('\n');		buf.append("average lookahead depth used in fixed lookahead decisions ");		buf.append(fields[7]);		buf.append('\n');		buf.append("standard deviation of depth used in fixed lookahead decisions ");		buf.append(fields[8]);		buf.append('\n');		buf.append("number of arbitrary lookahead decisions ");		buf.append(fields[9]);		buf.append('\n');		buf.append("min lookahead used in an arbitrary lookahead decision ");		buf.append(fields[10]);		buf.append('\n');		buf.append("max lookahead used in an arbitrary lookahead decision ");		buf.append(fields[11]);		buf.append('\n');		buf.append("average lookahead depth used in arbitrary lookahead decisions ");		buf.append(fields[12]);		buf.append('\n');		buf.append("standard deviation of depth used in arbitrary lookahead decisions ");		buf.append(fields[13]);		buf.append('\n');		buf.append("number of evaluated syntactic predicates ");		buf.append(fields[14]);		buf.append('\n');		buf.append("min lookahead used in a syntactic predicate ");		buf.append(fields[15]);		buf.append('\n');		buf.append("max lookahead used in a syntactic predicate ");		buf.append(fields[16]);		buf.append('\n');		buf.append("average lookahead depth used in syntactic predicates ");		buf.append(fields[17]);		buf.append('\n');		buf.append("standard deviation of depth used in syntactic predicates ");		buf.append(fields[18]);		buf.append('\n');		buf.append("rule memoization cache size ");		buf.append(fields[28]);		buf.append('\n');		buf.append("number of rule memoization cache hits ");		buf.append(fields[25]);		buf.append('\n');		buf.append("number of rule memoization cache misses ");		buf.append(fields[26]);		buf.append('\n');		buf.append("number of evaluated semantic predicates ");		buf.append(fields[19]);		buf.append('\n');		buf.append("number of tokens ");		buf.append(fields[20]);		buf.append('\n');		buf.append("number of hidden tokens ");		buf.append(fields[21]);		buf.append('\n');		buf.append("number of char ");		buf.append(fields[22]);		buf.append('\n');		buf.append("number of hidden char ");		buf.append(fields[23]);		buf.append('\n');		buf.append("number of syntax errors ");		buf.append(fields[24]);		buf.append('\n');		return buf.toString();	}	protected int[] trim(int[] X, int n) {		if ( n<X.length ) {			int[] trimmed = new int[n];			System.arraycopy(X,0,trimmed,0,n);			X = trimmed;		}		return X;	}	protected int[] toArray(List a) {		int[] x = new int[a.size()];		for (int i = 0; i < a.size(); i++) {			Integer I = (Integer) a.get(i);			x[i] = I.intValue();		}		return x;	}	/** Get num hidden tokens between i..j inclusive */	public int getNumberOfHiddenTokens(int i, int j) {		int n = 0;		TokenStream input = parser.getTokenStream();		for (int ti = i; ti<input.size() && ti <= j; ti++) {			Token t = input.get(ti);			if ( t.getChannel()!=Token.DEFAULT_CHANNEL ) {				n++;			}		}		return n;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -