-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomata.html
More file actions
242 lines (217 loc) · 9.12 KB
/
automata.html
File metadata and controls
242 lines (217 loc) · 9.12 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link rel="shortcut icon" type="image/png" href="css/favicon.png"/>
<meta name="theme-color" content="#000000" />
<link rel="stylesheet" href="css/materialize.css">
<link rel="stylesheet" href="css/style.css">
<title>Compiler</title>
</head>
<body onload="brython({debug: 1, indexedDB: false})">
<nav class="blue lighten-1">
<div class="nav-wrapper">
<a href="#" class="brand-logo lg">Welcome to Compiler GUI</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="index.html">Home</a></li>
<li class="active"><a href="automata.html">Automata</a></li>
<li><a href="re2nfa.html">Re2NFA</a></li>
<li><a href="parser.html">LL(1)</a></li>
<li><a href="parser_SLR.html">SLR</a></li>
</ul>
</div>
</nav>
<div class="container wrap-me">
<div id="zone0">
<br/><br/>
<div class="row">
<div class="input-field col s3">
<input id="noOfStates" type="text" placeholder="Enter the no of states">
</div>
<div class="input-field col s3">
<input id="nOofSymbols" type="text" placeholder="Enter the no of input symbols">
</div>
<div class="input-field col s3">
<input id="IpSymbols" type="text" placeholder="Enter input symbols">
</div>
<div class="input-field col s3">
<select id="FaMode" class="blue">
<option value="" disabled selected>Choose Automata</option>
<option value="1">DFA</option>
<option value="2">NFA</option>
</select>
<label>Select Automata</label>
</div>
</div>
<button class="btn waves-effect waves-light blue lighten-1" type="submit" id="getTab" name="action">Get Table</button>
</div>
<br/>
<div class="hide-me" style="display: none;" id="btns">
<div class="row">
<div class="input-field col s4">
<label for="ckeckString">String to Check</label></br>
<input id="ckeckString" type="text" placeholder="Enter the string to check">
</div>
<div class="input-field col s4">
<label for="initial">Initial State</label><br/>
<input id="initial" type="text" placeholder="Enter the Initial state">
</div>
<div class="input-field col s4">
<label for="finals">Final States</label><br/>
<input id="finals" type="text" placeholder="Enter Final States">
</div>
</div>
<button class="btn waves-effect waves-light blue lighten-1" type="submit" id="check" name="action">Check</button>
<div class="leave-me"></div>
</div>
</div>
<div id="ab" class="container">
<h4>Instructions:-</h4>
<hr class="blue lighten-5 line"/>
<p>
<blockquote>
<i><strong>Step1:</strong></i> Fill the number of states, number of input symbol and all the input symbols present in your automata.
</blockquote>
<blockquote>
<i><strong>Step2:</strong></i> Fill The transition table generated, for giving multiple paths, you can use <i>"A, B"</i>.
</blockquote>
<blockquote>
<i><strong>Step3:</strong></i> Fill the string you want to check and provide the initial and final state. You can provide multiple final states seperating them with <i>","</i> or <i>space</space>
</blockquote>
<blockquote>
<i><strong>Result:</strong></i>The result will be shown in the alert box, So that you can give another input for the same table or make correction in table.
</blockquote>
<blockquote class="note">
<i><strong>Note:</strong>Don't leave any field blank. This automata is not designed to take epsilon move. You can refresh the page and go back to original input by clickink that red button in right bottom corner.
</blockquote>
The Github repo is:<br/> <a href="https://github.com/Vishnu44d/compiler_parser_GUI"> https://github.com/Vishnu44d/compiler_parser_GUI</a>
<div class="leave-me"></div>
</p>
</div>
<script type="text/python" id="script0">
from browser import document, alert
from browser import html
from browser.html import TABLE, TR, TH, TD
from automata import nfa_match, draw_fa
global nS
global nI
global IpSymbols
global ckString
global initial
global finals
global mode
def clean_fa(fa):
for i in fa:
for j in fa[i]:
fa[i][j][0].replace(" ","")
temp = fa[i][j][0].split(",")
fa[i][j] = temp
return fa
def handleCheckNFA(e):
global ns
global ckString
global initial
global finals
fa = {}
for i in range(int(nS)):
#print("cell"+str(i+1)+"1")
sname = document["cell"+str(i+1)+"1"].value
fa[sname] = {j:[] for j in IpSymbols}
k = 2
for j in fa[sname]:
fa[sname][j].append(document["cell"+str(i+1)+str(k)].value)
k += 1
ckString = document['ckeckString'].value
initial = document['initial'].value
finals = document['finals'].value
initial = initial[0]
finals = finals.replace(" ", "")
finals = finals.replace(",", "")
l = []
for i in finals:
l.append(i)
finals = set(l)
new_fa = clean_fa(fa)
#img = draw_fa(new_fa, finals, initial)
ck = nfa_match(new_fa, initial, finals, ckString)
if ck == True:
alert("String "+ckString+" is accepted")
elif ck == False:
alert("String "+ckString+" is Rejected")
else:
alert(ck)
print("Response ", ck)
#print("Image url ", img)
print("Initial ",initial)
print("Finals ", finals)
print("New Fa ", new_fa)
print("Check String ",ckString)
def handleSubmit(e):
global nS
global nI
global IpSymbols
global mode
nS = document['noOfStates'].value
nI = document['nOofSymbols'].value
mode = document['FaMode'].value
print(mode)
IpSymbols = document['IpSymbols'].value
document['zone0'].clear()
ii = html.H1("Enter the Table", Class="center")
table = TABLE()
row = TR() # create a row
row <= TH("states")
for i in IpSymbols:
row <= TH(i)
table <= row # add the row to the table
ii += table
for i in range(int(nS)):
row = TR()
tt = TD(html.INPUT(type="text",id="cell"+str(i+1)+str(1), placeholder="cell"+str(i+1)+str(1)))
for j in range(int(nI)):
tt += TD(html.INPUT(type="text",id="cell"+str(i+1)+str(j+2), placeholder="cell"+str(i+1)+str(j+2)))
row <= tt
table <= row
ii += table
document['zone0'].clear()
document['zone0'] <= ii
document['btns'].style.display = "inline" if document['btns'].style.display == "none" else "none"
document['ab'].style.display = "inline" if document['btns'].style.display == "none" else "none"
def handleCheck(e):
#alert("Check is clicked")
global mode
if mode=="2" or mode=="1":
handleCheckNFA(e)
else:
alert("Please choose the automata")
btn = document["getTab"]
check_btn = document["check"]
btn.bind("click", handleSubmit)
check_btn.bind("click", handleCheck)
</script>
<button type="button" class="btn-floating btn-small waves-effect waves-light red lighten-1 rel" onClick="refreshPage()"><img src="css/refresh.svg" width="60%"></button>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script>
function refreshPage(){
window.location.reload();
}
$(document).ready(function() {
$('select').formSelect();
});
</script>
<div class="container-foot">
<div class="cont">
© 2019 vishnu deo
</div>
</div>
<script src="js/brython.js"></script>
<script src="js/brython_stdlib.js"></script>
<script src="js/materialize.js"></script>
</body>
</html>