加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
word_parser_sm.php 17.83 KB
一键复制 编辑 原始数据 按行查看 历史
dorobu 提交于 2013-10-16 17:11 . add enum-syntax-parser
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
<?php
/*
ex: set ro:
DO NOT EDIT.
generated by smc (http://smc.sourceforge.net/)
from file : word_parser.sm
*/
require_once 'StateMachine/statemap.php';
class word_parState extends State {
public function Entry($fsm) {
}
public function Exit_($fsm) {
}
public function getchar($fsm, $c) {
$this->Default_($fsm);
}
public function Default_($fsm) {
$state = $fsm->getState()->getName();
$transition = $fsm->getTransition();
$msg = "\n\tState: $state\n\tTransition: $transition";
throw new TransitionUndefinedException($msg);
}
}
class Main_Default extends word_parState {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->printError($c);
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
}
}
class Main_IDLE extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if ($ctxt->isChracter($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doBeginItem($c, "char");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Character);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isNum($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doBeginItem($c, "num");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Number);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex('/') == bin2hex($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doBeginItem($c, "pre_div");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_div);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isBorder($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doBeginItem($c, "border");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Border);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
} else {
parent::getchar($fsm, $c);
}
}
}
class Main_Character extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if ($ctxt->isChracter($c) || $ctxt->isNum($c)) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isBorder($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "border");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Border);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex('/') == bin2hex($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_div);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isOperator($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "opt");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_Comm);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
} else {
parent::getchar($fsm, $c);
}
}
}
class Main_Number extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if ($ctxt->isNum($c) || bin2hex($c) == bin2hex('.')) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isBorder($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "border");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Border);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex('/') == bin2hex($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_div);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isOperator($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "opt");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_Comm);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
} else {
parent::getchar($fsm, $c);
}
}
}
class Main_Border extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if ($ctxt->isChracter($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "char");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Character);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isNum($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "num");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Number);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex('/') == bin2hex($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_div);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isOperator($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "opt");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_Comm);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ((bin2hex($c) == bin2hex("\n")) || (bin2hex($c) == bin2hex("\r")) || (bin2hex($c) == bin2hex(" "))) {
# No actions.
}
elseif ($ctxt->isBorder($c)) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "border");
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
} else {
parent::getchar($fsm, $c);
}
}
}
class Main_Operator_Comm extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if ($ctxt->isChracter($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "char");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Character);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex($c) == bin2hex('/')) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Operator_div);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isNum($c)) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "num");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Number);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif ($ctxt->isBorder($c)) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem($c, "border");
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
} else {
parent::getchar($fsm, $c);
}
}
}
class Main_Operator_div extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if (bin2hex($c) == bin2hex('*')) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
$ctxt->set_type("block_note");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Block_Note);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
elseif (bin2hex($c) == bin2hex('/')) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
$ctxt->set_type("row_note");
}
catch (Exception $exception) {}
$fsm->setState(Main::$Row_Note);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
else {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
}
catch (Exception $exception) {}
$fsm->setState(Main::$IDLE);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
}
}
class Main_Block_Note extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if (bin2hex($c) != bin2hex('*')) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
}
else {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState(Main::$Block_Note_Meet_Mult);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
}
}
class Main_Block_Note_Meet_Mult extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if (bin2hex($c) == bin2hex('/')) {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
$ctxt->doSave();
$ctxt->doBeginItem("", "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$IDLE);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
else {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState(Main::$Block_Note);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
}
}
class Main_Row_Note extends Main_Default {
public function getchar($fsm, $c) {
$ctxt = $fsm->getOwner();
if (bin2hex($c) != bin2hex("\n")) {
$endState = $fsm->getState();
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doAppend($c);
}
catch (Exception $exception) {}
$fsm->setState($endState);
if ($exception != NULL) {
throw $exception;
}
}
else {
$fsm->getState()->Exit_($fsm);
$fsm->clearState();
$exception = NULL;
try {
$ctxt->doSave();
$ctxt->doBeginItem("", "unknown");
}
catch (Exception $exception) {}
$fsm->setState(Main::$IDLE);
$fsm->getState()->Entry($fsm);
if ($exception != NULL) {
throw $exception;
}
}
}
}
class Main {
public static $IDLE;
public static $Character;
public static $Number;
public static $Border;
public static $Operator_Comm;
public static $Operator_div;
public static $Block_Note;
public static $Block_Note_Meet_Mult;
public static $Row_Note;
public static $Default_;
}
Main::$IDLE = new Main_IDLE('Main.IDLE', 4);
Main::$Character = new Main_Character('Main.Character', 5);
Main::$Number = new Main_Number('Main.Number', 6);
Main::$Border = new Main_Border('Main.Border', 7);
Main::$Operator_Comm = new Main_Operator_Comm('Main.Operator_Comm', 8);
Main::$Operator_div = new Main_Operator_div('Main.Operator_div', 9);
Main::$Block_Note = new Main_Block_Note('Main.Block_Note', 10);
Main::$Block_Note_Meet_Mult = new Main_Block_Note_Meet_Mult('Main.Block_Note_Meet_Mult', 11);
Main::$Row_Note = new Main_Row_Note('Main.Row_Note', 12);
Main::$Default_ = new Main_Default('Main.Default_', -1);
class word_par_sm extends FSMContext {
public function __construct($owner) {
parent::__construct(Main::$IDLE);
$this->_owner = $owner;
}
public function getchar($c) {
$this->_transition = "getchar";
$this->getState()->getchar($this, $c);
$this->_transition = NULL;
}
public function getState() {
if ($this->_state == NULL) {
throw new StateUndefinedException();
}
return $this->_state;
}
public function enterStartState() {
$this->_state->Entry($this);
}
public function getOwner() {
return $this->_owner;
}
}
/*
Local variables:
buffer-read-only: t
End:
*/
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化