测试SLR文法例子

来源:互联网 发布:单机游戏网络对战平台 编辑:程序博客网 时间:2024/05/01 19:25

输入的文法

int
if
then
else
while
do
and
not
true
id
(
)
{
}
;
:
<
=
+
*
$
##################################
O
P
D
A
S
K
C
B
R
W
U
L
N
E
T
F
M
H
[
##################################
O->P
P->D
D->D;D
D->A:id
D->id()D;S
A->int
S->id=K E
C->if B then
R->C S else
S->R S
S->C S
W->while
U->W B do
S->U S
S->{L}
L->L;NS
L->S
K->[
N->[
E->E+T
E->T
E->T*F
T->F
F->(E)
F->id
B->B and M B
B->not H B
B->id<id
B->true
M->[
H->[
##################################

注意:
1.务必把$作为最后一个终结符输入。
2.务必把З作为最后一个终结符输入。
3.务必把拓广符号S及原来的开始符号放在非终结符的第1、2个。
4.#号分隔符是必须的:终结符、非终结符、产生式。

输出的分析表及first集和follow集,共有61个状态

First collection of "int" is :int
First collection of "if" is :if
First collection of "then" is :then
First collection of "else" is :else
First collection of "while" is :while
First collection of "do" is :do
First collection of "and" is :and
First collection of "not" is :not
First collection of "true" is :true
First collection of "id" is :id
First collection of "(" is :(
First collection of ")" is :)
First collection of "{" is :{
First collection of "}" is :}
First collection of ";" is :;
First collection of ":" is ::
First collection of "<" is :<
First collection of "=" is :=
First collection of "+" is :+
First collection of "*" is :*
First collection of "$" is :$
First collection of "O" is :id int
First collection of "P" is :id int
First collection of "D" is :id int
First collection of "A" is :int
First collection of "S" is :id { if while
First collection of "K" is :[
First collection of "C" is :if
First collection of "B" is :not id true
First collection of "R" is :if
First collection of "W" is :while
First collection of "U" is :while
First collection of "L" is :id { if while
First collection of "N" is :[
First collection of "E" is :( id
First collection of "T" is :( id
First collection of "F" is :( id
First collection of "M" is :[
First collection of "H" is :[
First collection of "[" is :
Follow collection of "O" is :$
Follow collection of "P" is :$
Follow collection of "D" is :$ ;
Follow collection of "A" is ::
Follow collection of "S" is :$ ; else }
Follow collection of "K" is :( id
Follow collection of "C" is :id { if while
Follow collection of "B" is :then do and
Follow collection of "R" is :id { if while
Follow collection of "W" is :not id true
Follow collection of "U" is :id { if while
Follow collection of "L" is :} ;
Follow collection of "N" is :id { if while
Follow collection of "E" is :$ ; + ) else }
Follow collection of "T" is :$ ; + * ) else }
Follow collection of "F" is :$ ; + * ) else }
Follow collection of "M" is :not id true
Follow collection of "H" is :not id true
Follow collection of "[" is :

(分析表太大,61×39项,这里只显示其左上部分)
           1    2    3    4    5    6    7    8    9   10   11   12    ........39
state0    s4    0    0    0    0    0    0    0    0   s5    0    0  
state1     0    0    0    0    0    0    0    0    0    0    0    0     
state2     0    0    0    0    0    0    0    0    0    0    0    0     
state3     0    0    0    0    0    0    0    0    0    0    0    0    
state4     0    0    0    0    0    0    0    0    0    0    0    0    
state5     0    0    0    0    0    0    0    0    0    0   s8    0 
state6    s4    0    0    0    0    0    0    0    0   s5    0    0 
state7     0    0    0    0    0    0    0    0    0   s10   0    0 
state8     0    0    0    0    0    0    0    0    0    0    0   s11 
state9     0    0    0    0    0    0    0    0    0    0    0    0   
.
.
state60