Parser generator & IsNonTerminal

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Nik Verkhovtseff
Version: 4.0.0243
Avatar
Hi,

I use Parser Generator to create semantic parser and use TokenCondition in some non-termainals, e.g.:

<NonTerminal Key="TestNonTerminal">
    <AdditionalConditions>
        <TokenCondition>TokenOption2</TokenCondition>
    </AdditionalConditions>
    <Production><![CDATA[
     .....
    ]]></Production>
</NonTerminal>
I notice that Parser Generator generates different C# code for IsNonTerminal("TestNonTerminal") and for "TestNonTerminal" inside Production tags - it seems that tokens from AdditionalConditions is not included in MultiMatchSets for code that's generated for IsNonTerminal. Is it defect or I misunderstand a TokenCondition?

Thanks,
Nik

Comments (4)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks this bug is now fixed for the next maintenance release.


Actipro Software Support

Posted 12 years ago by Adam Dickinson
Avatar
Version 4.0.246

I have a similar problem, but with conditions in Production code and MultiMatchSets.

        <NonTerminal Key="NativeDataType" Parameters="out Identifier id, bool allowSpecialDatatype">
            <Production><![CDATA[
                <%
                    id = null;
                %>
                (
                    'BOOL'
                    |
                    'FLOAT'
                    |
                    'INT'
                    |
                    'VECTOR'
                    |
                    'STRING'
                    |
                    <? allowSpecialDatatype ?>
                    'SpecialDatatype'                
                )
                <% 
                    id = new Identifier( this.TokenText, this.Token.TextRange );
                %>
            ]]></Production>
        </NonTerminal>
When the multi-match set is generated, only BOOL, FLOAT, INT, VECTOR, and STRING are in it, never SpecialDatatype. This means in cases where I allow the semantic parser to look for SpecialDatatype, it will never be found because this Non-Terminal's pre-condition fails when it checks its multi-match set. Is this on purpose or is it also a bug?

I can fix this situation myself by removing the "allowSpecialDatatype" first-set condition, reading SpecialDatatype, then deciding whether to add a syntax error based on the value of "allowSpecialDatatype". Then I just have to make sure that SpecialDatatype doesn't exist in any other Non-Terminal pre-conditions because, as you know, the Grammar Designer will error out if the same Terminal is found more than once inside the same Non-Terminal's Production code/pre-conditions.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In your case you probably want to add an expression additional condition that perhaps calls a method to first check allowSpecialDatatype and if true, then sees if the next token is a SpecialDatatype. That additional condition should be propagated up as part of the first set then.


Actipro Software Support

Posted 12 years ago by Adam Dickinson
Avatar
I see, thank you!
The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.