I know that Control Flow Graph(CFG) can be built from Abstract Syntax Tree (AST).
However, it is not clear to me whether CFG is a subset of AST?
As an example, given a CFG can we go back to AST?
I know that Control Flow Graph(CFG) can be built from Abstract Syntax Tree (AST).
However, it is not clear to me whether CFG is a subset of AST?
As an example, given a CFG can we go back to AST?
However, it is not clear to me whether CFG is a subset of AST?
No, AST is an entirely syntactical construct. But a CST is well integrated with language's semantics. Also they represent different stuff.
As an example, given a CFG can we go back to AST?
It depends on the language, and how the constructs in that language maps to the control flow. For example these 2 snippets would construct entirely different ASTs;
print('a') if a else print('b')
if a:
print('a')
else:
print('b')
But the generated CFG would be equal for both of those.