public static void main(String[] args) { try { Scanner consoleInput = new Scanner(System.in); System.out.println("Enter file name: "); String fileName = consoleInput.next(); if (!fileName.endsWith(".t")) { System.out.println("Expecting a LOGO file"); return; } Root program = Parser.parse(Lexer.tokenise(FileManager.contentsOfFile(fileName))); System.out.println("Enter output file name"); String outFileName = consoleInput.next(); if (!outFileName.endsWith(".ps") && !outFileName.endsWith(".eps")) { outFileName += ".ps"; } String output = CodeGenerator.generateCodeText(program); if (ErrorLog.containsErrors()) { ErrorLog.displayErrors(); return; } else { FileManager.writeStringToFile(output, outFileName); } } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } catch (IOException IO) { System.out.println(IO.getMessage()); } }
private void updateDisplay() { // first, set block colours textView.setBackground(getColour(backgroundColour("text-background-colour"))); textView.setForeground(getColour(foregroundColour("text-foreground-colour"))); textView.setCaretColor(getColour(foregroundColour("text-caret-colour"))); problemsView.setBackground(getColour(backgroundColour("problems-background-colour"))); problemsView.setForeground(getColour(foregroundColour("problems-foreground-colour"))); consoleView.setBackground(getColour(backgroundColour("console-background-colour"))); consoleView.setForeground(getColour(foregroundColour("console-foreground-colour"))); // second, set colours on the code! java.util.List<Lexer.Token> tokens = Lexer.tokenise(textView.getText(), true); int pos = 0; for (Lexer.Token t : tokens) { int len = t.toString().length(); if (t instanceof Lexer.RightBrace || t instanceof Lexer.LeftBrace) { highlightArea(pos, len, foregroundColour("text-brace-colour")); } else if (t instanceof Lexer.Strung) { highlightArea(pos, len, foregroundColour("text-string-colour")); } else if (t instanceof Lexer.Comment) { highlightArea(pos, len, foregroundColour("text-comment-colour")); } else if (t instanceof Lexer.Quote) { highlightArea(pos, len, foregroundColour("text-quote-colour")); } else if (t instanceof Lexer.Comma) { highlightArea(pos, len, foregroundColour("text-comma-colour")); } else if (t instanceof Lexer.Identifier) { highlightArea(pos, len, foregroundColour("text-identifier-colour")); } else if (t instanceof Lexer.Integer) { highlightArea(pos, len, foregroundColour("text-integer-colour")); } pos += len; } }