📄 编译原理的算符优先文法[网页版]).htm
字号:
Mid(strArray(i), j, 1)) - 1) & a(Instr(tempStra, Mid(strArray(i), j +
1, 1)) - 1) & =<BR> 'Response.write a(Instr(tempStra,
Mid(strArray(i), j, 1)) - 1) & = & a(Instr(tempStra,
Mid(strArray(i), j + 1, 1)) - 1) & <br><BR> End
If<BR> If j <= Len(strArray(i)) - 2 And Instr(tempStra,
Mid(strArray(i), j, 1)) > 0 And Instr(tempStra, Mid(strArray(i), j + 2,
1)) > 0 And Instr(tempStrP, Mid(strArray(i), j + 1, 1)) > 0
Then<BR> tabStr = tabStr & a(Instr(tempStra,
Mid(strArray(i), j, 1)) - 1) & a(Instr(tempStra, Mid(strArray(i), j +
2, 1)) - 1) & =<BR> 'Response.write a(Instr(tempStra,
Mid(strArray(i), j, 1)) - 1) & = & a(Instr(tempStra,
Mid(strArray(i), j + 2, 1)) - 1) & <br><BR> End
If<BR> '------******------******------******------******------******------******------******------******------******<BR> If
Instr(tempStra, Mid(strArray(i), j, 1)) > 0 And Instr(tempStrP,
Mid(strArray(i), j + 1, 1)) > 0 Then<BR> For k = 1 to
Len(strFirstvt(Instr(tempStrP, Left(strArray(i),
1))))<BR> tabStr = tabStr & a(Instr(tempStra,
Mid(strArray(i), j, 1)) - 1) & Mid(strFirstvt(Instr(tempStrP,
Left(strArray(i), 1))), k, 1) & <<BR> 'Response.write
a(Instr(tempStra, Mid(strArray(i), j, 1)) - 1) & &lt; &
Mid(strFirstvt(Instr(tempStrP, Left(strArray(i), 1))), k, 1) &
strArray(i) & <br><BR> Next<BR> End
If<BR> If Instr(tempStrP, Mid(strArray(i), j, 1)) > 0 And
Instr(tempStra, Mid(strArray(i), j + 1, 1)) > 0 Then<BR>
For k = 1 to Len(strLastvt(Instr(tempStrP, Left(strArray(i),
1)))) '此处放LastVt集合<BR> tabStr = tabStr &
Mid(strLastvt(Instr(tempStrP, Left(strArray(i), 1))), k, 1) &
a(Instr(tempStra, Mid(strArray(i), j + 1, 1)) - 1) &
><BR> 'Response.write Mid(strLastvt(Instr(tempStrP,
Left(strArray(i), 1))), k, 1) & &gt; & a(Instr(tempStra,
Mid(strArray(i), j + 1, 1)) - 1) & <br><BR>
Next<BR> End
If<BR> '------******------******------******------******------******------******------******------******------******<BR>
Next<BR>Next<BR>'Response.write Server.HTMLEncode(tabStr) & <br>
&
Len(tabStr)/3<BR>'--------------------------此处生成优先关系表格<BR>Response.write(<li>生成优先关系表如下:
</li> & vbcrlf)<BR>Response.write(<table border=1> &
vbcrlf)<BR>Response.Write(<tr align=center> &
vbcrlf)<BR>Response.Write(<td width=30>&nbsp;</td>)<BR>Dim
sub_a<BR>For each sub_a in a<BR> Response.Write(<td width=30>
& sub_a & </td>)<BR>Next<BR>Response.Write(</tr> &
vbcrlf)<BR>For i = 0 to Ubound(a)<BR> Response.Write(<tr
align=center><td> & a(i) & </td>)<BR> For each
sub_a in a '此处生成对应的a,a的关系<BR> If Instr(tabStr, a(i)
& sub_a) Then<BR> Response.write(<td>
& Mid(tabStr, Instr(tabStr, a(i) & sub_a) + 2, 1) &
</td>)<BR> Else<BR>
Response.write(<td>&nbsp;</td>)<BR> End
If<BR> Next<BR> Response.write(</tr> &
vbcrlf)<BR>Next<BR>Response.write(</table><br>)<BR>'*******************************函数区域*******************************************************<BR>Function
outForL() '输出F(m, n)的值<BR>Response.Write(<table
border=1> & vbcrlf)<BR>Response.Write(<tr align=center> &
vbcrlf)<BR>Response.Write(<td width=20>&nbsp;</td>)<BR>For
j = 0 to n<BR> Response.Write(<td width=20> & a(j) &
</td>)<BR>Next<BR>Response.Write(</tr> & vbcrlf)<BR>For i
= 0 to m<BR> Response.write(<tr align=center> &
vbcrlf)<BR> Response.write(<td> & P(i) &
</td>)<BR> For j = 0 to n<BR>
Response.write(<td> & F(i, j) & </td>)<BR>
Next<BR> Response.write(</tr> & vbcrlf)<BR>Next<BR>
Response.write(</table><br>)<BR>End Function</P>
<P>Function checkInput() '检查输入文法正确性<BR> For i = 0 to
Ubound(strArray)<BR> If Instr(strArray(i), ->)
<> 2 or Len(strArray(i)) < 4 Then<BR> checkInput =
false<BR> Exit Function<BR> End IF<BR>
Next<BR> checkInput = true<BR>End Function</P>
<P>Function pToa(subP, suba) '检查是否P->a<BR> Dim
pToai<BR> For pToai = 0 to Ubound(strArray)<BR> If
Left(strArray(pToai), 1) = subp and Mid(strArray(pToai), 4, 1) = suba
Then<BR> ptoa = true<BR> Exit
Function<BR> End If<BR> Next<BR> pToa = false<BR>End
Function</P>
<P>Function pTo_a(subP, suba) '检查是否P->a<BR> Dim
pTo_ai<BR> For pTo_ai = 0 to Ubound(strArray)<BR>
If Left(strArray(pTo_ai), 1) = subp and Mid(strArray(pTo_ai),
Len(strArray(pTo_ai)), 1) = suba Then<BR> pto_a =
true<BR> Exit Function<BR> End If<BR>
Next<BR> pTo_a = false<BR>End Function</P>
<P>Function pToQa(subP, suba) '检查是否P->Qa<BR> Dim
pToQai<BR> For pToQai = 0 to Ubound(strArray)<BR>
If Left(strArray(pToQai), 1) = subp and Mid(strArray(pToQai), 5, 1) = suba
and Instr(tempStrP, Mid(strArray(pToQai), 4, 1)) Then<BR>
pToQa = true<BR> Exit Function<BR> End If<BR>
Next<BR> pToQa = false<BR>End Function</P>
<P>Function pToaQ(subp, suba)<BR> Dim pToaQi<BR> For pToaQi =
0 to Ubound(strArray)<BR> If Left(strArray(pToaQi), 1) =
subp and Mid(strArray(pToaQi), Len(strArray(pToaQi)) - 1, 1) = suba and
Instr(tempStrP, Mid(strArray(pToaQi), Len(strArray(pToaQi)), 1))
Then<BR> pToaQ = true<BR> Exit
Function<BR> End If<BR> Next<BR> pToaQ = false<BR>End
Function</P>
<P>Function pushStack(s_P, s_a) '入栈stack<BR> Dim
boundStackPush<BR> If Ubound(stack, 2) Then<BR> boundStackPush
= Ubound(stack, 2)<BR> Else<BR> boundStackPush =
0<BR> End If<BR> ReDim Preserve stack(1,
boundStackPush+1)<BR> stack(0, boundStackPush+1) = s_P<BR>
stack(1, boundStackPush+1) = s_a<BR>End Function</P>
<P>Function popStack() '出栈stack<BR> Dim
stackP, boundStackPop, r_p, r_a<BR> boundStackPop = Ubound(stack,
2)<BR> r_P = stack(0, boundStackPop)<BR> r_a = stack(1,
boundStackPop)<BR> ReDim Preserve stack(1,
boundStackPop-1)<BR> popStack = r_P & & r_a<BR>End
Function</P>
<P>Function chStr()<BR> Dim tempStr<BR> For i = 0 to
Ubound(strArray)<BR> If Instr(strArray(i), |)
Then<BR> tempStr = Left(strArray(i), 3) &
Right(strArray(i), Len(strArray(i)) - Instr(strArray(i),
|))<BR> strArray(i) = Left(strArray(i), Instr(strArray(i), |)
- 1)<BR> Redim Preserve strArray(Ubound(strArray) +
1)<BR> strArray(Ubound(strArray)) = tempStr<BR>
Call chStr<BR> End If<BR> Next<BR>End
Function<BR>'*********************************************************************************************<BR>If
err then<BR>Response.write(err.description)<BR>err.clear<BR>end
if<BR>Response.write(<li><a
href=a.htm>返回</a></li><br>)<BR>%><BR></body><BR></html></P>
<P><FONT color=#ff0000><STRONG>a.htm</STRONG></FONT></P>
<P><FONT
color=#000000><html><BR><title>算符优先关系表生成程序</title><BR><style><BR>body {
font-size: 14px }<BR>input { font-size: 14px; height: 20px; border:
1px, solid; border-color: #666666; background: #ffffff
}<BR></style><BR><body><BR><div><BR><br><BR><form
method=post
action=c.asp><BR><li>请在下面文本框中输入文法(各式间以空格隔开,如:<b><font
color=blue>E->E+T|T T->T*F|F F->P↑F|P
P->i|(E)</font></b>)<BR><li><input type=text
name=str size=100 value=E->E+T|T T->T*F|F F->P↑F|P
P->i|(E)><BR><li><input type=Submit value=提交
onmouseover=this.style.background='yellow';
onmouseout=this.style.background='white';><BR><input type=Reset
value=重置 onmouseover=this.style.background='yellow';
onmouseout=this.style.background='white';><BR></form><BR></div><BR></body><BR></html></FONT></P></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -