标签:style blog io ar os for on div log
<meta charset="utf-8">
<form action=‘‘ method=‘post‘>
<!--判断i->显示错误:等于0
判断i->显示Helloworld:等于1-->
<!--
Init->显示 Helloworld:1
-->
<!--
判断i->显示错误:等于0
判断i->显示Helloworld:等于1
-->
<!--
判断i->显示错误:等于0
判断i->显示错误:等于-1
-->
<!--
显示 Helloworld->结束:i=1
-->
<!--
显示 Helloworld->结束:
-->
<textarea name="content" style="width:100%; height:30%">
显示 Helloworld->结束:
</textarea>
<input type="submit" value="提交" />
</from>
<?php
if( !isset($_POST[‘content‘]) ) exit;
$content = $_POST[‘content‘];
if( !isset($content) ) exit;
//状态表
$状态表 = array();
$状态关系表 = array();
$arrContent = explode("\r\n", $content);
$arrTemplate=array();
$code="";
for($i=0;$i<sizeof( $arrContent );$i++ )
{
$strLine = trim($arrContent[$i]);
if( !$strLine ) continue;
$n1 = strpos($strLine,"->");
$n2 = strpos($strLine,":");
$strState1 = trim(substr($strLine,0,$n1));
$strState2 = trim(substr($strLine,$n1+2,$n2-$n1-2));
$strEvent = trim(substr($strLine,$n2+1));
if( $strState1!="" )
{
$pos1=搜索数组($strState1,$状态表);
if( $pos1<0 )
{
$pos1=array_push($状态表,$strState1)-1;
}
}
if( $strState2!="" )
{
$pos2=搜索数组($strState2,$状态表);
if( $pos2<0 )
$pos2=array_push($状态表,$strState2)-1;
}
$arr = array();
array_push($arr,$pos1);
array_push($arr,$pos2);
array_push($arr,$strEvent);
$状态关系表=添加到状态关系表($状态关系表,$arr);
}
$code = 获取代码($状态关系表,$状态表);
//echo "<pre>";
//var_dump($状态表);
// var_dump($状态关系表);
//echo "</pre>";
?>
<canvas id="c" width="300" height="<?php echo sizeof($状态表)*140?>"></canvas>
<script>
<?php
for($i=0;$i<sizeof($状态表);$i++)
{
$state1 = $状态表[$状态关系表[$i][0]];
$state2 = $状态表[$状态关系表[$i][1]];
?>
var c=document.getElementById("c");
var ctx=c.getContext("2d");
ctx.rect(20,20+120*<?php echo $i?>,150,100);
ctx.stroke();
<?php
}
?>
</script>
<textarea id="code" style="width:100%; height:30%">
<?php echo $code?>
</textarea>
<?php
function 搜索数组($str,$arr)
{
for($i=0;$i<sizeof($arr);$i++)
{
if( $arr[$i]==$str )
{
return $i;
}
}
return -1;
}
function 搜索状态关系表($str,$arr)
{
for($i=0;$i<sizeof($arr);$i++)
{
if( $arr[$i][0]==$str )
{
return $i;
}
}
return -1;
}
function 添加到状态关系表($arr,$arrEvent)
{
$arrState = array();
$pos= 搜索状态关系表($arrEvent[0],$arr);
$newArrEvent = array();
array_push($newArrEvent,$arrEvent[1]);
if( $arrEvent[2] )
array_push($newArrEvent,$arrEvent[2]);
if( $pos >= 0 )
{
//累加
array_push($arr[$pos][1],$newArrEvent);
}
else
{
$arrEventParent = array();
array_push($arrEventParent,$newArrEvent);
array_push($arrState,$arrEvent[0]);
array_push($arrState,$arrEventParent);
//新增
array_push($arr,$arrState);
}
return $arr;
}
function 获取代码($状态关系表,$状态表)
{
$str="";
for($i=0;$i<sizeof($状态关系表);$i++)
{
if(sizeof($状态关系表[$i][1])>0&&sizeof($状态关系表[$i][1][0])<2)
$template=file_get_contents("0.txt");
else
$template=file_get_contents(sizeof($状态关系表[$i][1]).".txt");
$template=str_replace("{state}",$状态表[$状态关系表[$i][0]],$template);
for( $j=0;$j<sizeof($状态关系表[$i][1]);$j++ )
{
$template=str_replace("{state".$j."}",$状态表[ $状态关系表[$i][1][$j][0] ],$template);
if( sizeof($状态关系表[$i][1][$j])>1)
$template=str_replace("{case".$j."}", $状态关系表[$i][1][$j][1] ,$template);
}
}
$str=$template;
return $str;
}
?>
{state}();
0.txt
{state}();
if( {case0} )
{state0}();
1.txt
switch( {state}() )
{
case {case0}:
{state0}();
break;
case {case1}:
{state1}();
break;
}
2.txt
标签:style blog io ar os for on div log
原文地址:http://www.cnblogs.com/Lancoder/p/4164075.html