Invalid example in GettingStarted04d Quickstart grammar?

SyntaxEditor for WPF Forum

Posted 12 years ago by Jonah Flor
Version: 11.2.0553
Avatar

In SimpleGrammar.cs of the GettingStarted04d Quickstart, the result of an AstFrom function is assigned to a BinaryOperatorExpression.Operator property.  The types are incompatible, and debugging suggests that the assignment simply fails to execute without throwing an exception.

additiveExpression.Production = multiplicativeExpression["leftexp"] + ((@addition | @subtraction).SetLabel("op") + additiveExpression["rightexp"].OnErrorContinue()).Optional() > AstConditional<BinaryOperatorExpression>(AstFrom("leftexp"), AstFrom("rightexp")) .SetProperty(e => e.Operator, AstFrom("op")) .SetProperty(e => e.LeftExpression, AstFrom("leftexp")) .SetProperty(e => e.RightExpression, AstFrom("rightexp"));

I'm trying to figure out how to accomplish this--set the operator property based on the actual operator used (either addition of subtraction) in the binary expression.

Comments (1)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Good find Jonah.  It should have been this:

additiveExpression.Production = multiplicativeExpression["leftexp"] + (
	(
		@addition > Ast(OperatorKind.Addition.ToString()) 
		| @subtraction > Ast(OperatorKind.Subtraction.ToString())
	).SetLabel("op") + additiveExpression["rightexp"].OnErrorContinue()).Optional()
	> AstConditional<BinaryOperatorExpression>(AstFrom("leftexp"), AstFrom("rightexp"))
		.SetProperty(e => e.Operator, AstFrom("op"))
		.SetProperty(e => e.LeftExpression, AstFrom("leftexp"))
		.SetProperty(e => e.RightExpression, AstFrom("rightexp"));

And similar for the other two productions that use BinaryOperatorExpression. 


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.