/* 
 * Copyright (C) 2007  Anders Nilsson <anders.nilsson@cs.lth.se>
 *
 * This file is part of XmlSchemaCompiler.
 */

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;

import AST.SchemaParser;
import AST.ParseException;
import AST.Start;

public class Parser {
    
    protected static Start parse(String args[]) {
	Reader r = getReader(args);
	Start ast = null;
	try {
	    SchemaParser parser = new SchemaParser(r);

	    ast = parser.Start();
	} catch (ParseException e) {
	    System.out.println(e.getMessage());
	}
	return ast;
    }

    private static Reader getReader(String[] args) {
	Reader r = null;
	if (args.length != 1) {
	    r = new InputStreamReader(System.in);
	} else {
	    try {
		r = new FileReader(args[0]);
	    } catch (FileNotFoundException e1) {
		System.err.println("Dumper: file " + args[0] + " not found");
	    }
	}
	return r;
    }

}