Forum Discussion

OleksiiKovalov's avatar
OleksiiKovalov
Copper Contributor
May 31, 2021

Looking for Microsoft.SqlServer.TransactSql.ScriptDom grammar

Hi!

I'm looking for any info/contact for antlr grammar used by Microsoft.SqlServer.TransactSql.ScriptDom assembly

Looks like https://github.com/microsoft/ doesn't contains any useful info

 

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    OleksiiKovalov 

     

    ANTLR = ANother Tool for Language Recognition? Don't understand that.

     

    ScriptDom is a "simple" parser for Transact-SQL, with the MS SQL Server specific SQL dialect.

    No need to "recognite" anything, it's for T-SQL.

    • OleksiiKovalov's avatar
      OleksiiKovalov
      Copper Contributor
      yes, ANother Tool for Language Recognition

      Scriptdom is built using ANTLR (version/implementation is unknown to me) grammar.
      And generated parser is very fast.

      Now I'm working on a set of similar SQL parsers and I have some performance problems.
      Some of the issues I've resolved by simplification, removing ambiguities, and extra LA in grammar/parser, but my implementation of SQL grammar still way too slow as compared to ScriptDOM parser.

      I'm sure that I missed some simple, but important things when developing SQL grammar. I think it would be very useful to take a look/receive a consultation from developers of original ScriptDOM grammar.
      • olafhelper's avatar
        olafhelper
        Bronze Contributor
        Now I'm working on a set of similar SQL parsers 

        Why re-inventing the wheel, use the existing MS SqlScriptDom.

  • xgamewiki's avatar
    xgamewiki
    Copper Contributor
    While I can't access the specific ANTLR grammar used within the Microsoft.SqlServer.TransactSql.ScriptDom assembly, I can provide information based on available resources and general ANTLR usage:

    Likely Grammar Location:

    The grammar file likely resides within the assembly itself, but it's not directly accessible or editable.
    Accessing Grammar Information:

    Reflection: Use tools like ILSpy or dotPeek to inspect the assembly and potentially view generated parser/lexer classes, hinting at grammar structure.
    Documentation: Consult official Microsoft documentation or community resources for insights.
    Using the Assembly:

    Scripting: The assembly primarily supports parsing and working with Transact-SQL scripts programmatically.
    Grammar Exploration: To delve deeper into the grammar, consider using ANTLR to create a custom T-SQL parser from a publicly available grammar or crafting one yourself.
    Additional Considerations:

    Grammar Version: The specific grammar version employed within the assembly might vary.
    Grammar Changes: Microsoft could update the grammar in future releases.
    Recommendations:

    Specific Needs: Clarify your goals for understanding the grammar. This will guide next steps.
    Alternate Solutions: Explore alternative methods to achieve your objectives, such as using publicly available T-SQL grammars with ANTLR directly.
    I'm ready to assist further based on your specific requirements.

Resources