/** * Parse command line options and arguments to set various user-option flags and variables. * * @param argv the command line arguments to be parsed. */ protected static void parse_args(String argv[]) { int len = argv.length; int i; /* parse the options */ for (i = 0; i < len; i++) { /* try to get the various options */ if (argv[i].equals("-package")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-") || argv[i].endsWith(".cup")) usage("-package must have a name argument"); /* record the name */ emit.package_name = argv[i]; } else if (argv[i].equals("-parser")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-") || argv[i].endsWith(".cup")) usage("-parser must have a name argument"); /* record the name */ emit.parser_class_name = argv[i]; } else if (argv[i].equals("-input")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-") || argv[i].endsWith(".cup")) usage("-input must have a name argument"); /* record the name */ emit.input_file_name = argv[i]; } else if (argv[i].equals("-symbols")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-") || argv[i].endsWith(".cup")) usage("-symbols must have a name argument"); /* record the name */ emit.symbol_const_class_name = argv[i]; } else if (argv[i].equals("-nonterms")) { include_non_terms = true; } else if (argv[i].equals("-expect")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-") || argv[i].endsWith(".cup")) usage("-expect must have a name argument"); /* record the number */ try { expect_conflicts = Integer.parseInt(argv[i]); } catch (NumberFormatException e) { usage("-expect must be followed by a decimal integer"); } } else if (argv[i].equals("-out")) { /* must have an arg */ if (++i >= len || argv[i].startsWith("-")) usage("-out must have a path argument"); /* validate path */ if (argv[i].length() != 0) { out_path = argv[i] + File.separator; File f = new File(out_path); if (!f.exists() || !f.isDirectory()) out_path = null; } if (out_path == null) usage("-out argument must be a valid existing path"); } else if (argv[i].equals("-compact_red")) opt_compact_red = true; else if (argv[i].equals("-nosummary")) no_summary = true; else if (argv[i].equals("-nowarn")) emit.nowarn = true; else if (argv[i].equals("-dump_states")) opt_dump_states = true; else if (argv[i].equals("-dump_tables")) opt_dump_tables = true; else if (argv[i].equals("-progress")) print_progress = true; else if (argv[i].equals("-dump_grammar")) opt_dump_grammar = true; else if (argv[i].equals("-dump")) opt_dump_states = opt_dump_tables = opt_dump_grammar = true; else if (argv[i].equals("-time")) opt_show_timing = true; else if (argv[i].equals("-debug")) opt_do_debug = true; else { usage("Unrecognized option \"" + argv[i] + "\""); } } }