Version

Grammar Analysis (Syntax Parsing Engine)

Topic Overview

Purpose

This topic explains the grammar analysis performed by the Syntax Parsing Engine.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the Syntax Parsing Engine.

This topic provides an overview of the Syntax Parsing Engine’s Grammar.

In this topic

This topic contains the following sections:

Grammar Analysis

Grammar analysis summary

There are many things which are not allowed in a grammar definition (for more information refer to the Restrictions topic). However there are other things which are allowed but may not be what the grammar writer intended or may slow down the lexical or syntax analyzers. Below you can find the issues like this highlighted during grammar analysis and how to avoid them.

Obtain warnings

To determine the issues in your grammar definition you can use the Grammar.Analyze method and you can configure the analysis by passing an instance of type GrammarAnalysisOptions.

Note
Note

If you do not specify a GrammarAnalysisOptions object, the Syntax Parsing Engine will use one with the default options set.

The GrammarAnalysisOptions contains the following configurable options:

properties:

Properties Description

Indicates whether to analyze the grammar for Ambiguity warnings. This value is true by default.

Indicates whether to analyze the grammar for ComplexNonTerminalSymbol warnings. This value is true by default.

Indicates whether to analyze the grammar for SymbolCannotBeParsed warnings. This value is true by default.

Indicates whether to analyze the grammar for UnnecessarySyntaxRule warnings. This value is true by default.

The minimum number of productions a NonTerminalSymbol must own before it is considered complex. This value is 100 by default.

The return value of this method is an instance of type GrammarAnalysisResult, which contains the grammar and a Warnings collection containing objects of type GrammarWarning. The GrammarWarning type has a descriptive Message property of type string and a Type property of type GrammarWarningType, which is an enumeration with the following values:

Value Description

Ambiguity

Indicates when the productions of the grammar may cause an ambiguity when parsing certain text. For more information look at the Ambiguities topic. If an ambiguity is known to be acceptable and its warnings are cluttering the warnings produced by analyzing a grammar, they can be suppressed by setting the NonTerminalSymbol.SuppressAmbiguityWarnings property to true on one of the non-terminal symbols involved in the ambiguity.

ComplexNonTerminalSymbol

Indicates when the rule tree for a non-terminal symbol will internally expand to over 100 productions, although this limit is configurable using the GrammarAnalysisOptions. Having complex non-terminal symbols can significantly slowdown the process of generating the syntax analyzer as well as error reporting.

SymbolCannotBeParsed

Indicates that a non-terminal symbol or significant terminal symbol defined in the grammar is not referenced directly or indirectly by the start symbol, meaning it will never have a node representing it in the syntax tree.

UnnecessarySyntaxRule

Indicates when a syntax rule is not necessary, such as:

  • Using an EmptySyntaxRule within a ConcatenationSyntaxRule. Concatenating empty onto a sequence of symbols is the same as just having the sequence of symbols.

  • Using an EmptySyntaxRule within an AlternationSyntaxRule which is itself the child of an OptionalSyntaxRule or RepetitionSyntaxRule. The optional or repetition rule implies that one of the alternatives in addition to those specified is the empty rule. Specifying it is unnecessary.

  • A FactorSyntaxRule has as its Rule property an instance of RepetitionSyntaxRule. Having a fixed number of zero or more things is the same as just having zero or more of them, so the use of the FactorSyntaxRule is unnecessary and the RepetitionSyntaxRule can just be used in its place.

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains the restrictions placed on grammar definitions.

This topic describes the ambiguities that may occur while a document is parsing and how to handle them.

This topic explains the lexical analysis performed by the Syntax Parsing Engine.

This topic explains the syntax analysis performed by the Syntax Parsing Engine.