📄 smcparser.java
字号:
else { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); os.println("CREATE STATE : " + name + "(" + Integer.toString(lineNumber) + ")"); } _stateInProgress = new SmcState(name, lineNumber, _mapInProgress); } return; } /* package */ void setEntryAction(List<SmcAction> actions) { // Verify there is an in-progress state. if (_stateInProgress == null) { error("There is no in-progress state to receive " + "the entry action.", _lineNumber); } else if (_stateInProgress.getEntryActions() != null) { warning("Entry action previously specified, new " + "entry action ignored.", _lineNumber); } else { _stateInProgress.setEntryActions(actions); } return; } /* package */ void setExitAction(List<SmcAction> actions) { // Verify there is an in-progress state. if (_stateInProgress == null) { error("There is no in-progress state to receive " + "the exit action.", _lineNumber); } else if (_stateInProgress.getExitActions() != null) { warning("Exit action previously specified, new " + "exit action ignored.", _lineNumber); } else { _stateInProgress.setExitActions(actions); } return; } // Append the in-progress transition to the in-progress // state's transition list. /* package */ void addTransition() { if (_stateInProgress == null) { error("There is no in-progress state to which the " + "transition may be added.", _lineNumber); } else if (_transitionInProgress == null) { error("There is no in-progress transition to add " + "to the state.", _lineNumber); } else { _stateInProgress.addTransition( _transitionInProgress); _transitionInProgress = null; } return; } // Returns the stored transition name. /* package */ String getTransitionName() { return (_transitionInProgress != null ? _transitionInProgress.getName() : _transitionName); } // Store away the transition's name for later use in // creating the transition. /* package */ void storeTransitionName(String name) { if (_transitionName != null) { error("There already is a previously stored " + "transition name - \"" + name + "\".", _lineNumber); } else { _transitionName = name; } return; } // Create a transition object with the current token as its // name. /* package */ void createTransition(List<SmcParameter> params, int lineNumber) { if (_transitionInProgress != null) { error("Cannot create new transition while still " + "filling in previous transition (" + _transitionInProgress.getName() + ").", lineNumber); } else if (_stateInProgress == null) { error("There is no in-progress state to which the " + "transition may be added.", lineNumber); } else if (_transitionName == null) { error("There is no stored transition name.", lineNumber); } else { String name; SmcTransition transition; // Check if this state already has a transition with // this name. If so, then reuse that object. // Otherwise, create a new transition object. _transitionInProgress = _stateInProgress.findTransition( _transitionName, params); if (_transitionInProgress == null) { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); Iterator<SmcParameter> pit; String sep; StringBuffer buffer = new StringBuffer(80); buffer.append("CREATE TRANS : "); buffer.append(_transitionName); buffer.append('('); for (pit = params.iterator(), sep = ""; pit.hasNext() == true; sep = ", ") { buffer.append(sep); buffer.append(pit.next()); } buffer.append(')'); buffer.append(" ("); buffer.append(lineNumber); buffer.append(")"); os.println(buffer); } _transitionInProgress = new SmcTransition( _transitionName, params, lineNumber, _stateInProgress); } _transitionName = null; } return; } // Create a transition object with the current token as its // name. /* package */ void createTransition(int lineNumber) { createTransition(new ArrayList<SmcParameter>(), lineNumber); return; } /* package */ void addGuard() { if (_transitionInProgress == null) { error("There is no in-progress transition to " + "which the guard may be added.", _lineNumber); } else if (_guardInProgress == null) { error("There is no in-progress guard to add " + "to the " + _transitionInProgress.getName() + " transition.", _lineNumber); } else { _transitionInProgress.addGuard(_guardInProgress); _guardInProgress = null; } return; } // Create a guard object with the in-progress action as its // condition. /* package */ void createGuard(String transition, String condition, int lineNumber) { if (_guardInProgress != null) { error("Cannot create new guard while still " + "filling in previous guard.", lineNumber); } else { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); os.println("CREATE GUARD : " + condition + "(" + Integer.toString(lineNumber) + ")"); } _guardInProgress = new SmcGuard(condition, lineNumber, _transitionInProgress); } return; } // Set the in-progress guard's transtion type (set, push or // pop). /* package */ void setTransType(int trans_type) { if (_guardInProgress == null) { error("There is no in-progress guard to which to " + "set the transition type.", _lineNumber); } else { switch (trans_type) { case Smc.TRANS_SET: case Smc.TRANS_PUSH: case Smc.TRANS_POP: _guardInProgress.setTransType(trans_type); break; default: error("Transition type must be either " + "\"TRANS_SET\", \"TRANS_PUSH\" or " + "\"TRANS_POP\".", _lineNumber); break; } } return; } // Set the in-progress guard's end state. /* package */ void setEndState(String state) { if (_guardInProgress == null) { error("There is no in-progress guard to which to " + "add the end state.", _lineNumber); } else { _guardInProgress.setEndState(state); } return; } // Set the in-progress guard's push state. /* package */ void setPushState(String name) { if (_guardInProgress == null) { error("There is no in-progress guard to which to " + "add the end state.", _lineNumber); } else if (_guardInProgress.getTransType() != Smc.TRANS_PUSH) { error("Cannot set push state on a non-push " + "transition.", _lineNumber); } else if (name.equals("nil") == true) { error("Cannot push to \"nil\" state.", _lineNumber); } else { _guardInProgress.setPushState(name); } return; } // Set the guard's actions. /* package */ void setActions(List<SmcAction> actions) { if (_guardInProgress == null) { error("There is no in-progress guard to which to " + "add the action.", _lineNumber); } else { _guardInProgress.setActions(actions); } return; } /* package */ void setPopArgs(String args) { if (_guardInProgress == null) { error("There is no in-progress guard to which to " + "add the action.", _lineNumber); } else { _guardInProgress.setPopArgs(args); } return; } /* package */ void createParamList() { if (_paramList == null) { _paramList = new ArrayList<SmcParameter>(); } return; } /* package */ List<SmcParameter> getParamList() { List<SmcParameter> retval = _paramList; _paramList = null; return (retval); } /* package */ void createParameter(String name, int lineNumber) { if (_paramInProgress != null) { error("Cannot create new parameter while still " + "filling in previous one.", lineNumber); } else { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); os.println("CREATE PARAM : " + name + "(" + Integer.toString(lineNumber) + ")"); } _paramInProgress = new SmcParameter(name, lineNumber); } return; } /* package */ void setParamType(String type) { if (_paramInProgress == null) { error("There is no in-progress parameter to which " + "to add the type.", _lineNumber); } else { _paramInProgress.setType(type); } return; } /* package */ void addParameter() { if (_paramList == null) { error("There is no parameter list to which the " + "parameter may be added.", _lineNumber); } else if (_paramInProgress == null) { error("There is no in-progress parameter to add " + "to the list.", _lineNumber); } else { _paramList.add(_paramInProgress); _paramInProgress = null; } return; } /* package */ void clearParameter() { _paramInProgress = null; return; } /* package */ void createActionList() { if (_actionList != null) { error("Cannot create an action list when one " + "already exists.", _lineNumber); } else { _actionList = new ArrayList<SmcAction>(); } return; } /* package */ List<SmcAction> getActionList() { List<SmcAction> retval = _actionList; _actionList = null; return(retval); } /* package */ void createAction(String name, int lineNumber) { if (_actionInProgress != null) { error("Cannot create new action while still " + "filling in previous one.", lineNumber); } else { if (_parserFSM.getDebugFlag() == true) { PrintStream os = _parserFSM.getDebugStream(); os.println("CREATE ACTION: " + name + "(" + Integer.toString(lineNumber) +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -