{"id":6977,"date":"2024-09-06T14:00:16","date_gmt":"2024-09-06T11:00:16","guid":{"rendered":"https:\/\/new.intechcore.com\/?p=6977"},"modified":"2025-12-01T14:15:22","modified_gmt":"2025-12-01T11:15:22","slug":"entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose","status":"publish","type":"post","link":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/","title":{"rendered":"Developing your own programming language in Java+ANTLR: diagnostics of errors"},"content":{"rendered":"<p>This is the second article in the series\u00a0\u201cDeveloping your own programming language in Java\u201d,\u00a0first article <a class=\"external-link\" href=\"https:\/\/intechcore.com\/en\/development-of-an-own-programming-language-in-javaantlr-interpreter\/\" rel=\"nofollow\">can be read\u00a0here<\/a>.<\/p>\n<p>At the current stage,\u00a0we have an interpreter capable of executing the commands of our language.\u00a0However,\u00a0this is not enough if we want to check the code for errors and display them in a clear way to the user.\u00a0In this article we will consider adding error diagnostics to the language.\u00a0Conducting error analysis in your own programming language is an important step in language development.\u00a0Using powerful tools,\u00a0such as\u00a0<a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/ANTLR\" rel=\"nofollow\">ANTLR<\/a>,\u00a0allows you to implement rather efficient code analysis tools in a short time that will help you to detect potential problems in a program at early stages of development,\u00a0which helps to improve software quality and increase developer&#8217;s productivity.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Classificationoferrors\">Classification of errors<\/h2>\n<p>There are different types of errors,\u00a0but in general they can be divided into three categories:\u00a0<strong>syntax<\/strong>,\u00a0<strong>semantic<\/strong>\u00a0and\u00a0<strong>runtime errors<\/strong>.<\/p>\n<p><strong>Syntax errors<\/strong>\u00a0occur due to violation of the syntax rules of a particular programming language.\u00a0Syntax rules define how statements and expressions in code should be organized.<\/p>\n<p>Example of a syntax error\u00a0(missing closing quote):<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;\">println<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Hello, <\/span><span style=\"color:#80b979;\">World!)<\/span><\/div>\n<p><strong>Semantic errors<\/strong>\u00a0occur when a program is compiled and even executed,\u00a0but the result is different from what was expected.\u00a0This type of error is the most difficult.\u00a0Semantic errors can be caused by the programmer&#8217;s misunderstanding of the language or the task at hand.\u00a0For example,\u00a0if a programmer has a poor understanding of\u00a0<a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Order_of_operations\" rel=\"nofollow\">operator precedence<\/a>,\u00a0then he can write the following code:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">var<\/span> a <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#f9ae58;\">1<\/span> <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#f9ae58;\">2<\/span> <span style=\"color:#f97b58;\">*<\/span> <span style=\"color:#f9ae58;\">3<\/span><\/div>\n<p>One could expect the variable\u00a0<code>a<\/code>\u00a0to be equal to 9,\u00a0but in fact it will be equal to 7.\u00a0This happens because the multiplication operator has higher precedence than the addition operator.\u00a0A semantic error can usually be discovered during debugging or extensive testing of the program.<\/p>\n<p><strong>Runtime errors<\/strong>,\u00a0also known as Exceptions,\u00a0occur during program execution.\u00a0Such errors can occur due to incorrect data entry,\u00a0attempting to access a non-existent file,\u00a0and in many other scenarios.\u00a0Some runtime errors can be handled in a program,\u00a0but if this is not done,\u00a0the program usually crash.<\/p>\n<p>In addition to errors,\u00a0it is also important to detect potential problems or non-obvious situations that are not errors in the strict sense,\u00a0but may lead to undesirable consequences.\u00a0For example,\u00a0it could be an unused variable,\u00a0use of deprecated functions,\u00a0or a meaningless operation.\u00a0In all such cases,\u00a0<em>warnings<\/em>\u00a0can be shown to the user.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-JimpleBaseVisitor\">JimpleBaseVisitor<\/h2>\n<p>To identify errors and warnings,\u00a0we need the abstract class\u00a0<code>JimpleBaseVisitor<\/code>\u00a0(generated by ANTLR),\u00a0familiar to us from the first article,\u00a0which by default implements the\u00a0<code>JimleVisitor<\/code>\u00a0interface.\u00a0It allows you to traverse the AST tree\u00a0(<em>Abstract Syntax Tree<\/em>),\u00a0and based on the analysis of its nodes we will decide upon the error,\u00a0warning or normal part of the code.\u00a0In essence,\u00a0diagnosing errors is almost no different from interpreting code,\u00a0except when we need to perform I\/O or access external resources.\u00a0For example,\u00a0if a console output command is executed,\u00a0then our task is to check whether the data type is passed as an argument is valid,\u00a0without directly outputting to the console.<\/p>\n<p>Let&#8217;s create the\u00a0<code>JimpleDiagnosticTool<\/code>\u00a0class,\u00a0which inherits\u00a0<code>JimleBaseVisitor<\/code>\u00a0and encapsulates all the logic of finding and storing errors:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">class<\/span> <span style=\"color:#f9ae58;\">JimpleDiagnosticTool<\/span> <span style=\"color:#ec5f66;\">extends<\/span> <span style=\"color:#5fb4b4;font-style:italic;\">JimpleBaseVisitor<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#5fb4b4;\">><\/span> {<br \/>    <span style=\"color:#ec5f66;\">private<\/span> <span style=\"color:#6699cc;font-style:italic;\">Set<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#6699cc;font-style:italic;\">Issue<\/span><span style=\"color:#5fb4b4;\">><\/span> issues <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">LinkedHashSet<\/span><span style=\"color:#5fb4b4;\">&lt;><\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/p>\n<p><span style=\"color:#c695c6;font-style:italic;\">record<\/span> <span style=\"color:#f9ae58;\">Issue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span> <span style=\"color:#f9ae58;\">type<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span> <span style=\"color:#f9ae58;\">message<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">lineNumber<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">lineOffset<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span> <span style=\"color:#f9ae58;\">details<\/span>) {}<\/div>\n<p>This class contains a list of type\u00a0<code>Issue<\/code>,\u00a0which represents information about a specific error.<\/p>\n<p>It is known that each method of a given class must return a value of a certain type.\u00a0In our case,\u00a0we will return information about the type of node in the tree\u00a0&#8211;\u00a0<code>ValidationInfo<\/code>.\u00a0This class also contains information about the possible value,\u00a0this will help us identify some semantic or runtime errors.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">record<\/span> <span style=\"color:#f9ae58;\">ValidationInfo<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ValidationType<\/span> <span style=\"color:#f9ae58;\">type<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Object<\/span> <span style=\"color:#f9ae58;\">value<\/span>) {}<\/p>\n<p><span style=\"color:#c695c6;font-style:italic;\">enum<\/span> <span style=\"color:#f9ae58;\">ValidationType<\/span> {<br \/>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">returns <\/span><span style=\"color:#999999;\">nothing.<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">VOID<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">String<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">STRING<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">double<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">DOUBLE<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">long<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">NUMBER<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">boolean<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">BOOL<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Expression <\/span><span style=\"color:#999999;\">contains <\/span><span style=\"color:#999999;\">error <\/span><span style=\"color:#999999;\">and <\/span><span style=\"color:#999999;\">analysing <\/span><span style=\"color:#999999;\">in <\/span><span style=\"color:#999999;\">another <\/span><span style=\"color:#999999;\">context <\/span><span style=\"color:#999999;\">no <\/span><span style=\"color:#999999;\">makes <\/span><span style=\"color:#999999;\">sense.<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">SKIP<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">When <\/span><span style=\"color:#999999;\">object <\/span><span style=\"color:#999999;\">can <\/span><span style=\"color:#999999;\">be <\/span><span style=\"color:#999999;\">any <\/span><span style=\"color:#999999;\">type. <\/span><span style=\"color:#999999;\">Used <\/span><span style=\"color:#999999;\">only <\/span><span style=\"color:#999999;\">in <\/span><span style=\"color:#999999;\">Check <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">definition <\/span><span style=\"color:#999999;\">mode.<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">ANY<\/span><span style=\"color:#ac7a68;\">,<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/**<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">Tree <\/span><span style=\"color:#999999;\">part <\/span><span style=\"color:#999999;\">is <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">declaration<\/span><br \/><span style=\"color:#999999;\">     <\/span><span style=\"color:#999999;\">*\/<\/span><br \/>    <span style=\"color:#f9ae58;\">FUNCTION_DEFINITION<\/span><br \/>}<\/div>\n<p>You should pay attention to the value of\u00a0<code>ValidationType.SKIP<\/code>.\u00a0It will be used if an error has been found and already registered in a part of the tree,\u00a0and further analysis of this tree node does not make sense.\u00a0For example,\u00a0if one argument in a sum expression contains an error,\u00a0then the second argument of the expression will not be analyzed.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">checkBinaryOperatorCommon<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ParseTree<\/span> <span style=\"color:#f9ae58;\">leftExp<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">ParseTree<\/span> <span style=\"color:#f9ae58;\">rightExp<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Token<\/span> <span style=\"color:#f9ae58;\">operator<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> left <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(leftExp)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;\">if<\/span> (left<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">isSkip<\/span>()) {<br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SKIP<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>    <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> right <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(rightExp)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;\">if<\/span> (right<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">isSkip<\/span>()) {<br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SKIP<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">code <\/span><span style=\"color:#999999;\">omitted<\/span><br \/>}<\/div>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-ListersvsVisitors\">Listeners vs Visitors<\/h2>\n<p>Before moving on,\u00a0let&#8217;s take a look at another ANTLR-generated interface\u00a0<code>JimpleListener<\/code>\u00a0(pattern\u00a0<a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Observer_pattern\" rel=\"nofollow\">Observer<\/a>),\u00a0which can also be used if we need traverse the AST tree.\u00a0What is the difference between them?\u00a0The biggest difference between these mechanisms is that listener methods are always called by ANTLR on a per-node basis,\u00a0whereas visitor methods must bypass their child elements with explicit calls.\u00a0And if the programmer does not call\u00a0<code>visit()<\/code>\u00a0on child nodes,\u00a0then these nodes are not visited,\u00a0i.e.\u00a0we have the ability to control tree traversal.\u00a0For example,\u00a0in our implementation,\u00a0the function body is first visited once in its entirety\u00a0(mode\u00a0<code>checkFuncDefinition==true<\/code>)\u00a0to detect errors in the entire function\u00a0(all if and else blocks),\u00a0and several times with specific argument values:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#5fb4b4;\">@<\/span><span style=\"color:#6699cc;\">Override<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">visitIfStatement<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IfStatementContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">calc <\/span><span style=\"color:#999999;\">expression <\/span><span style=\"color:#999999;\">in <\/span><span style=\"color:#999999;\">&#8220;if&#8221; <\/span><span style=\"color:#999999;\">condition<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> condition <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">expression<\/span>())<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#c695c6;\">if<\/span> (checkFuncDefinition) {<br \/>        <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">statement<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">as <\/span><span style=\"color:#999999;\">it&#8217;s <\/span><span style=\"color:#999999;\">just <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">definition <\/span><span style=\"color:#999999;\">check, <\/span><span style=\"color:#999999;\">check <\/span><span style=\"color:#999999;\">else <\/span><span style=\"color:#999999;\">statement <\/span><span style=\"color:#999999;\">as <\/span><span style=\"color:#999999;\">well<\/span><br \/>        <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">ElseStatementContext<\/span> elseStatement <span style=\"color:#f97b58;\">=<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">elseStatement<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">if<\/span> (elseStatement <span style=\"color:#f97b58;\">!=<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>) {<br \/>            <span style=\"color:#6699cc;\">visit<\/span>(elseStatement)<span style=\"color:#ac7a68;\">;<\/span><br \/>        }<br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">VOID<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">it&#8217;s <\/span><span style=\"color:#999999;\">not <\/span><span style=\"color:#999999;\">check <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">definition, <\/span><span style=\"color:#999999;\">it&#8217;s <\/span><span style=\"color:#999999;\">checking <\/span><span style=\"color:#999999;\">of <\/span><span style=\"color:#999999;\">certain <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">call<\/span><br \/>    <span style=\"color:#c695c6;\">if<\/span> (condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">isBool<\/span>() <span style=\"color:#f97b58;\">&amp;&amp;<\/span> condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">hasValue<\/span>()) {<br \/>        <span style=\"color:#c695c6;\">if<\/span> (condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">asBoolean<\/span>()) {<br \/>            <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">statement<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>        } <span style=\"color:#c695c6;\">else<\/span> {<br \/>            <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">ElseStatementContext<\/span> elseStatement <span style=\"color:#f97b58;\">=<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">elseStatement<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>            <span style=\"color:#c695c6;\">if<\/span> (elseStatement <span style=\"color:#f97b58;\">!=<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>) {<br \/>                <span style=\"color:#6699cc;\">visit<\/span>(elseStatement)<span style=\"color:#ac7a68;\">;<\/span><br \/>            }<br \/>        }<br \/>    }<\/p>\n<p>    <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">VOID<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>The Visitor pattern works very well if we need to map a specific value for each tree node.\u00a0This is exactly what we need.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Catchingsyntacticerrors\">Catching syntactic errors<\/h2>\n<p>In order to find some syntax errors in the code,\u00a0we need to implement the\u00a0<code>ANTLRErrorListener<\/code>\u00a0interface.\u00a0This interface contains four methods that will be called\u00a0(by the parser and\/or lexer)\u00a0in case of an error or undefined behavior:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#c695c6;font-style:italic;\">interface<\/span> <span style=\"color:#f9ae58;\">ANTLRErrorListener<\/span> {<br \/>    <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">syntaxError<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Recognizer<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#c695c6;\">?<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;\">?<\/span><span style=\"color:#5fb4b4;\">><\/span> <span style=\"color:#f9ae58;\">recognizer<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Object<\/span> <span style=\"color:#f9ae58;\">offendingSymbol<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">line<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">charPositionInLine<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span> <span style=\"color:#f9ae58;\">msg<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">RecognitionException<\/span> <span style=\"color:#f9ae58;\">e<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">reportAmbiguity<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Parser<\/span> <span style=\"color:#f9ae58;\">recognizer<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">DFA<\/span> <span style=\"color:#f9ae58;\">dfa<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">startIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">stopIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">boolean<\/span> <span style=\"color:#f9ae58;\">exact<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">BitSet<\/span> <span style=\"color:#f9ae58;\">ambigAlts<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">ATNConfigSet<\/span> <span style=\"color:#f9ae58;\">configs<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">reportAttemptingFullContext<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Parser<\/span> <span style=\"color:#f9ae58;\">recognizer<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">DFA<\/span> <span style=\"color:#f9ae58;\">dfa<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">startIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">stopIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">BitSet<\/span> <span style=\"color:#f9ae58;\">conflictingAlts<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">ATNConfigSet<\/span> <span style=\"color:#f9ae58;\">configs<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">reportContextSensitivity<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Parser<\/span> <span style=\"color:#f9ae58;\">recognizer<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">DFA<\/span> <span style=\"color:#f9ae58;\">dfa<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">startIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">stopIndex<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">prediction<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">ATNConfigSet<\/span> <span style=\"color:#f9ae58;\">configs<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>} <\/div>\n<p>The name of the first method\u00a0(<code>syntaxError<\/code>)\u00a0speaks for itself;\u00a0it will be called in case of a syntax error.\u00a0The implementation is quite simple:\u00a0we need to convert the error information into an object of type\u00a0<code>Issue<\/code>\u00a0and add it to the list of errors:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#5fb4b4;\">@<\/span><span style=\"color:#6699cc;\">Override<\/span><br \/><span style=\"color:#c695c6;font-style:italic;\">void<\/span> <span style=\"color:#5fb4b4;\">syntaxError<\/span>(<span style=\"color:#6699cc;font-style:italic;\">Recognizer<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#c695c6;\">?<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;\">?<\/span><span style=\"color:#5fb4b4;\">><\/span> <span style=\"color:#f9ae58;\">recognizer<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Object<\/span> <span style=\"color:#f9ae58;\">offendingSymbol<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">line<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#c695c6;font-style:italic;\">int<\/span> <span style=\"color:#f9ae58;\">charPositionInLine<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span> <span style=\"color:#f9ae58;\">msg<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">RecognitionException<\/span> <span style=\"color:#f9ae58;\">e<\/span>) {<br \/>    <span style=\"color:#c695c6;font-style:italic;\">int<\/span> offset <span style=\"color:#f97b58;\">=<\/span> charPositionInLine <span style=\"color:#f97b58;\">+<\/span> <span style=\"color:#f9ae58;\">1<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    issues<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">add<\/span>(<span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">Issue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ERROR<\/span><span style=\"color:#ac7a68;\">,<\/span> msg<span style=\"color:#ac7a68;\">,<\/span> line<span style=\"color:#ac7a68;\">,<\/span> offset<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;\">makeDetails<\/span>(line<span style=\"color:#ac7a68;\">,<\/span> offset)))<span style=\"color:#ac7a68;\">;<\/span><br \/>}<\/div>\n<p>The remaining three methods can be ignored.\u00a0ANTLR also implements this interface itself\u00a0(see class\u00a0<code>ConsoleErrorListener<\/code>)\u00a0and sends errors to the\u00a0<code>standard error stream<\/code>\u00a0(System.err).\u00a0To disable it and other standard handlers,\u00a0we need to call the\u00a0<code>removeErrorListeners<\/code>\u00a0method on the parser and lexer:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">remove <\/span><span style=\"color:#999999;\">default <\/span><span style=\"color:#999999;\">error <\/span><span style=\"color:#999999;\">handlers<\/span><br \/>lexer<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">removeErrorListeners<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>parser<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">removeErrorListeners<\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/div>\n<p>Another type of syntax error is based on the rules of a particular language.\u00a0For example,\u00a0in our language,\u00a0a function is identified by its name and number of arguments.\u00a0When the analyzer encounters a function call,\u00a0it checks whether a function with the same name and number of arguments exists.\u00a0If not,\u00a0then it throws an error.\u00a0To do this,\u00a0we need to override the\u00a0<code>visitFunctionCall<\/code>\u00a0method:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#5fb4b4;\">@<\/span><span style=\"color:#6699cc;\">Override<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">visitFunctionCall<\/span>(<span style=\"color:#6699cc;font-style:italic;\">FunctionCallContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#6699cc;font-style:italic;\">String<\/span> funName <span style=\"color:#f97b58;\">=<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;font-style:italic;\">IDENTIFIER<\/span>()<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getText<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">int<\/span> argumentsCount <span style=\"color:#f97b58;\">=<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">expression<\/span>()<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">size<\/span>()<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">var<\/span> funSignature <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">FunctionSignature<\/span>(funName<span style=\"color:#ac7a68;\">,<\/span> argumentsCount<span style=\"color:#ac7a68;\">,<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getParent<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">find <\/span><span style=\"color:#999999;\">a <\/span><span style=\"color:#999999;\">function <\/span><span style=\"color:#999999;\">in <\/span><span style=\"color:#999999;\">the <\/span><span style=\"color:#999999;\">context <\/span><span style=\"color:#999999;\">by <\/span><span style=\"color:#999999;\">signature <\/span><span style=\"color:#999999;\">(<\/span><span style=\"color:#999999;\">name+number <\/span><span style=\"color:#999999;\">of <\/span><span style=\"color:#999999;\">arguments)<\/span><br \/>    <span style=\"color:#c695c6;font-style:italic;\">var<\/span> handler <span style=\"color:#f97b58;\">=<\/span> context<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getFunction<\/span>(funSignature)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#c695c6;\">if<\/span> (handler <span style=\"color:#f97b58;\">==<\/span> <span style=\"color:#ec5f66;font-style:italic;\">null<\/span>) {<br \/>        <span style=\"color:#6699cc;\">addIssue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">ERROR<\/span><span style=\"color:#ac7a68;\">,<\/span> ctx<span style=\"color:#f97b58;\">.<\/span>start<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Function <\/span><span style=\"color:#80b979;\">with <\/span><span style=\"color:#80b979;\">such <\/span><span style=\"color:#80b979;\">signature <\/span><span style=\"color:#80b979;\">not <\/span><span style=\"color:#80b979;\">found: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> funName)<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SKIP<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">code <\/span><span style=\"color:#999999;\">omitted<\/span><br \/>}<\/div>\n<p>Let&#8217;s check the\u00a0<code>if<\/code>\u00a0construct.\u00a0Jimple requires that the expression in the\u00a0<code>if<\/code>\u00a0condition is of\u00a0<code>boolean<\/code>\u00a0type:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#5fb4b4;\">@<\/span><span style=\"color:#6699cc;\">Override<\/span><br \/><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">visitIfStatement<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IfStatementContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">visit <\/span><span style=\"color:#999999;\">expression<\/span><br \/>    <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> condition <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#6699cc;\">visit<\/span>(ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">expression<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">skip <\/span><span style=\"color:#999999;\">if <\/span><span style=\"color:#999999;\">expression <\/span><span style=\"color:#999999;\">contains <\/span><span style=\"color:#999999;\">error<\/span><br \/>    <span style=\"color:#c695c6;\">if<\/span> (condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">isSkip<\/span>()) {<br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SKIP<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#c695c6;\">if<\/span> (<span style=\"color:#f97b58;\">!<\/span>condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">isBool<\/span>()) {<br \/>        <span style=\"color:#6699cc;\">addIssue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">WARNING<\/span><span style=\"color:#ac7a68;\">,<\/span> ctx<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">expression<\/span>()<span style=\"color:#f97b58;\">.<\/span>start<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">The <\/span><span style=\"color:#c695c6;\">\\&#8221;<\/span><span style=\"color:#80b979;\">if<\/span><span style=\"color:#c695c6;\">\\&#8221;<\/span><span style=\"color:#80b979;\"> <\/span><span style=\"color:#80b979;\">condition <\/span><span style=\"color:#80b979;\">must <\/span><span style=\"color:#80b979;\">be <\/span><span style=\"color:#80b979;\">of <\/span><span style=\"color:#80b979;\">boolean <\/span><span style=\"color:#80b979;\">type <\/span><span style=\"color:#80b979;\">only. <\/span><span style=\"color:#80b979;\">But <\/span><span style=\"color:#80b979;\">found: <\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span> <span style=\"color:#f97b58;\">+<\/span> condition<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">type<\/span>())<span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">code <\/span><span style=\"color:#999999;\">omitted<\/span><br \/>}<\/div>\n<p>The attentive reader will notice that in this case we added a warning,\u00a0not an error.\u00a0This is done due to the fact that our language is dynamic,\u00a0and we don&#8217;t always know the exact information about the type of the expression.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Identifysemanticerrors\">Identify semantic errors<\/h2>\n<p>As mentioned earlier,\u00a0semantic errors are difficult to find and can often be found only during debugging or testing the program.\u00a0However,\u00a0some of them can be identified at the compilation stage.\u00a0For example,\u00a0if we know that the function\u00a0<code>X<\/code>\u00a0always returns\u00a0<code>0<\/code>,\u00a0then we can show a warning if a division expression uses this function as a divisor.\u00a0Division by zero is usually considered a semantic error,\u00a0since division by zero makes no sense in mathematics.<\/p>\n<p>An example of error detection\u00a0&#8220;<a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Division_by_zero\" rel=\"nofollow\">Division by zero<\/a>&#8220;:\u00a0triggered when an expression is used as a divisor,\u00a0which always returns the value\u00a0<code>0<\/code>:<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">checkBinaryOperatorForNumeric<\/span>(<span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#f9ae58;\">left<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#f9ae58;\">right<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">Token<\/span> <span style=\"color:#f9ae58;\">operator<\/span>) {<br \/>    <span style=\"color:#c695c6;\">if<\/span> (operator<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getType<\/span>() <span style=\"color:#f97b58;\">==<\/span> <span style=\"color:#6699cc;font-style:italic;\">JimpleParser<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SLASH<\/span> <span style=\"color:#f97b58;\">&amp;&amp;<\/span> right<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">hasValue<\/span>() <span style=\"color:#f97b58;\">&amp;&amp;<\/span> ((<span style=\"color:#6699cc;font-style:italic;\">Number<\/span>) right<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">value<\/span>())<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">longValue<\/span>() <span style=\"color:#f97b58;\">==<\/span> <span style=\"color:#f9ae58;\">0<\/span>) {<br \/>        <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">if <\/span><span style=\"color:#999999;\">we <\/span><span style=\"color:#999999;\">have <\/span><span style=\"color:#999999;\">value <\/span><span style=\"color:#999999;\">of <\/span><span style=\"color:#999999;\">right&#8217;s <\/span><span style=\"color:#999999;\">part <\/span><span style=\"color:#999999;\">of <\/span><span style=\"color:#999999;\">division <\/span><span style=\"color:#999999;\">expression <\/span><span style=\"color:#999999;\">and <\/span><span style=\"color:#999999;\">it&#8217;s <\/span><span style=\"color:#999999;\">zero<\/span><br \/>        <span style=\"color:#6699cc;\">addIssue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">WARNING<\/span><span style=\"color:#ac7a68;\">,<\/span> operator<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Division <\/span><span style=\"color:#80b979;\">by <\/span><span style=\"color:#80b979;\">zero<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span>)<span style=\"color:#ac7a68;\">;<\/span><br \/>    }<\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">code <\/span><span style=\"color:#999999;\">omitted<\/span><br \/>}<\/div>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Runtimeerrors\">Runtime errors<\/h2>\n<p>Runtime errors are also difficult or even impossible to detect at the compilation\/interpretation stage.\u00a0However,\u00a0some such errors can still be identified.\u00a0For example,\u00a0if a function calls itself\u00a0(either directly or through another function),\u00a0this may result in a stack overflow error\u00a0(<a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Stack_overflow\" rel=\"nofollow\">StackOverflow<\/a>).\u00a0The first thing we need to do is to declare a list\u00a0(Set)\u00a0where we will store the functions that are in the process of being called at the moment.\u00a0The check itself can\u00a0(and should)\u00a0be placed in the\u00a0<strong>handleFuncInternal<\/strong>\u00a0method of processing the function call.\u00a0At the beginning of this method,\u00a0we check whether the current\u00a0<strong>FunctionDefinitionContext<\/strong>\u00a0(function declaration context)\u00a0is in the list of already called functions,\u00a0and if that is the case,\u00a0we log a Warning and interrupt further processing of the function.\u00a0If not,\u00a0then we add the current context to our list,\u00a0and the rest of the logic follows.\u00a0When exiting handleFuncInternal,\u00a0you need to remove the current function context from the list.\u00a0Here it should be noted that in this case we not only identified a potential StackOverflow,\u00a0but also got rid of the same error when diagnosing error,\u00a0namely when looping the handleFuncInternal method.<\/p>\n<div style=\"white-space:pre;font-family:Monospace;color:#333333;background-color:#f8f8f8;-moz-tab-size:2;tab-size:2;border:1px solid #E5E5E5;padding:3px;margin: 6px 0 6px 0;font-size:12px;\"><span style=\"color:#6699cc;font-style:italic;\">Set<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#6699cc;font-style:italic;\">FunctionDefinitionContext<\/span><span style=\"color:#5fb4b4;\">><\/span> calledFuncs <span style=\"color:#f97b58;\">=<\/span> <span style=\"color:#c695c6;\">new<\/span> <span style=\"color:#6699cc;font-style:italic;\">HashSet<\/span><span style=\"color:#5fb4b4;\">&lt;><\/span>()<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p><span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span> <span style=\"color:#5fb4b4;\">handleFuncInternal<\/span>(<span style=\"color:#6699cc;font-style:italic;\">List<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#6699cc;font-style:italic;\">String<\/span><span style=\"color:#5fb4b4;\">><\/span> <span style=\"color:#f9ae58;\">parameters<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">List<\/span><span style=\"color:#5fb4b4;\">&lt;<\/span><span style=\"color:#6699cc;font-style:italic;\">Object<\/span><span style=\"color:#5fb4b4;\">><\/span> <span style=\"color:#f9ae58;\">arguments<\/span><span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">FunctionDefinitionContext<\/span> <span style=\"color:#f9ae58;\">ctx<\/span>) {<br \/>    <span style=\"color:#c695c6;\">if<\/span> (calledFuncs<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">contains<\/span>(ctx)) {<br \/>        <span style=\"color:#6699cc;\">addIssue<\/span>(<span style=\"color:#6699cc;font-style:italic;\">IssueType<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">WARNING<\/span><span style=\"color:#ac7a68;\">,<\/span> ctx<span style=\"color:#f97b58;\">.<\/span>name<span style=\"color:#ac7a68;\">,<\/span> <span style=\"color:#6699cc;font-style:italic;\">String<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">format<\/span>(<span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#80b979;\">Recursive <\/span><span style=\"color:#80b979;\">call <\/span><span style=\"color:#80b979;\">of <\/span><span style=\"color:#80b979;\">function <\/span><span style=\"color:#80b979;\">&#8216;%s&#8217; <\/span><span style=\"color:#80b979;\">can <\/span><span style=\"color:#80b979;\">lead <\/span><span style=\"color:#80b979;\">to <\/span><span style=\"color:#80b979;\">StackOverflow<\/span><span style=\"color:#5fb4b4;\">&#8220;<\/span><span style=\"color:#ac7a68;\">,<\/span> ctx<span style=\"color:#f97b58;\">.<\/span>name<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">getText<\/span>()))<span style=\"color:#ac7a68;\">;<\/span><br \/>        <span style=\"color:#c695c6;\">return<\/span> <span style=\"color:#6699cc;font-style:italic;\">ValidationInfo<\/span><span style=\"color:#f97b58;\">.<\/span><span style=\"color:#c695c6;\">SKIP<\/span><span style=\"color:#ac7a68;\">;<\/span><br \/>    }<br \/>    calledFuncs<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">add<\/span>(ctx)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">other <\/span><span style=\"color:#999999;\">checkings<\/span><\/p>\n<p>    calledFuncs<span style=\"color:#f97b58;\">.<\/span><span style=\"color:#6699cc;\">remove<\/span>(ctx)<span style=\"color:#ac7a68;\">;<\/span><\/p>\n<p>    <span style=\"color:#999999;\">\/\/<\/span><span style=\"color:#999999;\"> <\/span><span style=\"color:#999999;\">return <\/span><span style=\"color:#999999;\">resulting <\/span><span style=\"color:#999999;\">ValidationInfo<\/span><br \/>}<\/div>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Control\/data-flowanalysis\">Control\/data-flow analysis<\/h2>\n<p>For a deeper study of program code,\u00a0optimization and identification of complex errors,\u00a0<strong>Control-flow analysis<\/strong>\u00a0and\u00a0<strong>Data-flow analysis<\/strong>\u00a0are also used.<\/p>\n<p>Control flow analysis is focused on understanding which parts of a program are executed depending on various conditions and control structures such as conditional\u00a0(if-else)\u00a0statements,\u00a0loops,\u00a0and branches.\u00a0It allows you to identify the program execution paths and detect potential errors associated with incorrect flow control logic.\u00a0For example,\u00a0unreachable code or potential program hangpoints.<\/p>\n<p>Data flow analysis,\u00a0on the other hand,\u00a0focuses on how data is distributed and used within a program.\u00a0It helps identify potential data problems such as the use of uninitialized variables,\u00a0data dependencies,\u00a0and possible memory leaks.\u00a0Data flow analysis can also detect errors associated with incorrect data operations,\u00a0such as the use of incorrect types or incorrect\u00a0(meaningless)\u00a0calculations.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Summary\">Summary<\/h2>\n<p>In this article,\u00a0we have examined the process of adding error and warning diagnostics to your programming language.\u00a0We have learned what does the ANTLR provides out of the box for logging syntax errors.\u00a0We have alos implemented a handling of some errors and potential problems during program execution.<\/p>\n<p>The entire interpreter source code <a class=\"external-link\" href=\"https:\/\/github.com\/intechcore\/articles\/tree\/main\/antlr\/JimpleLang\" target=\"_blank\" rel=\"nofollow noopener\">can be viewed here<\/a>.<\/p>\n<h2 id=\"Articledraft(EN)DevelopingourownprogramminglanguageinJava+ANTLR:diagnosticsoferrors-Links\">Links<\/h2>\n<ul>\n<li><a class=\"external-link\" href=\"https:\/\/www.antlr.org\/api\/Java\/org\/antlr\/v4\/runtime\/ANTLRErrorListener.html\" rel=\"nofollow\">https:\/\/www.antlr.org\/api\/Java\/org\/antlr\/v4\/runtime\/ANTLRErrorListener.html<\/a><\/li>\n<li><a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Control-flow_graph\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki\/Control-flow_graph<\/a><\/li>\n<li><a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Control_flow_analysis\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki\/Control_flow_analysis<\/a><\/li>\n<li><a class=\"external-link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Data-flow_analysis\" rel=\"nofollow\">https:\/\/en.wikipedia.org\/wiki\/Data-flow_analysis<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This is the second article in the series\u00a0\u201cDeveloping your own programming language in Java\u201d,\u00a0first article can be read\u00a0here. At the current stage,\u00a0we have an interpreter capable of executing the commands of our language.\u00a0However,\u00a0this is not enough if we want to check the code for errors and display them in a clear way to the user.\u00a0In &#8230;<\/p>\n","protected":false},"author":3,"featured_media":7222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[],"class_list":{"0":"post-6977","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-articles","8":"anons"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors\" \/>\n<meta property=\"og:description\" content=\"This is the second article in the series\u00a0\u201cDeveloping your own programming language in Java\u201d,\u00a0first article can be read\u00a0here. At the current stage,\u00a0we have an interpreter capable of executing the commands of our language.\u00a0However,\u00a0this is not enough if we want to check the code for errors and display them in a clear way to the user.\u00a0In ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\" \/>\n<meta property=\"og:site_name\" content=\"Intechcore GmbH\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-06T11:00:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-01T11:15:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"845\" \/>\n\t<meta property=\"og:image:height\" content=\"321\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ruslan Absaliamov\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ruslan Absaliamov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\"},\"author\":{\"name\":\"Ruslan Absaliamov\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6\"},\"headline\":\"Developing your own programming language in Java+ANTLR: diagnostics of errors\",\"datePublished\":\"2024-09-06T11:00:16+00:00\",\"dateModified\":\"2025-12-01T11:15:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\"},\"wordCount\":2131,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/intechcore.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg\",\"articleSection\":[\"Articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\",\"url\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\",\"name\":\"Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors\",\"isPartOf\":{\"@id\":\"https:\/\/intechcore.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg\",\"datePublished\":\"2024-09-06T11:00:16+00:00\",\"dateModified\":\"2025-12-01T11:15:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage\",\"url\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg\",\"contentUrl\":\"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg\",\"width\":845,\"height\":321,\"caption\":\"Software-Code close-up\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/intechcore.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/intechcore.com\/en\/articles\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Developing your own programming language in Java+ANTLR: diagnostics of errors\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/intechcore.com\/en\/#website\",\"url\":\"https:\/\/intechcore.com\/en\/\",\"name\":\"Intechcore GmbH - Software Development Company\",\"description\":\"Technology Leading Software Development Company\",\"publisher\":{\"@id\":\"https:\/\/intechcore.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/intechcore.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/intechcore.com\/en\/#organization\",\"name\":\"Intechcore GmbH\",\"alternateName\":\"Software Development Company\",\"url\":\"https:\/\/intechcore.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png\",\"contentUrl\":\"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png\",\"width\":64,\"height\":64,\"caption\":\"Intechcore GmbH\"},\"image\":{\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6\",\"name\":\"Ruslan Absaliamov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/intechcore.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g\",\"caption\":\"Ruslan Absaliamov\"},\"url\":\"https:\/\/intechcore.com\/en\/author\/ruslan-absaliamov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/","og_locale":"en_US","og_type":"article","og_title":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors","og_description":"This is the second article in the series\u00a0\u201cDeveloping your own programming language in Java\u201d,\u00a0first article can be read\u00a0here. At the current stage,\u00a0we have an interpreter capable of executing the commands of our language.\u00a0However,\u00a0this is not enough if we want to check the code for errors and display them in a clear way to the user.\u00a0In ...","og_url":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/","og_site_name":"Intechcore GmbH","article_published_time":"2024-09-06T11:00:16+00:00","article_modified_time":"2025-12-01T11:15:22+00:00","og_image":[{"width":845,"height":321,"url":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg","type":"image\/jpeg"}],"author":"Ruslan Absaliamov","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ruslan Absaliamov","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#article","isPartOf":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/"},"author":{"name":"Ruslan Absaliamov","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6"},"headline":"Developing your own programming language in Java+ANTLR: diagnostics of errors","datePublished":"2024-09-06T11:00:16+00:00","dateModified":"2025-12-01T11:15:22+00:00","mainEntityOfPage":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/"},"wordCount":2131,"commentCount":0,"publisher":{"@id":"https:\/\/intechcore.com\/en\/#organization"},"image":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage"},"thumbnailUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg","articleSection":["Articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/","url":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/","name":"Intechcore GmbH - Developing your own programming language in Java+ANTLR: diagnostics of errors","isPartOf":{"@id":"https:\/\/intechcore.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage"},"image":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage"},"thumbnailUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg","datePublished":"2024-09-06T11:00:16+00:00","dateModified":"2025-12-01T11:15:22+00:00","breadcrumb":{"@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#primaryimage","url":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg","contentUrl":"https:\/\/intechcore.com\/wp-content\/uploads\/2024\/09\/code-1.jpg","width":845,"height":321,"caption":"Software-Code close-up"},{"@type":"BreadcrumbList","@id":"https:\/\/intechcore.com\/en\/entwicklung-einer-eigenen-programmiersprache-in-javaantlr-fehlerdiagnose\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/intechcore.com\/en\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/intechcore.com\/en\/articles\/"},{"@type":"ListItem","position":3,"name":"Developing your own programming language in Java+ANTLR: diagnostics of errors"}]},{"@type":"WebSite","@id":"https:\/\/intechcore.com\/en\/#website","url":"https:\/\/intechcore.com\/en\/","name":"Intechcore GmbH - Software Development Company","description":"Technology Leading Software Development Company","publisher":{"@id":"https:\/\/intechcore.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/intechcore.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/intechcore.com\/en\/#organization","name":"Intechcore GmbH","alternateName":"Software Development Company","url":"https:\/\/intechcore.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png","contentUrl":"https:\/\/new.intechcore.com\/wp-content\/uploads\/2024\/09\/favicon.png","width":64,"height":64,"caption":"Intechcore GmbH"},"image":{"@id":"https:\/\/intechcore.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/366b8eb5c4abbccd8a17d7328dc0a2e6","name":"Ruslan Absaliamov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/intechcore.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9095380f9a38f10fce91553dcefa1b20f0a83ced000c99ab4f17343f92557a10?s=96&d=mm&r=g","caption":"Ruslan Absaliamov"},"url":"https:\/\/intechcore.com\/en\/author\/ruslan-absaliamov\/"}]}},"_links":{"self":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/6977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/comments?post=6977"}],"version-history":[{"count":19,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/6977\/revisions"}],"predecessor-version":[{"id":10154,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/posts\/6977\/revisions\/10154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/media\/7222"}],"wp:attachment":[{"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/media?parent=6977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/categories?post=6977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intechcore.com\/en\/wp-json\/wp\/v2\/tags?post=6977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}