PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Benjamin P.   DEA   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Sample script using the class DEA
Class: DEA
An abstract deterministic finite automaton
Author: By
Last change:
Date: 21 years ago
Size: 2,691 bytes
 

Contents

Class file image Download
<?php
   
include_once( './class_dea.inc');
include_once(
'./common.inc');
   
   
//_print out a nice header + title + inner-head-tags like "<link>"
_metaheader( "php-class_DEA", "<link href='automata.css' rel='stylesheet' type='text/css'>" );
   
   
/* ..we have to define..
 *
 * ..the states(Q) of the dea,
 * ..the set of terminal-symbols(S),
 * ..transform-func(delta),
 * ..the starting state(qS),
 * ..the set of final-states(qF)
 */
   
$Q = array( 0, 1, 2, 3 );
$S = array( 'a', 'b' );
$delta = array( 0 => array( 'a' => 3 ,
                               
'b' => 0 ),
                   
3 => array( 'a' => 3 ,
                               
'b' => 0 ));
$qS = array( 0 );
$qF = array( 3 );
   
   
$tmpHTML = "<div align='center'><table>\n\t<tr>";
$tmpHTML .= "<td colspan='2'><h2>DEA-Acceptor</h2><br>";
   
//...either we get a word
if (! isset($word)) { $word = 'abb'; }
   
   
// ..create a new-empty dea-object
   
if ( $dea0 = new DEA( $Q, $S, $delta, $qS, $qF ) ){
   
       
// ..define and stamp our dea
        // ..comment out the next line 4 getting the dea we specified above
       
$dea0->readDeltafromFile( './dea/as-bs_3mod4.spec' );
       
       
$tmpHTML .= "Given word was... [".$word."]<br><br>";
       
       
//..if we accept, then
       
if ( $dea0->accept( $word ) ) {
           
$tmpHTML .= "dea succesfull created!<br>\ndea accepted [".$word."] :)";
        } else {
           
$tmpHTML .= "dea <strong>NOT</strong> accepted [".$word."]<br><br>&nbsp;";
        }
       
    } else {
       
//..otherwise
       
$tmpHTML .= "dea creating failed...";
}
$tmpHTML .= "</td></tr>";
   
$tmpHTML .= "<tr>\n";
$tmpHTML .= "<td>\n";
   
$tmpHTML .= "<br>State----Symbol----State+1<br>";
   
// ..write out our transitions of our dea
$icount = count ($dea0->delta_states );
for (
$i=0; $i<$icount; $i++ ) {
   
    foreach (
array_keys($dea0->delta_states[ $i ]) as $symbol ) {
       
$tmpHTML .= "(". $i.")";
       
$tmpHTML .= "__x__(\"". $symbol."\") ";
       
$tmpHTML .= "::= (".$dea0->delta_states[$i][$symbol].")<br>\n";
    }
}
$tmpHTML .= "<br>\n";
       
$tmpHTML .= "<br><br><form action='".$PHPSELF."' method='post'>";
$tmpHTML .= "<input type='text' name='word' value='ababb'><br>";
$tmpHTML .= "<input type='submit' name='submit' value='send word 2 dea'>";
$tmpHTML .= "</form>";
   
$tmpHTML .= "<br><br>&nbsp;</td></tr>\n";
$tmpHTML .= "<tr><td colspan='2'><br><p>..if U have suggestions or sth. to say...";
$tmpHTML .= "<br>give me a comment!";
$tmpHTML .= "<br>you're welcome!<br>";
$tmpHTML .= "<br>[halyc0ndaze_at_gmx_dot_net]</p><br>&nbsp;";
$tmpHTML .= "</td></tr>";
$tmpHTML .= "</table></div>\n";
echo
$tmpHTML;
   
_footer();
?>