From 1518fbdbaedf7f1d18e34509a3d195840e718f94 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Sat, 15 Mar 2008 09:46:17 +0000 Subject: [PATCH] Slight tweaks to PrismParser main method. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@658 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/PrismParser.java | 37 +++++++++++++++++-------------- prism/src/parser/PrismParser.jj | 37 +++++++++++++++++-------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/prism/src/parser/PrismParser.java b/prism/src/parser/PrismParser.java index 46c61c68..a02d4df0 100644 --- a/prism/src/parser/PrismParser.java +++ b/prism/src/parser/PrismParser.java @@ -31,7 +31,7 @@ public class PrismParser implements PrismParserConstants { { if (args.length == 0) { System.out.println("Usage: java parser.PrismParser "); - System.out.println("Where: = -modulesfile or -f"); + System.out.println("Where: = -modulesfile or -mf"); System.out.println(" -propertiesfile or -pf"); System.out.println(" -expression or -e"); System.exit(1); @@ -40,13 +40,16 @@ public class PrismParser implements PrismParserConstants { ModulesFile mf = null; try { PrismParser p = new PrismParser(); - mf = p.parseModulesFile(System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); mf = p.parseModulesFile(new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); mf = p.parseModulesFile(System.in); } System.out.println("Modules file:\n=============\n"); System.out.print(mf); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } System.out.println("\nAnd after expansion:\n====================\n"); @@ -65,20 +68,18 @@ public class PrismParser implements PrismParserConstants { else if (args[0].equals("-propertiesfile") || args[0].equals("-pf")) { PropertiesFile pf = null; try { - // create empty modules file - ModulesFile mf = new ModulesFile(); - mf.setFormulaList(new FormulaList()); - mf.setConstantList(new ConstantList()); - // parse PrismParser p = new PrismParser(); - pf = p.parsePropertiesFile(mf, System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); pf = p.parsePropertiesFile(new ModulesFile(), new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); pf = p.parsePropertiesFile(new ModulesFile(), System.in); } System.out.println("Properties file:\n===============\n"); System.out.print(pf); System.out.print(pf.toTreeString()); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } try { @@ -97,7 +98,8 @@ public class PrismParser implements PrismParserConstants { Expression expr = null; try { PrismParser p = new PrismParser(); - expr = p.parseSingleExpression(System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); expr = p.parseSingleExpression(new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); expr = p.parseSingleExpression(System.in); } System.out.println("Expression: " + expr.toString()); System.out.print("Tree:\n" + expr.toTreeString(0)); expr.check(); @@ -105,12 +107,13 @@ public class PrismParser implements PrismParserConstants { System.out.println("Eval: " + expr.evaluate(null, null)); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); } catch (PrismException e) { - System.out.println("Error:\n" + e.getMessage()); - System.exit(0); + System.out.println("Error:\n" + e.getMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } } } diff --git a/prism/src/parser/PrismParser.jj b/prism/src/parser/PrismParser.jj index ff7581cf..ef42cb2a 100644 --- a/prism/src/parser/PrismParser.jj +++ b/prism/src/parser/PrismParser.jj @@ -63,7 +63,7 @@ public class PrismParser { if (args.length == 0) { System.out.println("Usage: java parser.PrismParser "); - System.out.println("Where: = -modulesfile or -f"); + System.out.println("Where: = -modulesfile or -mf"); System.out.println(" -propertiesfile or -pf"); System.out.println(" -expression or -e"); System.exit(1); @@ -72,13 +72,16 @@ public class PrismParser ModulesFile mf = null; try { PrismParser p = new PrismParser(); - mf = p.parseModulesFile(System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); mf = p.parseModulesFile(new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); mf = p.parseModulesFile(System.in); } System.out.println("Modules file:\n=============\n"); System.out.print(mf); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } System.out.println("\nAnd after expansion:\n====================\n"); @@ -97,20 +100,18 @@ public class PrismParser else if (args[0].equals("-propertiesfile") || args[0].equals("-pf")) { PropertiesFile pf = null; try { - // create empty modules file - ModulesFile mf = new ModulesFile(); - mf.setFormulaList(new FormulaList()); - mf.setConstantList(new ConstantList()); - // parse PrismParser p = new PrismParser(); - pf = p.parsePropertiesFile(mf, System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); pf = p.parsePropertiesFile(new ModulesFile(), new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); pf = p.parsePropertiesFile(new ModulesFile(), System.in); } System.out.println("Properties file:\n===============\n"); System.out.print(pf); System.out.print(pf.toTreeString()); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } try { @@ -129,7 +130,8 @@ public class PrismParser Expression expr = null; try { PrismParser p = new PrismParser(); - expr = p.parseSingleExpression(System.in); + if (args.length > 1) { System.out.println("Reading from "+args[1]+"...\n"); expr = p.parseSingleExpression(new FileInputStream(args[1])); } + else { System.out.println("Reading from stdin...\n"); expr = p.parseSingleExpression(System.in); } System.out.println("Expression: " + expr.toString()); System.out.print("Tree:\n" + expr.toTreeString(0)); expr.check(); @@ -137,12 +139,13 @@ public class PrismParser System.out.println("Eval: " + expr.evaluate(null, null)); } catch (ParseException e) { - System.out.println("Syntax error:\n" + e.getShortMessage()); - System.exit(0); + System.out.println("Syntax error:\n" + e.getShortMessage()); System.exit(0); } catch (PrismException e) { - System.out.println("Error:\n" + e.getMessage()); - System.exit(0); + System.out.println("Error:\n" + e.getMessage()); System.exit(0); + } + catch (FileNotFoundException e) { + System.out.println(e); System.exit(0); } } }