import java.io.*;
/**
* Simple Parser driver.
*/
public class ParseTest {
/**
* Test harness for the Parser class.pathname to parse. Command switches
* must precede the filepath.
*
* - -methods, -nomethods
* - enable/disable tracing of method entry/exit
* - -symbols, -nosymbols
* - enable/disable tracing of Symbols as they are defined
* - filepath
* - pathname of the file to parse. If not specified,
* then the program tries to parse "fm/hello.fm".
*
* @param arg the String array of command switches and arguments
* @throws IOException thrown if any IO errors occur during processing
*/
public static void main(String[] arg) throws IOException {
boolean methods = true;
boolean symbols = false;
String in = "fm/tA.fm";
int argN = 0;
// check for -switches
while (argN < arg.length) {
if (arg[argN].charAt(0) != '-') break;
String tag = arg[argN];
if (tag.equals("-methods")) methods=true;
else if (tag.equals("-nomethods")) methods=false;
else if (tag.equals("-symbols")) symbols = true;
else if (tag.equals("-nosymbols")) symbols = false;
else System.out.println("unrecognized switch: "+tag);
argN++;
}
// check for file pathname
if (argN < arg.length) {
in = arg[argN];
}
CompilerIO io = new CompilerIO(in,"txt");
io.setEchoing(true);
io.setEchoPrefix("% ");
SymbolTable sym = new SymbolTable(2);
Scanner lex = new Scanner(io,sym);
Parser p = new Parser(io,sym,lex);
p.setShowMethods(methods);
p.setShowSymbols(symbols);
if (p.parse()) {
System.out.println("Parsed "+in+" successfully.");
} else {
System.out.println("Parse errors in "+in);
}
io.closeAll();
}
}