profile-parsing
Profile grammar parsing to get performance metrics like parse time, token count, tree depth, ambiguity count, and optimization suggestions for debugging slow parsing.
Instructions
Profile grammar parsing with detailed performance metrics.
When to use: Deep performance analysis, debugging slow parsing, optimizing grammars.
Measures:
Parse time (ms)
Token count
Parse tree depth
Decision evaluations (ATN transitions)
Ambiguity count (conflicting alternatives)
Context sensitivity (SLL→LL fallbacks)
Rule invocation frequency
Parameters:
grammar_files: Object mapping filename to content
start_rule: Parser rule to start from
input: Sample input text
Returns:
Detailed profile metrics
Most frequently invoked rules
Optimization suggestions
Example: grammar_files: {"Expr.g4": "grammar Expr; ..."} start_rule: "program" input: "x = 1 + 2 * 3"
Interpretation:
ambiguityCount > 0: Grammar has ambiguous alternatives
contextSensitivityCount > 10: Many SLL→LL fallbacks (slow)
treeDepth > 100: Excessive nesting
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Input text to parse | |
| start_rule | Yes | Parser rule to start parsing from | |
| grammar_files | Yes | Map of filename to grammar content |