Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3424
  • 博文数量: 2
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-03 18:06
文章分类
文章存档

2014年(2)

我的朋友

分类: PHP

2014-12-15 08:16:06


点击(此处)折叠或打开

  1. <meta charset="utf-8">
  2. <form action='' method='post'>







  3. <textarea name="content" style="width:100%; height:30%">
  4. 显示 Helloworld->结束:
  5. </textarea>
  6. <input type="submit" value="提交" />
  7. </from>
  8. <?php
  9. if( !isset($_POST['content']) ) exit;
  10. $content = $_POST['content'];
  11. if( !isset($content) ) exit;
  12. //状态表
  13. $状态表 = array();
  14. $状态关系表 = array();

  15.  $arrContent = explode("\r\n", $content);
  16.  $arrTemplate=array();
  17.  
  18.   $code="";
  19.  for($i=0;$i<sizeof( $arrContent );$i++ )
  20.  {
  21.         $strLine = trim($arrContent[$i]);
  22.         if( !$strLine ) continue;
  23.         
  24.         $n1 = strpos($strLine,"->");
  25.         $n2 = strpos($strLine,":");
  26.         
  27.         $strState1 = trim(substr($strLine,0,$n1));
  28.         $strState2 = trim(substr($strLine,$n1+2,$n2-$n1-2));
  29.         
  30.         $strEvent = trim(substr($strLine,$n2+1));
  31.         


  32.         if( $strState1!="" )
  33.         {
  34.                 $pos1=搜索数组($strState1,$状态表);
  35.                 if( $pos1<0 )
  36.                 {
  37.                         $pos1=array_push($状态表,$strState1)-1;
  38.                 }
  39.                 
  40.         }
  41.         if( $strState2!="" )
  42.         {
  43.                 $pos2=搜索数组($strState2,$状态表);
  44.                 if( $pos2<0 )
  45.                         $pos2=array_push($状态表,$strState2)-1;
  46.         }

  47.         
  48.         $arr = array();
  49.         array_push($arr,$pos1);
  50.         array_push($arr,$pos2);
  51.         array_push($arr,$strEvent);
  52.         $状态关系表=添加到状态关系表($状态关系表,$arr);

  53.         
  54.         
  55. }


  56. $code = 获取代码($状态关系表,$状态表);


  57.  //echo "
    ";
  58.   //var_dump($状态表);
  59.  // var_dump($状态关系表);
  60.  
  61.  //echo "";
  62. ?>

  63. <canvas id="c" width="300" height=""></canvas>
  64. <script>
  65. <?php
  66.  
  67. for($i=0;$i<sizeof($状态表);$i++)
  68. {
  69.         $state1 = $状态表[$状态关系表[$i][0]];
  70.         $state2 = $状态表[$状态关系表[$i][1]];
  71.         ?>
  72.         
  73.         var c=document.getElementById("c");
  74.         var ctx=c.getContext("2d");
  75.         ctx.rect(20,20+120*<?php echo $i?>,150,100);
  76.         ctx.stroke();
  77.         
  78.         <?php
  79.          
  80. }
  81. ?>
  82. </script>


  83. <textarea id="code" style="width:100%; height:30%">
  84. <?php echo $code?>
  85. </textarea>
  86. <?php
  87. function 搜索数组($str,$arr)
  88. {

  89.         for($i=0;$i<sizeof($arr);$i++)
  90.         {
  91.                 if( $arr[$i]==$str )
  92.                 {
  93.                         return $i;
  94.                 }
  95.         }
  96.         
  97.         return -1;
  98. }
  99. function 搜索状态关系表($str,$arr)
  100. {

  101.         for($i=0;$i<sizeof($arr);$i++)
  102.         {
  103.                 if( $arr[$i][0]==$str )
  104.                 {
  105.                         return $i;
  106.                 }
  107.         }
  108.         
  109.         return -1;
  110. }
  111. function 添加到状态关系表($arr,$arrEvent)
  112. {
  113.         $arrState = array();

  114.         $pos= 搜索状态关系表($arrEvent[0],$arr);
  115.         $newArrEvent = array();
  116.                 array_push($newArrEvent,$arrEvent[1]);
  117.                 if( $arrEvent[2] )
  118.                         array_push($newArrEvent,$arrEvent[2]);
  119.         if( $pos >= 0 )
  120.         {
  121.                 //累加
  122.                 array_push($arr[$pos][1],$newArrEvent);
  123.         }
  124.         else
  125.         {
  126.                 $arrEventParent = array();
  127.                 array_push($arrEventParent,$newArrEvent);
  128.         
  129.                 array_push($arrState,$arrEvent[0]);
  130.                 array_push($arrState,$arrEventParent);
  131.                 //新增
  132.                 array_push($arr,$arrState);
  133.         }
  134.         
  135.          
  136.          return $arr;
  137. }
  138. function 获取代码($状态关系表,$状态表)
  139. {
  140.         $str="";
  141.  
  142.         for($i=0;$i<sizeof($状态关系表);$i++)
  143.         {
  144.                 if(sizeof($状态关系表[$i][1])>0&&sizeof($状态关系表[$i][1][0])<2)
  145.                         $template=file_get_contents("0.txt");
  146.                 else
  147.                         $template=file_get_contents(sizeof($状态关系表[$i][1]).".txt");
  148.                 $template=str_replace("{state}",$状态表[$状态关系表[$i][0]],$template);
  149.                 
  150.                 for( $j=0;$j<sizeof($状态关系表[$i][1]);$j++ )
  151.                 {
  152.                         $template=str_replace("{state".$j."}",$状态表[ $状态关系表[$i][1][$j][0] ],$template);
  153.                         if( sizeof($状态关系表[$i][1][$j])>1)
  154.                                 $template=str_replace("{case".$j."}", $状态关系表[$i][1][$j][1] ,$template);
  155.                 }
  156.         
  157.         }
  158.         $str=$template;
  159.         return $str;
  160. }
  161. ?>


  162. {state}();
  163.  0.txt


  164. {state}();
  165. if( {case0}
  166.         {state0}();
  167.  1.txt


  168. switch( {state}() )
  169. {
  170.     case {case0}:
  171.     {state0}();
  172.     break;
  173.     case {case1}:
  174.     {state1}();
  175.     break;
  176. }
  177. 2.txt

阅读(284) | 评论(0) | 转发(0) |
0

上一篇:100个uml工具软件

下一篇:没有了

给主人留下些什么吧!~~