Consider the code below :


Its Directed graph is shown below :

enter image description here

My question for this example is why I can't add these red lines ( dependencies ) to the graph ? In other words , why they are Wong ?

New contributor
Joo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • As this is not a standard diagramming form (AFAIK), then there's not enough context here, so I would opine it is fine to add those arrows. – Erik Eidt Dec 2 at 21:36
  • @ErikEidt One more question , why we are drawing tokens for each constant , for example in the statement x=5 , we have drawn a separate token for the constant value 5 and we have drawn an arc from this token to the token of 5 in the statement which implies a data dependency , but why it is necessarily to do so for constants ? – Joo Dec 2 at 21:59
  • Like I said, I don't consider this a standard diagrammatic form. However, you can see that across the top there are the "inputs" and "constants" and down the side there are the "local variables". Beyond that, these items are repeated in a rather haphazard manner. Still, it is odd in that the across the top items don't really make columns and neither do the down the left-side items make rows. Fundamentally, the diagram shows static "dependencies" without ordering, which is a lossy representation of the source code. – Erik Eidt Dec 3 at 2:23
  • The if-then-else construct is particularly strange. It doesn't seem to allow for levels of computational dependencies, rather flattening those as well. I would have expected that u<v goes to a temp like z then goes to the then & else parts, rather than simply propagating u and v both individually to the then and else parts. – Erik Eidt Dec 3 at 2:28
  • If it were me, I would show the dependencies by an overlay the source code itself with some arrows interconnecting constructs like variables and expressions. (Or else use real compiler-style data flow analysis.) – Erik Eidt Dec 3 at 2:29

Browse other questions tagged or ask your own question.