How to get a control flow graph of a program?
up vote
0
down vote
favorite
I want to get a control flow graph of a code/program (be it any programming language and given its grammar).
I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
Having said that, any kind of new approach is highly appreciated. The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
python-3.x grammar control-flow-graph lark-parser
add a comment |
up vote
0
down vote
favorite
I want to get a control flow graph of a code/program (be it any programming language and given its grammar).
I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
Having said that, any kind of new approach is highly appreciated. The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
python-3.x grammar control-flow-graph lark-parser
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get a control flow graph of a code/program (be it any programming language and given its grammar).
I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
Having said that, any kind of new approach is highly appreciated. The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
python-3.x grammar control-flow-graph lark-parser
I want to get a control flow graph of a code/program (be it any programming language and given its grammar).
I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
Having said that, any kind of new approach is highly appreciated. The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
python-3.x grammar control-flow-graph lark-parser
python-3.x grammar control-flow-graph lark-parser
asked Aug 22 at 14:11
Ben Claude
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
A common approach is to
- walk the tree to generate an intermediate representation in which all looping and conditional constructs are replaced with jumps,
- divide the instructions of the IR into basic blocks by starting a new block before each jump label and after each jump and then
- construct a control flow graph where the basic blocks are the nodes, each block that doesn't end with a jump has an edge to the block that comes after it, and each block that does end with a jump has an edge to the possible jump targets (where the jump targets for a traditional conditional jump instruction would include the following block).
The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
You can't get the CFG of a program if all you know about the language is its grammar. You'll need some understanding of the semantics of the language to be able to construct a CFG.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51968789%2fhow-to-get-a-control-flow-graph-of-a-program%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
A common approach is to
- walk the tree to generate an intermediate representation in which all looping and conditional constructs are replaced with jumps,
- divide the instructions of the IR into basic blocks by starting a new block before each jump label and after each jump and then
- construct a control flow graph where the basic blocks are the nodes, each block that doesn't end with a jump has an edge to the block that comes after it, and each block that does end with a jump has an edge to the possible jump targets (where the jump targets for a traditional conditional jump instruction would include the following block).
The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
You can't get the CFG of a program if all you know about the language is its grammar. You'll need some understanding of the semantics of the language to be able to construct a CFG.
add a comment |
up vote
1
down vote
As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
A common approach is to
- walk the tree to generate an intermediate representation in which all looping and conditional constructs are replaced with jumps,
- divide the instructions of the IR into basic blocks by starting a new block before each jump label and after each jump and then
- construct a control flow graph where the basic blocks are the nodes, each block that doesn't end with a jump has an edge to the block that comes after it, and each block that does end with a jump has an edge to the possible jump targets (where the jump targets for a traditional conditional jump instruction would include the following block).
The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
You can't get the CFG of a program if all you know about the language is its grammar. You'll need some understanding of the semantics of the language to be able to construct a CFG.
add a comment |
up vote
1
down vote
up vote
1
down vote
As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
A common approach is to
- walk the tree to generate an intermediate representation in which all looping and conditional constructs are replaced with jumps,
- divide the instructions of the IR into basic blocks by starting a new block before each jump label and after each jump and then
- construct a control flow graph where the basic blocks are the nodes, each block that doesn't end with a jump has an edge to the block that comes after it, and each block that does end with a jump has an edge to the possible jump targets (where the jump targets for a traditional conditional jump instruction would include the following block).
The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
You can't get the CFG of a program if all you know about the language is its grammar. You'll need some understanding of the semantics of the language to be able to construct a CFG.
As a result, it gave me an object of parse tree or similar sort of stuff, now I am wondering where to proceed.
A common approach is to
- walk the tree to generate an intermediate representation in which all looping and conditional constructs are replaced with jumps,
- divide the instructions of the IR into basic blocks by starting a new block before each jump label and after each jump and then
- construct a control flow graph where the basic blocks are the nodes, each block that doesn't end with a jump has an edge to the block that comes after it, and each block that does end with a jump has an edge to the possible jump targets (where the jump targets for a traditional conditional jump instruction would include the following block).
The prime goal is to get the control flow graph of a code/program, given the grammar of the language in which it is written.
You can't get the CFG of a program if all you know about the language is its grammar. You'll need some understanding of the semantics of the language to be able to construct a CFG.
answered Aug 22 at 16:05
sepp2k
291k38593606
291k38593606
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51968789%2fhow-to-get-a-control-flow-graph-of-a-program%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown