I need to take some decisions depending on the structure and information in a parse tree, this is an example of the trees I am generating now:
The decisions for generating code will depend on the operator(";","AND","OR","XOR") between two workflows, for instance the code I need to generate from this tree is
mustPrecede(T6,T4) AND mustPrecede(T6,T1)
AND mustPrecede(T4,T5) AND mustPrecede(T1,T5)
For this I need to find out that the operator between T6 and (T4 AND T1) is ";" (sequential composition operator) for taking a decision and then I need to find out that between T4 and T1 the operator is "AND" and then I need to get the T4 and T1 to make a relation with T5. My question is how can I encode this in a parser?.
This is my grammar definition
grammar Hello;
execution: workflow EOF;
workflow : Task
| workflow OPERATOR workflow
|'(' workflow (OPERATOR workflow)+ ')'
;
Task : 'T' ('0'..'9')+
| 'WF' ('0'..'9')+
;
OPERATOR: 'AND'
| 'OR'
| 'XOR'
| ';'
;
WS : [ \t\n\r]+ -> channel(HIDDEN) ;