Reputation: 13
I've got this code that I need to draw a parse tree:
for(id=num;id<=num;id=id+1){
id=id/num;
if(id==num){
id=id*num;
}
else{
id=id+num;
}
}
I saw in other post someone suggesting to use this site: https://ironcreek.net/syntaxtree/. How can I use it?
Upvotes: 0
Views: 29
Reputation: 66
I hope this works for you.
[ForLoop
[Initialization
[Assignment
[Identifier "id"]
[Literal "num"]
]
]
[Condition
[Comparison
[Identifier "id"]
[Operator "<="]
[Literal "num"]
]
]
[Increment
[Assignment
[Identifier "id"]
[Expression
[Identifier "id"]
[Operator "+"]
[Literal "1"]
]
]
]
[Body
[Block
[Assignment
[Identifier "id"]
[Expression
[Identifier "id"]
[Operator "/"]
[Literal "num"]
]
]
[IfStatement
[Condition
[Comparison
[Identifier "id"]
[Operator "=="]
[Literal "num"]
]
]
[ThenBlock
[Assignment
[Identifier "id"]
[Expression
[Identifier "id"]
[Operator "*"]
[Literal "num"]
]
]
]
[ElseBlock
[Assignment
[Identifier "id"]
[Expression
[Identifier "id"]
[Operator "+"]
[Literal "num"]
]
]
]
]
]
]
]
Upvotes: 1