Question: I want interpreter For (If else ) in Java using this Parse //^_^ ------------------------------------------------------------------------------------- import java.io.*; public class Parser { private static StreamTokenizer tokens; private
I want interpreter For (If else ) in Java using this Parse //^_^
-------------------------------------------------------------------------------------
import java.io.*; public class Parser { private static StreamTokenizer tokens; private static int token; public static void main(String argv[]) throws IOException { InputStreamReader reader; if (argv.length > 0) reader = new InputStreamReader(new FileInputStream("x.txt")); else reader = new InputStreamReader(System.in); // create the tokenizer: tokens = new StreamTokenizer(reader); tokens.ordinaryChar('.'); tokens.ordinaryChar('-'); tokens.ordinaryChar('/'); // advance to the first token on the input: getToken(); // parse expression and get calculated value: int value = expr(); // check if expression ends with ';' and print value if (token == (int)';') System.out.println("Value = " + value); else System.out.println("Syntax error"); } // getToken - ad1vance to the next token on the input private static void getToken() throws IOException { token = tokens.nextToken(); } // expr - parse
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
