
Hi ActiproTeam,
I have an assembler like codesyntax consisting of multiple instructions, that in turn consist of an Operator and an optional Operand. Here's an example:
AND VARIABLE1
AND(
OR VARIABLE3
OR(
...
)
)
I have defined the following Grammar (simplified):
operator.Production = @operatorTypeOne > Ast<AstNodeOperand>()
|@operatorTypeTwo > Ast<AstNodeOperand>()
|@operatorTypeThree > Ast<AstNodeOperand>()
operand.Production = @operandTypeOne > Ast<AstNodeOperand>()
|@operandTypeTwo > Ast<AstNodeOperand>()
|@operandTypeThree > Ast<AstNodeOperand>()
instruction.Production = operator.SetLabel("AstOperator") + operand.SetLabel("AstOperand")
> Ast<AstNodeInstruction>().SetProperty(x => x.Operand, AstFrom("AstOperand")).SetProperty(x => x.Operator, AstFrom("AstOperator"));
this results in an Ast consisting of a linear list of Instructions
+- AstInstruction (AstOperator - "AND"; AstOperand - VARIABLE1)
+- AstInstruction (AstOperator - "AND("; AstOperand - null)
+- AstInstruction (AstOperator - "OR"; AstOperand - VARIABLE3)
...
my issue is that I want to nest the instructions based on the content of the operator. E.g. if the Operator contains a left parenthesis, i.e. "AND(", "OR(" I want to create a new level in my Ast. And if the Operator contains a right Parenthesis I want to to go up to the parent level again.
The nested Ast then should look something like that:
+- AstInstruction (AstOperator - "AND"; AstOperand - VARIABLE1)
+- AstInstruction (AstOperator - "AND("; AstOperand - null)
| |
| +- AstInstruction (AstOperator - "OR"; AstOperand - VARIABLE3)
| |
| +- AstInstruction (AstOperator - "OR("; AstOperand - null)
| |
| +- AstInstruction (AstOperator - "OR("; AstOperand - null)
| ...
|
+- AstInstruction (AstOperator - ")"; AstOperand - null)
I have tried to create a Custom Tree Node by subclassing ParentTreeConstructionNodeBase class and overriding the "CreateNode" method, but havent found a way to navigate in the structure (ie to implement "create a new hierarchy if the instruction's operator contains a left parenthesis). Unfortunately the sample in the help file is very trivial and didn't really help me.
How can I achieve to nest the Ast? Could you please point me in the right direction?
Many thanks in advance
Sven