How to pause a custom built interpreter while debugging?












0















I am developing a new custom programming language to perform some computations on numbers and display the results in a particular format.



For this purpose, I am using Antlr4 for Lexical Analysis and Parsing, and am developing this in Java. I have been able to "execute" the program by overriding the visitor methods generated by Antlr4.



I am now trying to add debugging functionality, and am trying to pause the execution upon hitting a breakpoint and then resume. Apart from this, I also need to support Step Through, Step In, Step Out, and Resume.



Could someone please throw some light on how to accomplish this?










share|improve this question























  • Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

    – van dench
    Jan 1 at 4:35
















0















I am developing a new custom programming language to perform some computations on numbers and display the results in a particular format.



For this purpose, I am using Antlr4 for Lexical Analysis and Parsing, and am developing this in Java. I have been able to "execute" the program by overriding the visitor methods generated by Antlr4.



I am now trying to add debugging functionality, and am trying to pause the execution upon hitting a breakpoint and then resume. Apart from this, I also need to support Step Through, Step In, Step Out, and Resume.



Could someone please throw some light on how to accomplish this?










share|improve this question























  • Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

    – van dench
    Jan 1 at 4:35














0












0








0


1






I am developing a new custom programming language to perform some computations on numbers and display the results in a particular format.



For this purpose, I am using Antlr4 for Lexical Analysis and Parsing, and am developing this in Java. I have been able to "execute" the program by overriding the visitor methods generated by Antlr4.



I am now trying to add debugging functionality, and am trying to pause the execution upon hitting a breakpoint and then resume. Apart from this, I also need to support Step Through, Step In, Step Out, and Resume.



Could someone please throw some light on how to accomplish this?










share|improve this question














I am developing a new custom programming language to perform some computations on numbers and display the results in a particular format.



For this purpose, I am using Antlr4 for Lexical Analysis and Parsing, and am developing this in Java. I have been able to "execute" the program by overriding the visitor methods generated by Antlr4.



I am now trying to add debugging functionality, and am trying to pause the execution upon hitting a breakpoint and then resume. Apart from this, I also need to support Step Through, Step In, Step Out, and Resume.



Could someone please throw some light on how to accomplish this?







java debugging antlr antlr4 interpreter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 4:19









user2970477user2970477

337




337













  • Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

    – van dench
    Jan 1 at 4:35



















  • Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

    – van dench
    Jan 1 at 4:35

















Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

– van dench
Jan 1 at 4:35





Usually I would recommend JITing the code and inserting interrupt code 3, then catch with a debugger, but that doesn’t really work here. Instead of what you’re currently doing I would recommend compiling the code into a virtual language which you would then run over sequentially, then you can add code to create breakpoints. Once a breakpoint is triggered in your virtual code the simplest (and most hacky) solution would be to call a dummy function which you place a breakpoint into in your IDE.

– van dench
Jan 1 at 4:35












1 Answer
1






active

oldest

votes


















1














ANTLR4 generated parsers cannot be stopped and resumed in the middle of a parse run. For that use the interpreters that come with the ANTLR4 runtime. They implement a simple ATN walk, which can be stopped at any point and the current ATN state be saved for later resume of the debugger.



I implemented this approach in my vscode-antlr4 extension, which allows to debug arbitrary ANTLR4 grammars. See also the vscode marketplace for more details.






share|improve this answer
























  • Thank you for sharing this. I will try this approach.

    – user2970477
    Jan 3 at 10:51











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',
autoActivateHeartbeat: false,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992981%2fhow-to-pause-a-custom-built-interpreter-while-debugging%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









1














ANTLR4 generated parsers cannot be stopped and resumed in the middle of a parse run. For that use the interpreters that come with the ANTLR4 runtime. They implement a simple ATN walk, which can be stopped at any point and the current ATN state be saved for later resume of the debugger.



I implemented this approach in my vscode-antlr4 extension, which allows to debug arbitrary ANTLR4 grammars. See also the vscode marketplace for more details.






share|improve this answer
























  • Thank you for sharing this. I will try this approach.

    – user2970477
    Jan 3 at 10:51
















1














ANTLR4 generated parsers cannot be stopped and resumed in the middle of a parse run. For that use the interpreters that come with the ANTLR4 runtime. They implement a simple ATN walk, which can be stopped at any point and the current ATN state be saved for later resume of the debugger.



I implemented this approach in my vscode-antlr4 extension, which allows to debug arbitrary ANTLR4 grammars. See also the vscode marketplace for more details.






share|improve this answer
























  • Thank you for sharing this. I will try this approach.

    – user2970477
    Jan 3 at 10:51














1












1








1







ANTLR4 generated parsers cannot be stopped and resumed in the middle of a parse run. For that use the interpreters that come with the ANTLR4 runtime. They implement a simple ATN walk, which can be stopped at any point and the current ATN state be saved for later resume of the debugger.



I implemented this approach in my vscode-antlr4 extension, which allows to debug arbitrary ANTLR4 grammars. See also the vscode marketplace for more details.






share|improve this answer













ANTLR4 generated parsers cannot be stopped and resumed in the middle of a parse run. For that use the interpreters that come with the ANTLR4 runtime. They implement a simple ATN walk, which can be stopped at any point and the current ATN state be saved for later resume of the debugger.



I implemented this approach in my vscode-antlr4 extension, which allows to debug arbitrary ANTLR4 grammars. See also the vscode marketplace for more details.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 11:45









Mike LischkeMike Lischke

21.5k352105




21.5k352105













  • Thank you for sharing this. I will try this approach.

    – user2970477
    Jan 3 at 10:51



















  • Thank you for sharing this. I will try this approach.

    – user2970477
    Jan 3 at 10:51

















Thank you for sharing this. I will try this approach.

– user2970477
Jan 3 at 10:51





Thank you for sharing this. I will try this approach.

– user2970477
Jan 3 at 10:51




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992981%2fhow-to-pause-a-custom-built-interpreter-while-debugging%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$