public TerminalSymbol Add(
string name,
string value = null,
TerminalSymbolComparison comparison = TerminalSymbolComparison.Literal,
bool isExitSymbol = false)
This topic explains a Grammar’s terminal symbols.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
Terminal symbols define a group of characters the lexical analyzer should recognize as a unit when it is creating tokens. In addition to a unique name allowing the parser to distinguish it from other symbols, it also defines what text it can possibly represent. For example, a grammar might have a terminal symbol named “SemicolonToken” which indicates it can only represent “;” and a terminal symbol named “IdentifierToken” which indicates it can represent an underscore or letter followed by zero or more underscores, letters, or digits.
The terminal symbols are represented by the TerminalSymbol class in the Infragistics.Documents.Parsing namespace.
Each LexerState has a Symbols collection containing the TerminalSymbol
instances that can be matched by the lexer when it is in that state. In addition to containing the TerminalSymbol
instances, the Symbols
collection is also the means by which new TerminalSymbol`s are created since `TerminalSymbol
does not have a public constructor. Here is the signature of the Add method on the Symbols collection which creates a TerminalSymbol
:
In C#:
public TerminalSymbol Add(
string name,
string value = null,
TerminalSymbolComparison comparison = TerminalSymbolComparison.Literal,
bool isExitSymbol = false)
In the Symbols
collection Add
method, If the comparison specified for a new TerminalSymbol
is RegularExpression
, the value parameter is interpreted as a regular expression string. Regular expressions allow for a concise description of a set of strings.
In addition to literal strings in the expression, there are certain operators that can be used to combine and enhance regular expressions to define larger and more complex sets. Here is a breakdown of some very basic regular expression features supported by the Syntax Parsing Engine:
The Syntax Parsing Engine conforms to the same syntax as .NET Framework Regular Expressions but only supports a subset of its functionality. This allows for a much faster lexical analysis at a cost of ability to define certain regular expressions. Here is the list of .NET Framework Regular Expression features as well as the features currently supported by the Parsing Engine (this list is taken from MSDN, which can be found here):
The following topics provide additional information related to this topic.