PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Arturo Gonzalez-Mata Santana   Simple RPN Interpreter   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of use of rpn.class.php with forms
Class: Simple RPN Interpreter
Evaluate reverse polish notation expressions
Author: By
Last change: //added some coments
Date: 16 years ago
Size: 3,925 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RPN interpreter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
.style3 {
    color: #CCCCCC;
    font-size: large;
    font-weight: bold;
    font-family: "Courier New", Courier, mono;
}
.style4 {color: #990000}
.style5 {font-family: "Courier New", Courier, mono}
.style7 {font-family: "Courier New", Courier, mono; font-weight: bold; }
.style8 {color: #FFFFFF}
.style9 {font-size: small}
.style10 { font-size: medium;
    font-weight: bold;
}
-->
</style>
</head>
<body>
<span class="style5 style1"><a href="index.html"><tt>PhpSqlAsp.com</tt></a> <tt><a href="rpn.html">RPN Interpreter (NEW)</a></tt> </span>
<h1 align="center">EXAMPLE OF<br />
   <span class="style4">RPN INTERPRETER IN PHP</span> </h1>
 <h3>(C) Arturo Gonzalez-Mata Santana </h3>
 <p>This example read and execute a RPN commands in the form. </p>
<?php


require_once("rpn.class.php");
$s=&new RPNstack(); // pila como variable global
//echo nl2br($_POST["textarea"]); // only for
$num_lineas=1;
$program = $_POST["textarea"] . " ";
if (
$program == "") : echo "<center><h3>please write or edit a program</h3></center>";
else :
?>
         <table border="1" align="center" cellpadding="2" cellspacing="1">
              <tr bgcolor="#0066FF">
                <td colspan="2"><div align="center" class="style5"><strong>&quot;Program&quot; Line</strong></div></td>
                <td><div align="center" class="style3">Result</div></td>
              </tr>
<?php
        $listado
= explode("\n",$program);
        foreach (
$listado as $buffer) {
           
?><tr>
                <td bgcolor="#FFCC99"><div align="center" class="style5">#<?php echo $num_lineas++;?></div></td>
                <td bgcolor="#FFCC99"><span class="style7"><?php echo $buffer;?></span></td>
                <td bgcolor="#003300"><div align="right" class="style8"><strong><?php echo $s->parse_line($buffer); ?></strong></div></td>
              </tr>
<?php } //foreach
endif; ?>
</table>
 <?php
if ($s->first() != "") printf("<h2>The Result is %s </h2>",$s->first());
?>
<form name="form1" id="form1" method="post" action="">
   <table border="1" align="center" cellpadding="0" cellspacing="2">
     <tr>
       <td width="505">
       <textarea name="textarea" cols="80" rows="24" class="style5"><?php
      
if ($_POST["textarea"] != "") echo $_POST["textarea"]; else echo "2 12 +
8 - 9 *
5 / 78 5 + -
25 10 * 50 +
DUP *
SWAP -
23 50 < IF + * then 40 +"
;?></textarea>
</td>
       <td width="145" valign="top"><h3 align="center">
         <input type="submit" name="Submit" value="Submit" />
         <input name="Clear" type="reset" id="Clear2" value="Reset" />
       </h3>
         <table width="95%" border="1" cellspacing="2" cellpadding="0">
           <tr>
             <th bgcolor="#003300" class="style5" scope="col"><h5 class="style8">RPN<br />
  COMMANDS </h5></th>
           </tr>
           <tr>
             <td class="style5"><span class="style9"><strong>Math Operators:</strong><br />
+ - * / </span></td>
           </tr>
           <tr>
             <td class="style5"><span class="style9"><strong>Comparison Operators:</strong><br />
  = &lt;&gt; &gt; &lt; &gt;= &lt;= </span></td>
           </tr>
           <tr>
             <td class="style5"><p class="style9"><strong>Conditionals:<br />
             </strong>IF .. THEN </p> </td>
           </tr>
           <tr>
             <td class="style5"><p class="style9"><strong>Stack:</strong><br />
               DUP SWAP
             </p> </td>
           </tr>
         </table> <p align="center" class="style5">&nbsp; </p>
       <p class="style5">&nbsp;</p><p>&nbsp;</p></td>
     </tr>
   </table>
</form>
<p>&nbsp;</p>
</body>
</html>