import java.util.regex.Matcher; import java.util.regex.Pattern; import java.io.*; import java.util.ArrayList; import java.io.File; import java.io.InputStreamReader; import java.io.FileInputStream; import java.lang.String; class Reader { private File openedFile_; private BufferedReader reader_; private ArrayList readedText_; public Reader(String path) { openedFile_ = new File(path); try { reader_ = new BufferedReader(new InputStreamReader(new FileInputStream(openedFile_), "UTF-8")); } catch (UnsupportedEncodingException exc) { System.out.println(" UTF-8 exception. " + exc.getMessage()); } catch (FileNotFoundException exc) { System.out.println("File Not Found. " + exc.getMessage()); } readedText_ = new ArrayList(); } public ArrayList Read() { String currentString; try { while((currentString = reader_.readLine()) != null) { readedText_.add(currentString); } } catch (IOException exc) { System.out.println("IOException while reading file. " + exc.getMessage()); } return new ArrayList(readedText_); } } public class main { public static void main(String args[]) { String program; try { File f = new File("C:/Users/Denis/file.txt"); char[] CB = new char[(int) f.length()]; Reader reader = new InputStreamReader(new FileInputStream(f), "UTF-8"); reader.read(CB); program = new String(CB); } catch (Exception ex) { System.out.println(ex); return; } Compiler comp = new Compiler(); Scanner scan = new Scanner(program, comp); Token t; while( (t = scan.NextToken()).Tag() != DomainTag.END_OF_PROGRAM){ System.out.print(t.Tag() + " "); System.out.print(t.Coords() + " "); switch (t.Tag()){ case IDENT: System.out.print((((IdentToken) t).Code) + "\n"); break; case OPER: System.out.print(((OperToken)t).Num + "\n"); break; case NUMBER: System.out.print(((NumberToken)t).Value + "\n"); break; } } comp.OutputMessages(); } }