Parsifal Software


Trial Copy

Intro. to Parsing

Users Say...

Special Features

Notation Summary

New 2.01 Features

File Trace

Grammar Trace



Expression evaluator (freeware)

XIDEK interpreter kit (freeware)

Lex/Yacc Comparison

If-else ambiguity

Contact Parsifal


AnaGram Parser Generator: Grammar Trace

The Grammar Trace tool lets you examine the workings of your parser in detail. Using the various options associated with this trace you can set up a representation of the parser state stack and parser state as they might appear in the course of execution of your parser. You can then examine the allowable input tokens and the changes to the state and the state stack caused by any input tokens you choose.

sample Grammar Trace window

AnaGram now provides a combo box where you can enter input characters for a Grammar Trace, in addition to choosing tokens. This means you can run a Grammar Trace like a File Trace where the test file is replaced by the combo box characters you type. This is a very convenient way to check out your grammar.

Starting Grammar Traces:

A Grammar Trace can be selected from either the Action Menu or the Control Panel toolbar once your grammar has been analyzed. There are also prebuilt grammar traces like the Conflict Trace and the Auxiliary Trace, which can be selected from the Auxiliary Windows popup menu for certain AnaGram windows or panes.

Like File Trace, a Grammar Trace presents three principal panes. These are a Parser Stack pane on the left, an Allowable Input pane on the right, and a Rule Stack pane at the bottom.

Initially, the Parser Stack will consist of a single line, which represents the initial configuration of your parser. The first column will show zero, which is the value of the parser stack index. The second column will show the state number of the parser, initially S000. The third column of the Parser Stack, which shows the token seen at that state, is initially blank. The Rule Stack will likewise be at level 0, state 000. The active pane of the Grammar Trace will be the Allowable Input pane, ready for you to choose a token.

Using Grammar Trace

At any stage, the Parser Stack pane represents a parse in progress. It shows the sequence of tokens that have been input so far and the states in which they were seen. When a production is complete and the grammar rule is reduced, the tokens that make up the rule are removed from the stack and replaced by the token on the left side of the production. The Rule Stack pane shows you all the grammar rules that are currently active at any level in the stack.

To explore your grammar, choose a token from the Allowable Input pane. This pane shows the tokens allowable at the current state of the grammar, and the actions that result when the tokens are chosen. The Action field for each token shows whether it would cause a shift or a reduction, and the new state or the rule reduced. It is blank if the parser action is a compound action.

Select a token by double-clicking it with the left mouse button or by positioning the cursor bar on the token and pressing Enter. Then the Parser Stack and Rule Stack will be modified to reflect the input choice you made. Note that the panes in the Grammar Trace window are synched with each other and also with your syntax file window if it is on-screen. The Rule Stack is particularly useful for seeing the relationship between the Parser Stack contents and your grammar.

You may now continue stepping through your grammar. At any time, as an alternative to choosing tokens in the Allowable Input pane, you may type text in the combo box at the bottom of the Grammar Trace window and either press Enter or select the Proceed button to parse the text. The Single Step button will accept the combo box input one step at a time if the combo box is active, or the highlighted token if Allowable Input is active.

You can back up the parse by moving the cursor bar in the Parser Stack window to the desired level and double-clicking the highlighted token in Allowable Input. You can reset the trace to the beginning with the Reset button.

If you are using semantically determined productions, a Reduction Choices pane will appear to the left of the Rule Stack when it is time to reduce such a production. Select the desired reduction token from the pane before continuing with the parse.

All Grammar Trace activity updates the trace coverage counts.

AnaGram parser generator
Copyright ©1993-2002, Parsifal Software.
All Rights Reserved.

Parsifal Software
Links to: Home page | Trial Copy | Syntax Directed Parsing | Glossary