Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
495
EBNF: I'm lost!
posted

I've started looking at the Syntax Parsing Framework and I have a few questions.

Regarding the EBNF format, I'm quite lost.  The only sample in 12.2 that I found was the XML one and the ones form the CTP don't work anymore with 12.2.  What would be the minimal EBNF to be able to parse a couple of words in a sentence let's say, Hello and World?

The sample directs you to create a cs file from an EBNF file.  Would it be possible to load an EBNF file directly without creating a class first?  I ask this because our grammar is based on a series of what we call "fields" and users can add their own to this list.

Thanks

Guy B.

Parents
  • 44743
    Suggested Answer
    posted

    Hey Guy, thanks for your feedback on the CTP version of the syntax parsing framework. I’m sorry that you had a problem with the samples. Which ones were giving you trouble? There was a bit of code churn before the CTP went out the door and it’s possible something which was working was broken accidentally. As far as your questions, I believe the attached file answers both of them (but let me know if it does not). The file dynamically loads in an EBNF grammar definition (which is a constant string, but could easily be generated based on customer preferences) and creates a CustomLanguage instance representing it. The grammar itself has a start symbol named Document, which represents zero or more Sentence symbols. Each Sentence represents one or more Phrase symbols followed by a punctuation symbol. And multiple instances of Phrase are separated by other types of punctuation. A Phrase represents one or more words. I have also included a short recursive routine to print the final parse tree to the debug window, which based on the input “Hello World! This sentence has multiple phrases; they are separated by a semicolon.” prints the following:

    Document

        Sentence

            Phrase

                WordToken: Hello

                WordToken: World

            SentenceEndingPunctuation

                ExclamationPointToken: !

        Sentence

            Phrase

                WordToken: This

                WordToken: sentence

                WordToken: has

                WordToken: multiple

                WordToken: phrases

            PhraseSeparatingPunctuation

                SemicolonToken: ;

            Phrase

                WordToken: they

                WordToken: are

                WordToken: separated

                WordToken: by

                WordToken: a

                WordToken: semicolon

            SentenceEndingPunctuation

                DotToken: .

        $:

    If you have any questions on the grammar or anything else, let me know and I will try to answer them as best as possible.

    Also, I should warn you that the format of the special sequences in the EBNF format has not been finalized and may change when the parsing framework is brought to RTM status.

    Another thing to note is that you can also create a Grammar instance by populating the terminal and non-terminal symbols collections with objects representing the symbols manually. This removes the need for EBNF files, which is just one way to provide grammatical information to the parsing framework. However, I can tell you that we have already made some breaking changes in this area, so again, keep that in mind.

    And finally, if you haven’t already, you might want to check out my blog where I have been discussing the parsing framework: http://es.infragistics.com/community/blogs/mike_dour/

    Program.zip
Reply Children