My grammar is something like this
ifStatment ::= IF PARETHESIS logicOperation PARENTHESIS_ KEY procedures KEY_ elseIfStatment;
elseIfStatment ::= ELSE IF PARENTHESIS logicOperation PARENTHESIS_ KEY procedures KEY_ elseIfStatment
|elseStatment;
elseStatment ::= ELSE KEY procedures KEY_
| ;
“logicOperation” returns true/false value, and “procedures” is what I want to do if “logicOperation” is true.
I was tinking of using the cup stack in “procedures” production to check if “logicOperation” is true.
It would work if there was only an “elseStatment” and not “elseIf”, but with the elseIf I could’nt know the exact position of logicOperation in the stack.
What should I do?
I was doing it wrong, thats not how a parser works.
There are two ways of doing it:
Abstract Syntax Tree: Save the procedures and execute after parsing
Three addres code: traduce the code to something else, like assembler.
But if someone still needs to make it, the way to go is using inherited attributes, something that java-cup doesn’t have, so use bison and c.