Parser generator & Grammar Designer

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Nik Verkhovtseff
Version: 4.0.0249
Avatar
Hello,

I use Grammar Designer form TestApplication to generate code for C# semantic parser.
Below is a fragment of Grammar definition file (within Production tags):

[ 'Else' "EmbeddedStatement<@out falseStatement@>" ]
When I run parser generator, I got a C# code for fragment above:

if ((this.TokenIs(this.LookAheadToken, CSharpTokenID.Else)) || (this.IsCondition1()) ...|| (this.IsLastCodition())) {
    if (!this.Match(CSharpTokenID.Else))
        return false;
    if (!this.MatchEmbeddedStatement(out falseStatement))
        return false;
}
I should notice that my non-terminal "EmbeddedStatement" has AdditionalConditions (ExpressionConditions).

To my mind, the generated code should be like this:

if (this.TokenIs(this.LookAheadToken, CSharpTokenID.Else)) {
    if (!this.Match(CSharpTokenID.Else))
        return false;
    if (!this.MatchEmbeddedStatement(out falseStatement))
        return false;
}
i.e. first-set condition should be only 'Else' token.

is it a defect in parser generator? or I do something wrong?


Thanks,
Nik

Comments (3)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hmm, that might be a bug. Can you modify the Simple grammar (or an even more basic one) to make this happen and email that over so we can debug? Thanks!


Actipro Software Support

Posted 17 years ago by Nik Verkhovtseff
Avatar
Hi,

I added to simple grammar tokens:

 <Token>If</Token>
 <Token>Else</Token>
and non-terminals:

<NonTerminal Key="EmbeddedExpression" Parameters="out Expression e">
    <AdditionalConditions>
        <ExpressionCondition>this.IsCondition()</ExpressionCondition>
    </AdditionalConditions>
    <Production><![CDATA[                
        'OpenCurlyBrace'
        'CloseCurlyBrace'                
    ]]></Production>
</NonTerminal>

<NonTerminal Key="IfStatement" Parameters="out Statement stat">
    <Production><![CDATA[                
        'If' "Expression"
        [ 'Else' "EmbeddedExpression" ]                
    ]]></Production>
</NonTerminal>
I got a generated code for IfStatement:

protected virtual bool MatchIfStatement(out Statement stat) {
    if (!this.Match(SimpleTokenID.If))
        return false;
    if (!this.MatchExpression())
        return false;
    if ((this.TokenIs(this.LookAheadToken, SimpleTokenID.Else)) || (this.this.IsCondition())) {
        if (!this.Match(SimpleTokenID.Else))
            return false;
        if (!this.MatchEmbeddedExpression())
            return false;
    }
    return true;
}
Is it ok?

Thanks,
Nik
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks, it's now fixed for the next maintenance release.


Actipro Software Support

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.