Ast node construction with SetLabel

SyntaxEditor for WPF Forum

Posted 9 years ago by Roy Versteeg
Version: 15.1.0621
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

I'm constructing a AST tree for expressions.

When i've got the following code

 

multiplyExpression.Production =
        primaryExpression["exp1"] + (multiplyOperator["op"] + multiplyExpression["exp2"].OnErrorContinue()).Optional()
            > AstConditional<ArithmeticOperatorExpression>(AstFrom("exp1"), AstFrom("exp2"))
                .SetProperty(e => e.Operator, AstFrom("op"))
                .SetProperty(e => e.LeftExpression, AstFrom("exp1"))
                .SetProperty(e => e.RightExpression, AstFrom("exp2"));

 The operater field is correctly set to '*'

But when I try to add the divide operator '/' with the following code

multiplyExpression.Production =
        primaryExpression["exp1"] + ((@multiplyOperator | @divideOperator).SetLabel("op") + multiplyExpression["exp2"].OnErrorContinue()).Optional()
            > AstConditional<ArithmeticOperatorExpression>(AstFrom("exp1"), AstFrom("exp2"))
                .SetProperty(e => e.Operator, AstFrom("op"))
                .SetProperty(e => e.LeftExpression, AstFrom("exp1"))
                .SetProperty(e => e.RightExpression, AstFrom("exp2"));

 The Operator property is not set anymore. My AST nodes are created correcty, but I need the value of the operator Terminal.

How can I Fix this?

Comments (2)

Posted 9 years ago by Roy Versteeg
Avatar

I'm using version: 14.2.610.0 with .NET 4.0 on Win 8.1

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

Hi Roy,

Any time you introduce an alternation as you did with the two operators, you need to specify the output AST for each option.  If you look at the SimpleGrammar in the GettingStarted04d QuickStart, you can see an example of this in multiplicativeExpression where it does:

multiplicativeExpression.Production = primaryExpression["leftexp"] + (
	(
		@multiplication > Ast(OperatorKind.Multiplication.ToString()) 
		| @division > Ast(OperatorKind.Division.ToString())
	).SetLabel("op") + multiplicativeExpression["rightexp"].OnErrorContinue()).Optional()
...


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.