This project has moved and is read-only. For the latest updates, please go here.

Grammar for T-SQL

Aug 31, 2011 at 8:10 PM

Hello, just discovered this project and I am curious to know if there exists a grammar for T-SQL?

Thanks in advanced,


Aug 31, 2011 at 9:12 PM

Perhaps if you someone could show me how to add some functions to the existing SQL grammar?  I would like to add LEFT, RIGHT, ROUND, etc.  If someone could just show me a sample that did one of these, I would be very grateful.


Aug 31, 2011 at 9:40 PM


So I added this to the columnSource.Rule and created a new set of rules for string functions in T-SQL:

      columnSource.Rule = aggregate | stringFunction | Id;
      stringFunction.Rule = stringFunctionName + "(" + stringFunctionArg + ")";
      stringFunctionArg.Rule = term + "," + number;
      stringFunctionName.Rule = COUNT | "Difference" | "Left" | "Right";

When I run the Irony Grammar Explorer, I can Parse my sample query but I notice that I am getting a Grammar Error of level "Conflict":

"Reduce-reduce conflict.  State S50, lookaheads: (. Selected reduce on first production in conflict set."

I am not sure what I need to do to fix this?  Any advice?


Sep 1, 2011 at 4:18 AM

the conflict is obviously from the fact that aggregate and stringfunction definitions are identical. You should join these declarations; for ex, add your function names to aggregate names. For clarity, you can rename aggregate element into funOrAggregate.

Sep 1, 2011 at 1:13 PM

Thanks for you response!  I am not quite sure how you know that they are identical?  The rules are different.  I will need several versions of this since I want to support functions that have a different number of parameters or ones that are optional.  Could you explain how you were able to see that they were identical?  I would also like to know the best way to define functions that have different number of parameters that may or may not be optional.

Thanks again for your response!

Sep 1, 2011 at 6:17 PM

Look at mini-Python grammar, function call element

Sep 1, 2011 at 7:15 PM

Thank you very much for pointing me in the right direction.  That's what I was looking for.