package natlab;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;

import beaver.Parser;

import natlab.ast.Root;

public class Interpreter {
	private Interpreter() {}

	public static void main(String[] args) throws IOException {
		System.out.println("Welcome to the Natlab Interpreter!");
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			System.out.print("> ");
			System.out.flush();

			String line = in.readLine();
			if(line == null) {
				break;
			}

			try {
				NatlabScanner scanner = new NatlabScanner(new StringReader(line));
				NatlabParser parser = new NatlabParser();
				Root original = (Root) parser.parse(scanner);
				
				if(parser.hasError()) {
					System.out.println("**ERROR**");
					for(String error : parser.getErrors()) {
						System.out.println(error);
					}
				} else {
					System.out.println(original.getStructureString());
				}
			} catch(Parser.Exception e) {
				System.out.println("**ERROR**");
				System.out.println(e.getMessage());
			}
		}
		System.out.println("Goodbye!");
	}
}

@@ -144,46 +144,45 @@
 ort 
-beaver.Parser;%0A%0Aimport natlab.ast.Root
+natlab.ast.Root;%0Aimport beaver.Parser
 ;%0A%0Ap
@@ -569,16 +569,61 @@
 ;%0A%09%09%09%7D%0A%0A
+%09%09%09NatlabParser parser = new NatlabParser();%0A
 %09%09%09try %7B
@@ -698,54 +698,8 @@
 ));%0A
-%09%09%09%09NatlabParser parser = new NatlabParser();%0A
 %09%09%09%09
@@ -748,13 +748,8 @@
 r);%0A
-%09%09%09%09%0A
 %09%09%09%09
@@ -1037,24 +1037,24 @@
 *ERROR**%22);%0A
-
 %09%09%09%09System.o
@@ -1081,16 +1081,99 @@
 age());%0A
+%09%09%09%09for(String error : parser.getErrors()) %7B%0A%09%09%09%09%09System.out.println(error);%0A%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Print error list in exception case.