-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprefixAndPostfixEvaluator.html
226 lines (206 loc) · 11.4 KB
/
prefixAndPostfixEvaluator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="google-adsense-account" content="ca-pub-2217728188815563">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Postfix and Prefix Notation Evaluator</title>
<meta name="keywords" content="Postfix, Prefix, Infix, Notation, Convertor, Evaluator">
<meta name="description"
content="A utilty for the evaluation of a prefix or a postfix notation with detailed steps." />
<script src="ds.js"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2217728188815563"
crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="index.html">Simple Tools</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
tools
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="calculator.html">Calculator</a>
<a class="dropdown-item" href="prefixAndPostfixConvertor.html">Infix->
postfix/Prefix</a>
<a class="dropdown-item" href="prefixAndPostfixEvaluator.html">Postfix/Prefix->
Evaluate</a>
<a class="dropdown-item" href="Clock.html">Beautiful Clock</a>
<a class="dropdown-item" href="RandomFPS.html">FPS Simulator</a>
</div>
<a class="nav-item nav-link" href="#" onclick='alert("Thanks for using this tool.")'>About</a>
<a class="nav-item nav-link" href="https://github.com/raj457036/Simple-Tools"
target="_blank">Github</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron mt-3 text-center">
<h4><span class="badge badge-pill badge-primary"> Updated (12 Feb 2023)</span></h4>
<h1 class="lead" style="font-size:10vmin">Postfix & Prefix Evaluator</h1>
<p class="lead">This is a simple Prefix or Postfix Evaluator.</p>
<hr class="my-4">
<p>Enter the Postfix or Prefix expression below in box and press Evaluate
<br><small>Note: Enter the number and operators seperated with space " "</small>
</p>
<div>
<label for="expression">
<p>Type the Expression below <br><small>prefix : + - 2 7 * 8 / 4 12<br>postfix: 4 55 + 62 23 - *
<br> (seperated with space)</small></p>
<input type="text" class="form-control form-control-lg" name="expression" id="expression">
<br>
<label for="posteval">
<input type="radio" name="fixer" checked id="posteval" value="1"> Postfix Evaluate
</label>
<label for="preeval">
<input type="radio" name="fixer" id="preeval" value="2"> Prefix Evaluate
</label>
<hr>
<a class="btn btn-primary btn-sm" id="convert" role="button"
href="./prefixAndPostfixConvertor.html">< Convert</a> <button
class="btn btn-lg btn-warning" id="evaluate">Evaluate</button>
</label>
</div>
<div id="shortresult">
<p class="lead">Evaluated : <span id="eval" class="font-weight-bold"></span>
<div class="text-center">
<small>By Raj</small>
</div>
</div>
</div>
<div id="fullresult">
<div class="row">
<div class="col-md-8">
<table class="table table-striped table-bordered">
<thead class="thead-inverse text-left">
<tr>
<th>Sr. no.</th>
<th>Expression</th>
<th>Stack</th>
</tr>
</thead>
<tbody id="tabledata" class="text-left">
</tbody>
<br>
<span id="ifpre" class="lead"></span>
</table>
</div>
<div class="col-md-4 text-center">
<h2>
Algorithm used
</h2>
<!--for postfix-->
<div class="text-left">
<p class="lead">Postfix Evaluation</p>
<small>
<ul>
<li>Step 1: Add a ")" at the end of the postfix expression</li>
<li>Step 2: Scan every character of the postfix expression and repeat Step 3 and 4
until
")" is encountered.</li>
<li>Step 3: IF an operand is encountered, Push it on the stack<br />
IF an operator O is encountered, then
<ul>
<li>a: Pop the top two elements from the stack as A and B</li>
<li>b: Evaluate B O A, where A is the topmost element and B is the element
below
A.</li>
<li>c: Push the result of evaluation on the stack<br />[END OF IF]</li>
</ul>
</li>
<li>Step 4: Set result = stack's top elements</li>
<li>Step 5: Exit</li>
</ul>
</small>
<hr>
<p class="lead">Prefix Evaluation</p>
<small>
<ul>
<li>Step 1: Get Prefix expression as it is</li>
<li>Step 2: Repeat untill all the characters in prefix<br /> expression have been
scanned</li>
<ul>
<li>a: Read the prefix expression from right to left one at a time</li>
<li>b: If the readed character is an operand, push it on the stack</li>
<li>c: If the readed character is an operator, then
<ul>
<li>i: pop two values from the stack.</li>
<li>ii: Apply the operation on the operands.</li>
<li>iii: Push the result onto the stack.</li>
</ul>
</li>
</ul>
</li>
<li>Step 3: Exit</li>
</ul>
</small>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"
integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"
integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
crossorigin="anonymous"></script>
<script>
function sel(x) { return document.getElementById(x) }
$("#fullresult").hide();
//evaluate button and expression
$("button#evaluate").click(function () {
var items, tab = "";
$("#fullresult").show();
let table;
const input = document.getElementById("expression").value.trim();
switch ($('input[name=fixer]:checked').val()) {
case '1':
if (checker(input) == 0) {
table = postfixEval(input);
}
else {
alert("Humm! looks like this is a prefix expression please select prefix evaluate.");
}
break;
case '2':
if (checker(input) == 1) {
table = prefixEval(input);
}
else {
alert("Humm! looks like this is a postfix expression please select postfix evaluate.");
}
break;
}
$("span#eval").html(table.s[table.s.length - 1]);
for (var i = 0; i < table.char.length; i++) {
tab += "<tr><td>" + i + "</td><td>" + table.char[i] + "</td><td>" + table.s[i] + "</td></tr>";
}
sel("tabledata").innerHTML = tab;
})
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-KSX9W2JJ5N"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-KSX9W2JJ5N');
gtag('page', "evaluator");
</script>
</body>
</html>