📄 smcparser.java
字号:
")"); } _actionInProgress = new SmcAction(name, lineNumber); } return; } /* package */ void setActionArgs(List<String> args) { if (_actionInProgress == null) { error("There is no in-progress action to which to " + "add the arguments.", _lineNumber); } else { _actionInProgress.setArguments(args); } return; } /* package */ void addAction() { if (_actionList == null) { error("There is no action list to which the " + "action may be added.", _lineNumber); } else if (_actionInProgress == null) { error("There is no in-progress action to add to " + "the list.", _lineNumber); } else { _actionList.add(_actionInProgress); _actionInProgress = null; } return; } // Retrieve the current action's property assignment flag. /* package */ boolean getProperty() { boolean retcode = false; if (_actionInProgress == null) { error("There is no in-progress action, " + "get property flag failed.", _lineNumber); } else { retcode = _actionInProgress.isProperty(); } return (retcode); } // Mark the current action as a .Net assignment. /* package */ void setProperty(boolean flag) { if (_actionInProgress == null) { error("There is no in-progress action, " + "set property flag failed.", _lineNumber); } else { _actionInProgress.setProperty(flag); } return; } /* package */ void clearActions() { if (_actionList != null) { _actionList.clear(); _actionList = null; } return; } /* package */ void createArgList() { if (_argList != null) { error("Cannot create an argument list when one " + "already exists.", _lineNumber); } else { _argList = new ArrayList<String>(); } return; } /* package */ List<String> getArgsList() { List<String> retval = _argList; _argList = null; return(retval); } /* package */ void createArgument(String name, int lineNumber) { if (_argInProgress != null) { error("Cannot create new argument while still " + "filling in previous one.", lineNumber); } else { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); os.println(" CREATE ARG: " + name + "(" + Integer.toString(lineNumber) + ")"); } _argInProgress = name; } return; } /* package */ void addArgument() { if (_argList == null) { error("There is no argument list to which the " + "argument may be added.", _lineNumber); } else if (_argInProgress == null) { error("There is no in-progress argument to add to " + "the list.", _lineNumber); } else { _argList.add(_argInProgress.trim()); _argInProgress = null; } return; } /* package */ void clearArguments() { if (_argList != null) { _argList.clear(); _argList = null; } return; } // // end of State Machine Actions //-----------------------------------------------------------//---------------------------------------------------------------// Member Data// // The FSM name. private String _name; // Store warning and error messages into this list. Do not // output them. That is up to the application. private List<SmcMessage> _messages; // The parse state map. private SmcParserContext _parserFSM; // Get tokens from the lexer. private SmcLexer _lexer; // Keep track of errors. private boolean _parseStatus; private boolean _quitFlag; // Store the parse result here. private SmcFSM _fsm; private SmcMap _mapInProgress; private SmcState _stateInProgress; private String _transitionName; private SmcTransition _transitionInProgress; private SmcGuard _guardInProgress; private SmcParameter _paramInProgress; private SmcAction _actionInProgress; private String _argInProgress; // Store parsed parameters here. private List<SmcParameter> _paramList; // Store parsed transition actions here. private List<SmcAction> _actionList; // Store parsed action arguments here. private List<String> _argList; private int _lineNumber; //----------------------------------------------------------- // Statics. // // Create a hashmap which associates token names with // parser transitions. When a token is received, use this // table to get the appropriate transition method and // invoke that method. private static Method[] _TransMethod; static { String transName = "<not set>"; _TransMethod = new Method[SmcLexer.TOKEN_COUNT]; try { Class fsmClass = SmcParserContext.class; Class[] paramTypes = new Class[1]; paramTypes[0] = SmcLexer.Token.class; transName = "ENTRY"; _TransMethod[SmcLexer.ENTRY] = fsmClass.getDeclaredMethod("ENTRY", paramTypes); transName = "EXIT"; _TransMethod[SmcLexer.EXIT] = fsmClass.getDeclaredMethod("EXIT", paramTypes); transName = "JUMP"; _TransMethod[SmcLexer.JUMP] = fsmClass.getDeclaredMethod("JUMP", paramTypes); transName = "POP"; _TransMethod[SmcLexer.POP] = fsmClass.getDeclaredMethod("POP", paramTypes); transName = "PUSH"; _TransMethod[SmcLexer.PUSH] = fsmClass.getDeclaredMethod("PUSH", paramTypes); transName = "WORD"; _TransMethod[SmcLexer.WORD] = fsmClass.getDeclaredMethod("WORD", paramTypes); transName = "START_STATE"; _TransMethod[SmcLexer.START_STATE] = fsmClass.getDeclaredMethod("START_STATE", paramTypes); transName = "MAP_NAME"; _TransMethod[SmcLexer.MAP_NAME] = fsmClass.getDeclaredMethod("MAP_NAME", paramTypes); transName = "CLASS_NAME"; _TransMethod[SmcLexer.CLASS_NAME] = fsmClass.getDeclaredMethod("CLASS_NAME", paramTypes); transName = "HEADER_FILE"; _TransMethod[SmcLexer.HEADER_FILE] = fsmClass.getDeclaredMethod("HEADER_FILE", paramTypes); transName = "INCLUDE_FILE"; _TransMethod[SmcLexer.INCLUDE_FILE] = fsmClass.getDeclaredMethod("INCLUDE_FILE", paramTypes); transName = "PACKAGE_NAME"; _TransMethod[SmcLexer.PACKAGE_NAME] = fsmClass.getDeclaredMethod("PACKAGE_NAME", paramTypes); transName = "IMPORT"; _TransMethod[SmcLexer.IMPORT] = fsmClass.getDeclaredMethod("IMPORT", paramTypes); transName = "DECLARE"; _TransMethod[SmcLexer.DECLARE] = fsmClass.getDeclaredMethod("DECLARE", paramTypes); transName = "LEFT_BRACE"; _TransMethod[SmcLexer.LEFT_BRACE] = fsmClass.getDeclaredMethod("LEFT_BRACE", paramTypes); transName = "RIGHT_BRACE"; _TransMethod[SmcLexer.RIGHT_BRACE] = fsmClass.getDeclaredMethod("RIGHT_BRACE", paramTypes); transName = "LEFT_BRACKET"; _TransMethod[SmcLexer.LEFT_BRACKET] = fsmClass.getDeclaredMethod("LEFT_BRACKET", paramTypes); transName = "LEFT_PAREN"; _TransMethod[SmcLexer.LEFT_PAREN] = fsmClass.getDeclaredMethod("LEFT_PAREN", paramTypes); transName = "RIGHT_PAREN"; _TransMethod[SmcLexer.RIGHT_PAREN] = fsmClass.getDeclaredMethod("RIGHT_PAREN", paramTypes); transName = "COMMA"; _TransMethod[SmcLexer.COMMA] = fsmClass.getDeclaredMethod("COMMA", paramTypes); transName = "COLON"; _TransMethod[SmcLexer.COLON] = fsmClass.getDeclaredMethod("COLON", paramTypes); transName = "SEMICOLON"; _TransMethod[SmcLexer.SEMICOLON] = fsmClass.getDeclaredMethod("SEMICOLON", paramTypes); transName = "SOURCE"; _TransMethod[SmcLexer.SOURCE] = fsmClass.getDeclaredMethod("SOURCE", paramTypes); transName = "EOD"; _TransMethod[SmcLexer.EOD] = fsmClass.getDeclaredMethod("EOD", paramTypes); transName = "SLASH"; _TransMethod[SmcLexer.SLASH] = fsmClass.getDeclaredMethod("SLASH", paramTypes); transName = "EQUAL"; _TransMethod[SmcLexer.EQUAL] = fsmClass.getDeclaredMethod("EQUAL", paramTypes); transName = "ACCESS"; _TransMethod[SmcLexer.ACCESS] = fsmClass.getDeclaredMethod("ACCESS", paramTypes); transName = "DOLLAR"; _TransMethod[SmcLexer.DOLLAR] = fsmClass.getDeclaredMethod("DOLLAR", paramTypes); } catch (NoSuchMethodException ex1) { System.err.println("INITIALIZATION ERROR! No such " + "method as SmcParserContext." + transName + "."); System.exit(2); } catch (SecurityException ex2) { System.err.println("INITIALIZATION ERROR! Not " + "allowed to access " + "SmcParserContext." + transName + "."); System.exit(2); } }}//// CHANGE LOG// $Log: SmcParser.java,v $// Revision 1.16 2007/11/19 18:53:21 fperrad// + add : jump syntax// jump uses the same syntax as push,// allows transition between states of different maps but without stacking a return context.//// Revision 1.15 2007/02/21 13:56:09 cwrapp// Moved Java code to release 1.5.0//// Revision 1.14 2007/01/15 00:23:51 cwrapp// Release 4.4.0 initial commit.//// Revision 1.13 2006/09/16 15:04:29 cwrapp// Initial v. 4.3.3 check-in.//// Revision 1.12 2005/11/07 19:34:54 cwrapp// Changes in release 4.3.0:// New features://// + Added -reflect option for Java, C#, VB.Net and Tcl code// generation. When used, allows applications to query a state// about its supported transitions. Returns a list of transition// names. This feature is useful to GUI developers who want to// enable/disable features based on the current state. See// Programmer's Manual section 11: On Reflection for more// information.//// + Updated LICENSE.txt with a missing final paragraph which allows// MPL 1.1 covered code to work with the GNU GPL.//// + Added a Maven plug-in and an ant task to a new tools directory.// Added Eiten Suez's SMC tutorial (in PDF) to a new docs// directory.//// Fixed the following bugs://// + (GraphViz) DOT file generation did not properly escape// double quotes appearing in transition guards. This has been// corrected.//// + A note: the SMC FAQ incorrectly stated that C/C++ generated// code is thread safe. This is wrong. C/C++ generated is// certainly *not* thread safe. Multi-threaded C/C++ applications// are required to synchronize access to the FSM to allow for// correct performance.//// + (Java) The generated getState() method is now public.//// Revision 1.11 2005/09/14 01:51:33 cwrapp// Changes in release 4.2.0:// New features://// None.//// Fixed the following bugs://// + (Java) -java broken due to an untested minor change.//// Revision 1.10 2005/08/26 15:21:34 cwrapp// Final commit for release 4.2.0. See README.txt for more information.//// Revision 1.9 2005/07/07 12:11:04 fperrad// Add a new token '$' for Perl language.//// Revision 1.8 2005/06/30 10:44:23 cwrapp// Added %access keyword which allows developers to set the generate Context// class' accessibility level in Java and C#.//// Revision 1.7 2005/06/18 18:28:42 cwrapp// SMC v. 4.0.1//// New Features://// (No new features.)//// Bug Fixes://// + (C++) When the .sm is in a subdirectory the forward- or// backslashes in the file name are kept in the "#ifndef" in the// generated header file. This is syntactically wrong. SMC now// replaces the slashes with underscores.//// + (Java) If %package is specified in the .sm file, then the// generated *Context.java class will have package-level access.//// + The Programmer's Manual had incorrect HTML which prevented the// pages from rendering correctly on Internet Explorer.//// + Rewrote the Programmer's Manual section 1 to make it more// useful.//// Revision 1.6 2005/05/28 19:28:42 cwrapp// Moved to visitor pattern.//// Revision 1.5 2005/02/21 15:37:43 charlesr// Added Francois Perrad to Contributors section for Python work.//// Revision 1.4 2005/02/21 15:19:30 charlesr// Trimming import, header and include names because they are lexed// as pure source.//// Revision 1.3 2005/02/03 17:04:39 charlesr// The parser was modified as part of an ongoing project to// make the SMC parser a self-contained, stand-alone library.// These changes include:// + Have SmcParser instantiate the SmcLexer thereby making// the lexer entirely encapsulated by the parser.// + Collecting warning and error messages in SmcMessage// objects. The application owning the parser can then call// SmcParser.getMessages() and display the messages in the// appropriate manner.// + If the parser is in debug mode, then all output is now// guaranteed to be written to the same output stream.//// Revision 1.2 2004/09/06 16:41:03 charlesr// Added C# support.//// Revision 1.1 2004/05/31 13:56:05 charlesr// Added support for VB.net code generation.//// Revision 1.0 2003/12/14 21:05:08 charlesr// Initial revision//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -