From 0f0236190e0c040b131bfecdd0c83884b2727e69 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Fri, 11 May 2007 15:30:50 +0000 Subject: [PATCH] Added parser utility method to test if a string is a PRISM language keyword. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@329 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/PrismParser.java | 146 ++++++++++-------- prism/src/parser/PrismParser.jj | 16 ++ prism/src/parser/PrismParserTokenManager.java | 1 + 3 files changed, 98 insertions(+), 65 deletions(-) diff --git a/prism/src/parser/PrismParser.java b/prism/src/parser/PrismParser.java index dabf96c2..87991c06 100644 --- a/prism/src/parser/PrismParser.java +++ b/prism/src/parser/PrismParser.java @@ -3,6 +3,7 @@ package parser; import java.io.*; import java.util.Vector; +import java.util.ArrayList; import java.util.Stack; import prism.PrismException; @@ -19,6 +20,8 @@ public class PrismParser implements PrismParserConstants { private static Stack reverseStack = new Stack(); // temp store for modules file associated with properties file private static ModulesFile modulesFile; + // list of keyword strings + private static ArrayList keywordList = new ArrayList(); //----------------------------------------------------------------------------------- // main method for testing purposes @@ -120,7 +123,13 @@ public class PrismParser implements PrismParserConstants { public PrismParser() { + // Call default constructor this(System.in); + // Build a list of strings for keywords + keywordList.clear(); + for (int i = PrismParserConstants.COMMENT+1; i < PrismParserConstants.NOT; i++) { + keywordList.add(PrismParserConstants.tokenImage[i].replaceAll("\"", "")); + } } // parse modules file @@ -295,6 +304,13 @@ public class PrismParser implements PrismParserConstants { return res; } + // Test a string to see if it is a PRISM language keyword + + public static boolean isKeyword(String s) + { + return keywordList.contains(s); + } + //----------------------------------------------------------------------------------- // top-level stuff //----------------------------------------------------------------------------------- @@ -3913,71 +3929,6 @@ public class PrismParser implements PrismParserConstants { finally { jj_save(184, xla); } } - static final private boolean jj_3R_72() { - if (jj_3R_92()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_142()) jj_scanpos = xsp; - return false; - } - - static final private boolean jj_3_166() { - if (jj_scan_token(FLOOR)) return true; - return false; - } - - static final private boolean jj_3R_58() { - if (jj_3R_61()) return true; - if (jj_scan_token(UNTIL)) return true; - if (jj_3R_61()) return true; - return false; - } - - static final private boolean jj_3_91() { - if (jj_3R_60()) return true; - return false; - } - - static final private boolean jj_3_141() { - if (jj_3R_72()) return true; - return false; - } - - static final private boolean jj_3_69() { - if (jj_scan_token(DIVIDE)) return true; - if (jj_scan_token(LBRACE)) return true; - if (jj_3R_48()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_67()) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(RBRACE)) return true; - return false; - } - - static final private boolean jj_3R_84() { - if (jj_scan_token(LPARENTH)) return true; - if (jj_3R_35()) return true; - if (jj_scan_token(RPARENTH)) return true; - return false; - } - - static final private boolean jj_3R_47() { - if (jj_3R_88()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_66()) { jj_scanpos = xsp; break; } - } - return false; - } - - static final private boolean jj_3_33() { - if (jj_3R_37()) return true; - return false; - } - static final private boolean jj_3_98() { if (jj_scan_token(LE)) return true; if (jj_3R_35()) return true; @@ -5935,6 +5886,71 @@ public class PrismParser implements PrismParserConstants { return false; } + static final private boolean jj_3R_72() { + if (jj_3R_92()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_142()) jj_scanpos = xsp; + return false; + } + + static final private boolean jj_3_166() { + if (jj_scan_token(FLOOR)) return true; + return false; + } + + static final private boolean jj_3R_58() { + if (jj_3R_61()) return true; + if (jj_scan_token(UNTIL)) return true; + if (jj_3R_61()) return true; + return false; + } + + static final private boolean jj_3_91() { + if (jj_3R_60()) return true; + return false; + } + + static final private boolean jj_3_141() { + if (jj_3R_72()) return true; + return false; + } + + static final private boolean jj_3_69() { + if (jj_scan_token(DIVIDE)) return true; + if (jj_scan_token(LBRACE)) return true; + if (jj_3R_48()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_67()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + static final private boolean jj_3R_84() { + if (jj_scan_token(LPARENTH)) return true; + if (jj_3R_35()) return true; + if (jj_scan_token(RPARENTH)) return true; + return false; + } + + static final private boolean jj_3R_47() { + if (jj_3R_88()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_66()) { jj_scanpos = xsp; break; } + } + return false; + } + + static final private boolean jj_3_33() { + if (jj_3R_37()) return true; + return false; + } + static private boolean jj_initialized_once = false; static public PrismParserTokenManager token_source; static SimpleCharStream jj_input_stream; diff --git a/prism/src/parser/PrismParser.jj b/prism/src/parser/PrismParser.jj index 5156fefa..70555c3b 100644 --- a/prism/src/parser/PrismParser.jj +++ b/prism/src/parser/PrismParser.jj @@ -34,6 +34,7 @@ package parser; import java.io.*; import java.util.Vector; +import java.util.ArrayList; import java.util.Stack; import prism.PrismException; @@ -51,6 +52,8 @@ public class PrismParser private static Stack reverseStack = new Stack(); // temp store for modules file associated with properties file private static ModulesFile modulesFile; + // list of keyword strings + private static ArrayList keywordList = new ArrayList(); //----------------------------------------------------------------------------------- // main method for testing purposes @@ -152,7 +155,13 @@ public class PrismParser public PrismParser() { + // Call default constructor this(System.in); + // Build a list of strings for keywords + keywordList.clear(); + for (int i = PrismParserConstants.COMMENT+1; i < PrismParserConstants.NOT; i++) { + keywordList.add(PrismParserConstants.tokenImage[i].replaceAll("\"", "")); + } } // parse modules file @@ -326,6 +335,13 @@ public class PrismParser if (comment.trim().length()>0) res += "// " + comment + "\n"; return res; } + + // Test a string to see if it is a PRISM language keyword + + public static boolean isKeyword(String s) + { + return keywordList.contains(s); + } } //----------------------------------------------------------------------------------- diff --git a/prism/src/parser/PrismParserTokenManager.java b/prism/src/parser/PrismParserTokenManager.java index fbade7d1..07d05856 100644 --- a/prism/src/parser/PrismParserTokenManager.java +++ b/prism/src/parser/PrismParserTokenManager.java @@ -2,6 +2,7 @@ package parser; import java.io.*; import java.util.Vector; +import java.util.ArrayList; import java.util.Stack; import prism.PrismException;