I am creating a parser for the class. The user will have to enter the equation with one place between each element. Then each element is read in the same array in its index. I keep getting stack overflow, I think this is because the last calling of only my CallClass function actually stops. However, if this is the case, then I am not sure how to organize the code to avoid this. Thanks in advance for any help.
import java.util.Scanner; Public class interpreter {public static zero main (string [] args) {// scanners scanned = New scanner (System.in) read in values as a string; String expression = scan NXtine (); // Save each token to array string [] tokens = expressions.split ("\\ s +"); Int solve = 0; Int o = 0; // call myCalculus function which will call other functions System.out.println (myCalculus (token, 0, solved)); } Public static int myCalculus (string [] token, int o, int solved) {while (lieu; token.length-1) {if (token [o] .equals ("*")) {multiply (token, O, solved); } And if (token [o]. Equals ("+")) {add (token, o, solution); } And if (token [o]. Equals ("& lt;")) {comparison (token, o, solution); } And if (token [o]. Equals ("& lt; =")) {comparison (token, o, solution); } And if (token [o]. Equals ("& gt;")) {comparison (token, o, solution); } And if (token [o]. Equals ("& lt; =")) {comparison (token, o, solution); } And {ifc (token [o]. Par ("(")) {myCalculus (token, O ++, hull);} Other {myCalculus (token, O ++, hull);}} Solved;} Public Add Stable Zero (string [] token, int o, int solution) {if (token [o ++]. Matches ("[- +]? \\ d * \\.? \\ \\ d +")) {solve = Resolved + integer.parseint (token [o-]) + integer. Parseint (token [o ++]); MichaelClus (token, o ++, solution);} Other (myCalculus (token, O ++, Hull);}} Public static zero times (string [] token, int o, int solved) {if (token [o ++]. Matches ("[- +]? \\ d * \\.? \\ d + ")) {Solved = solved + Integer.parseInt (Token, [o ++]); Merculous (token, o ++, solution);} Other {myCalculus (token, O ++, hull);}} Public static void (String [] token, int o, int solution {if (token [o ++]. Matches ("[- +]? \\ d * \\. \\ \\ d +")) {if ( Token [o] .equals ("& lt;") {solved = solved + ((Integer.parseInt (token [O--]) Integer. PRIIENT (token [O ++]))? 1: 0};} and if (token [o] .equals ("& gt;")) {resol = resolved + ((integer. PRIINT (token [o -])> integer .Portset (token [O ++] )) 1: 0); } And if (token [o]. Equals ("& lt; =") {resolve = resolved + ((integer. PRIINT (token [o -]) & lt; = integer. PRIINT (token [O ++ ]))? 1: 0); } And (Hull = Hull) + ((Integer PRIINT (Token [O -])> = Integer. PRIINT (Token [O ++])) 1: 0); } MyCalculus (token, O ++, solution); } Other {myCalculus (token, O ++, solution); }}}}
"post-text" itemprop = "text">I think that to change your code,
++ o
instead ofO ++
:myCalculus (token, ++ o, solved);
Your current code simply increments
o
after callcode> myCalculus , so whenever you face a bracket, your The code will enter the infinite loop.
Comments
Post a Comment