/** * print error message with location information * * @param file the file the error occurred for * @param message the code of the error message to print * @param line the line number of error position * @param column the column of error position */ public static void error(File file, ErrorMessages message, int line, int column) { String msg = NL + "Error"; if (file != null) { msg += " in file \"" + file + "\""; } if (line >= 0) { msg = msg + " (line " + (line + 1) + ")"; } try { err(msg + ": " + NL + ErrorMessages.get(message)); } catch (IndexOutOfRangeException) { err(msg); } errors++; if (line >= 0) { if (column >= 0) { showPosition(file, line, column); } else { showPosition(file, line); } } }
/** * Report generation progress. * * @param message the message to be printed * @param data data to be inserted into the message */ public static void println(ErrorMessages message, int data) { if (Options.verbose) { @out.WriteLine(ErrorMessages.get(message, data)); } }
/** * Emits the next part of the skeleton */ public void emitNext() { if (isCSharpSkeleton) { if (Options.emit_csharp) { pos++; @out.Write(line[pos++]); } else { @out.Write(line[pos++]); pos++; } } else { if (Options.emit_csharp && !notCSharpSkeletonWarned) { Out.warning(ErrorMessages.get(ErrorMessages.NOT_CSHARP_SKELETON)); notCSharpSkeletonWarned = true; } @out.Write(line[pos++]); } }
/** * Report time statistic data. * * @param message the message to be printed * @param time elapsed time */ public static void time(ErrorMessages message, Timer time) { if (Options.time) { String msg = ErrorMessages.get(message, time.ToString()); @out.WriteLine(msg); } }
/** * Expands the specified macro by replacing each macro usage * with the stored definition. * * @param name the name of the macro to expand (for detecting cycles) * @param definition the definition of the macro to expand * * @return the expanded definition of the macro. * * @throws MacroException when an error (such as a cyclic definition) * occurs during expansion */ private RegExp expandMacro(String name, RegExp definition) { #if DEBUG_TRACE log.WriteLine("expandMacro(String name = \"{0}\", RegExp definition = {1})", name, definition); #endif // DEBUG_TRACE // Out.print("checking macro "+name); // Out.print("definition is "+definition); switch (definition.type) { case sym.BAR: case sym.CONCAT: RegExp2 binary = (RegExp2)definition; binary.r1 = expandMacro(name, binary.r1); binary.r2 = expandMacro(name, binary.r2); return(definition); case sym.STAR: case sym.PLUS: case sym.QUESTION: case sym.BANG: case sym.TILDE: RegExp1 unary = (RegExp1)definition; unary.content = expandMacro(name, (RegExp)unary.content); return(definition); case sym.MACROUSE: String usename = (String)((RegExp1)definition).content; if (name.Equals(usename)) { throw new MacroException(ErrorMessages.get(ErrorMessages.MACRO_CYCLE, name)); } RegExp usedef = getDefinition(usename); if (usedef == null) { throw new MacroException(ErrorMessages.get(ErrorMessages.MACRO_DEF_MISSING, usename, name)); } markUsed(usename); return(expandMacro(name, usedef)); case sym.STRING: case sym.STRING_I: case sym.CHAR: case sym.CHAR_I: case sym.CCLASS: case sym.CCLASSNOT: return(definition); default: throw new MacroException("unknown expression type " + definition.type + " in macro expansion"); //$NON-NLS-1$ //$NON-NLS-2$ } }
/** * print a warning with line information * * @param message code of the warning message * @param line the line information * * @see ErrorMessages */ public static void warning(ErrorMessages message, int line) { warnings++; String msg = NL + "Warning"; if (line > 0) { msg = msg + " in line " + (line + 1); } err(msg + ": " + ErrorMessages.get(message)); }
/** * Creates a new ScannerException for a file with a message and line number. * * @param message the code for the error description presented to the user. * @param line the number of the line in the specification that * contains the error */ public ScannerException(File file, ErrorMessages message, int line) : this(file, ErrorMessages.get(message), message, line, -1) { }
/** * Creates a new ScannerException with a message and line number. * * @param message the code for the error description presented to the user. * @param line the number of the line in the specification that * contains the error */ public ScannerException(ErrorMessages message, int line) : this(null, ErrorMessages.get(message), message, line, -1) { }
/** * IO error message for a file (displays file * name in parentheses). * * @param message the code of the error message * @param file the file it occurred for */ public static void error(ErrorMessages message, File file) { errors++; err(NL + "Error: " + ErrorMessages.get(message) + " (" + file + ")"); }
/** * print error message with data * * @param data data to insert into the message * @param message the code of the error message * * @see ErrorMessages */ public static void error(ErrorMessages message, String data) { errors++; err(NL + "Error: " + ErrorMessages.get(message, data)); }
/** * print error message (code) * * @param message the code of the error message * * @see ErrorMessages */ public static void error(ErrorMessages message) { errors++; err(NL + "Error: " + ErrorMessages.get(message)); }
public const String version = "1.4"; //$NON-NLS-1$ /** * Generates a scanner for the specified input file. * * @param inputFile a file containing a lexical specification * to generate a scanner for. */ public static void generate(File inputFile) { Out.resetCounters(); Timer totalTime = new Timer(); Timer time = new Timer(); LexScan scanner = null; LexParse parser = null; TextReader inputReader = null; totalTime.start(); try { Out.println(ErrorMessages.READING, inputFile.ToString()); inputReader = new StreamReader(inputFile); scanner = new LexScan(inputReader); scanner.setFile(inputFile); parser = new LexParse(scanner); } catch (FileNotFoundException) { Out.error(ErrorMessages.CANNOT_OPEN, inputFile.ToString()); throw new GeneratorException(); } try { NFA nfa = (NFA)parser.parse().value; Out.checkErrors(); if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.NFA_IS) + Out.NL + nfa + Out.NL); } if (Options.dot) { nfa.writeDot(Emitter.normalize("nfa.dot", null)); //$NON-NLS-1$ } Out.println(ErrorMessages.NFA_STATES, nfa.numStates); time.start(); DFA dfa = nfa.getDFA(); time.stop(); Out.time(ErrorMessages.DFA_TOOK, time); dfa.checkActions(scanner, parser); nfa = null; if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.DFA_IS) + Out.NL + dfa + Out.NL); } if (Options.dot) { dfa.writeDot(Emitter.normalize("dfa-big.dot", null)); //$NON-NLS-1$ } time.start(); dfa.minimize(); time.stop(); Out.time(ErrorMessages.MIN_TOOK, time); if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.MIN_DFA_IS) + Out.NL + dfa); } if (Options.dot) { dfa.writeDot(Emitter.normalize("dfa-min.dot", null)); //$NON-NLS-1$ } time.start(); Emitter e = new Emitter(inputFile, parser, dfa); e.emit(); time.stop(); Out.time(ErrorMessages.WRITE_TOOK, time); totalTime.stop(); Out.time(ErrorMessages.TOTAL_TIME, totalTime); } catch (ScannerException e) { Out.error(e.file, e.message, e.line, e.column); throw new GeneratorException(); } catch (MacroException e) { Out.error(e.Message); throw new GeneratorException(); } catch (IOException e) { Out.error(ErrorMessages.IO_ERROR, e.ToString()); throw new GeneratorException(); } catch (OutOfMemoryException) { Out.error(ErrorMessages.OUT_OF_MEMORY); throw new GeneratorException(); } catch (GeneratorException) { throw new GeneratorException(); } catch (Exception e) { Out.error(e.ToString()); throw new GeneratorException(); } }