
<p><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Compiler (Pushdown Machine)</title> <style type="text/css"> <!-- .style1 { font-size: xx-large; font-weight: bold; } body { margin-top: 0px; margin-bottom: 0px; } --> </style> <script language="javascript"> var m="8",n="7",endmarker="|",start="@"; var input_number="",stack="",answer=""; var input function checktext(text) { if(text != "") { if((text >= 0) && (text <= 9)) { return true; } else { return false; } } else { return false; } } function Swap_Input() { if(checktext(txtN.value) && checktext(txtM.value)) { for(i=0;i<txtM.value;i++) { input_number += m; } for(i=0;i<txtN.value;i++) { input_number += n; } input_number += "|"; input.push(start); stack = start; var num = input_number.length; txtOutput.value = "Pushdown Machine \n"; txtOutput.value += "Stack: " + stack + " Input Sequence: " + input_number + "\n"; check_pushdown(input_number.substr(0,1),1); } else { window.alert("Input is between number(0-99)"); txtN.value = ""; txtm.value = ""; } } function check_pushdown(inputString, state) { var tmp; tmp = input.pop(); input.push(tmp); if (state != -1) { switch(inputString) { case m: //4 switch(state) { case 1: if((tmp == start) || (tmp == m)) // @ or 4 { input.push(m);stack += m; answer += n; input_number = input_number.substr(1, input_number.length); txtOutput.value += "Stack: " + stack + " Input Sequence: " + input_number + " answer: " + answer + "\n"; check_pushdown(input_number.substr(0,1), 1); } break case 2: if((tmp == start) || (tmp == m)) // @ or 4 { txtOutput.value += "Reject!!!! Because state2 have not value 7"; tmp_state = -1; } break default: window.alert("Error"); break } break case "7": //1 switch(state) { case 1: if(tmp == m) //4 { answer += n; input_number = input_number.substr(1, input_number.length); txtOutput.value += "Stack: " + stack + " Input Sequence: " + input_number + " answer: " + answer + "\n"; check_pushdown(input_number.substr(0,1), 2); } else if(tmp = start) //@ { txtOutput.value += "Reject!!!! Because have not value 1"; tmp_state = -1; } break case 2: if(tmp == m) //4 { answer += n; input_number = input_number.substr(1, input_number.length); txtOutput.value += "Stack: " + stack + " Input Sequence: " + input_number + " answer: " + answer + "\n"; check_pushdown(input_number.substr(0,1), 2); } else if(tmp = start) //@ { txtOutput.value += "Reject!!!! Because exceed value 1"; tmp_state = -1; } break default: window.alert("Error"); break } break case "|": switch(state) { case 1: if((tmp == start) || (tmp == m)) // @ or 4 { txtOutput.value += "Reject!!!! Because not reverse"; tmp_state = -1; } break case 2: if(tmp == m) //4 { answer += m; answer += input.pop(); stack = stack.substr(0,stack.length-1); txtOutput.value += "Stack: " + stack + " Input Sequence: " + input_number + " answer: " + answer + "\n"; check_pushdown(input_number.substr(0,1), 2); } else if(tmp = start) //@ { txtOutput.value += "Accept!!!!!!"; tmp_state = -1; } break default: window.alert("Error"); break } break default: window.alert("Unknow"); break } } } function Pushdown_machine() { txtOutput.value = ""; input_number=""; stack=""; answer=""; input = new Array(); Swap_Input(); } </script> </head> <body> <table width="742" border="0" align="center" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="14" rowspan="25" valign="top" background="Image/bg_left.gif"><!--DWLayoutEmptyCell--> </td> <td height="91" colspan="7" valign="top"><div align="center" class="style1"> <p>Pushdown Machine</p> <p> </p> </div></td> <td width="14" rowspan="25" valign="top" background="Image/bg_right.gif"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="23" colspan="7" valign="top"><div align="center"> <p>Input Sample Sequence: {code is 8^m and 7^n}</p> </div></td> </tr> <tr> <td height="23" colspan="7" valign="top"><div align="center">Translate : {code is 8^m+n, 7^2m} </div></td> </tr> <tr> <td height="24" colspan="7" valign="top"><div align="center">Please input number to text box <strong>N</strong> and <strong>M</strong> </div></td> </tr> <tr> <td colspan="3" rowspan="2" valign="top"><div align="right"> <p><strong>Input Number:</strong></p> </div></td> <td width="158" height="1"></td> <td width="154"></td> <td colspan="2" rowspan="3" valign="top"> <label> <input name="btnCheck" type="submit" id="btnCheck" onClick="Pushdown_machine()" value="Submit" /> </label> </td> </tr> <tr> <td height="22" valign="top"> <div align="center"> <p><strong>M: </strong> <input name="txtM" type="text" id="txtM" title="N:" value="2" size="10" maxlength="1" /> </p> </div></td> <td valign="top"><div align="center"><strong>N: </strong> <strong> <input name="txtN" type="text" id="txtN" title="N:" value="3" size="10" maxlength="1" /> </strong></div></td> </tr></p><p><tr> <td width="116" height="1"></td> <td width="10"></td> <td width="117"></td> <td></td> <td></td> </tr> <tr> <td height="14"></td> <td></td> <td></td> <td></td> <td></td> <td width="58"></td> <td width="101"></td> </tr> <tr> <td height="26" colspan="3" valign="top"><div align="right"><strong>Result:</strong></div></td> <td colspan="4" rowspan="2" valign="top"> <div align="center"><textarea name="txtOutput" cols="65" rows="10" readonly="readonly" id="txtOutput"></textarea> </label> </div></td> </tr> <tr> <td height="137"> </td> <td></td> <td></td> </tr></p><p><tr> <td height="57" colspan="7" valign="top"><div align="center"> <p><br> <strong>Note</strong> M is "8" and N is "7", My program you can input number to text box between(0-9).</p> </div></td> </tr> <tr> <td height="20"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr></p><p><tr> <td height="19" colspan="7" valign="top" bgcolor="#CCCCCC"><strong>Document:</strong></td> </tr> <tr> <td height="19" colspan="7" valign="top"><strong> Using Finite State Machine </strong></td> </tr> <tr> <td height="19" colspan="7" valign="top"> 1. Input number and click submit button.</td> </tr> <tr> <td height="19" colspan="7" valign="top">2. Result box show answer.</td> </tr> <tr> <td height="19" colspan="7" valign="top"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="19" valign="top"><div align="right"><strong>Design:</strong></div></td> <td colspan="5" valign="top"> Transition with pushdown machines</td> <td valign="top"><div align="center"><a href="Design.doc">click here </a></div></td> </tr> <tr> <td height="19" valign="top"><div align="right"><strong>Source Code: </strong></div></td> <td colspan="5" valign="top"> Implement by JavaScript</td> <td valign="top"><div align="center"><a href="Code.doc">click here</a> </div></td> </tr> <tr> <td height="19"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="19" colspan="7" valign="top" bgcolor="#CCCCCC"><strong>About:</strong></td> </tr></p><p><tr> <td height="19" colspan="2" valign="top"><div align="right"><strong>Develop by: </strong></div></td> <td colspan="5" valign="top"> Peerapong Kiatcheeranun</td> </tr> <tr> <td height="19" colspan="2" valign="top"><div align="right"><strong>Student No: </strong></div></td> <td colspan="5" valign="top"> 4605487</td> </tr> <tr> <td height="19" colspan="2" valign="top"><div align="right"><strong> Course Study:</strong></div></td> <td colspan="5" valign="top"> Compiler Construction </td> </tr> <tr> <td height="19" colspan="2" valign="top"><div align="right"><strong>Course No: </strong></div></td> <td colspan="5" valign="top"> 204442</td> </tr> </table> </body> </html></p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages12 Page
-
File Size-