Links
EControl Syntax Editor SDK
TGrammaAnalyzer Class

Implements grammar analyzer engine.

TGrammaAnalyzer = class(TPersistent);

ecSyntGramma

Grammar rules allows testing complex sequences of tokens. 

Grammar is defined in Gramma property. Grammar rules are separated by the semicolon. 

 

Syntax of grammar definitions:

Rule ::= RuleName '=' Branch_list ';'

Branch_list ::= Item_list
              | Branch_list '|' Item_list

Item_list ::= Element
            | Item_list Element

Element ::= Item
          | Item '*'
          | Item '+'
          | Item '?'

Item ::= RuleName
       | '"' Term '"'
       | ''' Term '''
       | '<' TokenType '>'
       | '(' Item_list ')'

where: 

"Term" - case insensitive terminal, 

'Term' - case sensitive terminal, 

TokenType - name of token type, 

RuleName - name of grammar rule. 

 

Repeaters: 

'*' - any number of entries including none 

'+' - at least one entry 

'?' - one entry or none 

 

There are special grammar rule "Skip". It is used after each match operation to skip unused tokens (for example, comments). 

 

There is reserved rule name "Skip", that is used to specify skipping sequence. This rule is executed after each item processing. 

For example, see Pascal lexer in default lexer library, rules "class declaration", "Empty class", "Interface declaration".

Topic 
Description 
The methods of the TGrammaAnalyzer class are listed here. 
The properties of the TGrammaAnalyzer class are listed here. 
The events of the TGrammaAnalyzer class are listed here. 
 
Method 
 
virtual 
 
Property 
 
read only 
 
Event 
TGrammaAnalyzer Events 
Description 
Occurs when grammar definition has been changed. 
TGrammaAnalyzer Methods 
Description 
Clears grammar definition and grammar rules (results of grammar compilation). 
Compiles grammar definition. 
Creates and initializes a TGrammaAnalyzer instance. 
Destroys an instance of TGrammaAnalyzer. 
Returns index of the rule in rules list. 
Returns grammar ruler with name AName. 
Analyzes text represented by Tags (TClientSyntAnalyze) starting from FromIndex to back direction using Rule. If parsing is successful result is not nil
Tests sequence of tokens from position FromIndex to satisfy grammar rule Rule 
TGrammaAnalyzer Properties 
Description 
Specifies grammar definition. 
Indicates number of grammar rules. 
Lists grammar rules references. 
Copyright (c) 2004-2011. All rights reserved.
What do you think about this topic? Send feedback!