Posted 14 years ago
by Phil Devaney
-
Senior Software Engineer,
Serck Controls Ltd
Version: 10.2.0531

Hi,
I am trying to convert an MGrammar grammar to use your LLParser, which has been mostly straightforward, but I am having trouble eliminating left recursion from a couple of productions. My grammar is for an expression evaluator with syntax similar to C#, with the usual literals, variables, binary & unary operators and function calls. It also has the member access operator (.) and subscript/indexer operator ([]), and it is these last two I am having problems with.
My MGrammar definition looks like this (tokens begin with T and should be obvious from their names):I have tried various ways of defining this, but can't find a way that isn't left recursive while still allowing for arbitrary chaining (e.g a[0].b[1].c.d). I don't think a CanMatch callback can help as there can be an arbitrarily complex expression on the left (e.g. ( x + y * z ).b). I guess you might have encountered a similar problem if you are working on a C# grammar the .NET Languages addon. If so, how did you solve it?
Another issue I encounted (and solved) was with strings. Is it expected to have to define string literals as NonTerminals like this:or is there a way to get the lexer to emit the full string literal as a Terminal?
Finally, because my parser DLL references the .NET 4 version of WPF (for SolidColorBrush etc), it causes the parser debugger to crash when trying to load it as the Language Designer tool uses the v2 runtime. This is easily solved by making it run under the v4 runtime by creating a .exe.config and adding a <supportedRuntime> element (see http://msdn.microsoft.com/en-us/library/w4atty68.aspx) but I thought it might be a good idea to add a note to the documentation about this.
Thanks
Phil
I am trying to convert an MGrammar grammar to use your LLParser, which has been mostly straightforward, but I am having trouble eliminating left recursion from a couple of productions. My grammar is for an expression evaluator with syntax similar to C#, with the usual literals, variables, binary & unary operators and function calls. It also has the member access operator (.) and subscript/indexer operator ([]), and it is these last two I am having problems with.
My MGrammar definition looks like this (tokens begin with T and should be obvious from their names):
syntax PrimaryExpr =
LiteralExpr
| ParenthesizedExpr
| FunctionCallExpr
| MemberAccessExpr
| ElementAccessExpr;
...
syntax MemberAccessExpr =
TIdentifier
| PrimaryExpr TPeriod TIdentifier;
syntax ElementAccessExpr =
PrimaryExpr TOpenBracket Expr TCloseBracket;
Another issue I encounted (and solved) was with strings. Is it expected to have to define string literals as NonTerminals like this:
stringLiteral.Production =
@stringStart + charList["chars"] + @stringEnd
> Ast( "StringLiteral", AstChildrenFrom( "chars" ) );
charList.Production =
( @stringText["c"] > AstFrom( "c" ) | @stringEscape["c"] > AstFrom( "c" ) ).ZeroOrMore().SetLabel( "chars" )
> Ast( "CharList", AstChildrenFrom( "chars" ) );
Finally, because my parser DLL references the .NET 4 version of WPF (for SolidColorBrush etc), it causes the parser debugger to crash when trying to load it as the Language Designer tool uses the v2 runtime. This is easily solved by making it run under the v4 runtime by creating a .exe.config and adding a <supportedRuntime> element (see http://msdn.microsoft.com/en-us/library/w4atty68.aspx) but I thought it might be a good idea to add a note to the documentation about this.
Thanks
Phil