求得FIRST集合:
first( INT ): INT
first( VOID ): VOID
first( IF ): IF
first( ELSE ): ELSE
first( WHILE ): WHILE
first( RETURN ): RETURN
first( + ): +
first( - ): -
first( * ): *
first( / ): /
first( < ): <
first( <= ): <=
first( > ): >
first( >= ): >=
first( == ): ==
first( != ): !=
first( = ): =
first( ; ): ;
first( , ): ,
first( ( ): (
first( ) ): )
first( [ ): [
first( ] ): ]
first( { ): {
first( } ): }
first( NUM ): NUM
first( ID ): ID
first( program ): INT VOID
first( declaration_list ): INT VOID
first( declaration_list_ ): EMPTY INT VOID
first( declaration ): INT VOID
first( declaration_ ): ; ( [
first( var_declaration ): ; [
first( fun_declaration ): (
first( fun_declaration_ ): VOID
first( params ): INT VOID
first( param_list ): INT
first( param_list_ ): EMPTY ,
first( param ): INT
first( param_ ): EMPTY [
first( compound_stmt ): {
first( local_declarations ): EMPTY INT
first( statement_list ): EMPTY IF WHILE RETURN ; ( { NUM ID
first( statement ): IF WHILE RETURN ; ( { NUM ID
first( expression_stmt ): ; ( NUM ID
first( selection_stmt ): IF
first( selection_stmt_ ): EMPTY ELSE
first( iteration_stmt ): WHILE
first( return_stmt ): RETURN
first( return_stmt_ ): ; ( NUM ID
first( expression ): ( NUM ID
first( var ): ID
first( var_ ): EMPTY [
first( simple_expression ): ( NUM ID
first( simple_expression_ ): EMPTY < <= > >= == !=
first( relop ): < <= > >= == !=
first( additive_expression ): ( NUM ID
first( additive_expression_ ): EMPTY + -
first( addop ): + -
first( term ): ( NUM ID
first( term_ ): EMPTY * /
first( mulop ): * /
first( factor ): ( NUM ID
first( call ): ID
first( args ): EMPTY ( NUM ID
first( arg_list ): ( NUM ID
first( arg_list_ ): EMPTY ,
求得FOLLOW集合:
follow( program ): $
follow( declaration_list ): $
follow( declaration_list_ ): $
follow( declaration ): $ INT VOID
follow( declaration_ ): $ INT VOID
follow( var_declaration ): $ INT VOID IF WHILE RETURN ; ( { } NUM ID
follow( fun_declaration ): $ INT VOID
follow( fun_declaration_ ): $ INT VOID
follow( params ): )
follow( param_list ): )
follow( param_list_ ): )
follow( param ): , )
follow( param_ ): , )
follow( compound_stmt ): $ INT VOID IF ELSE WHILE RETURN ; ( { } NUM ID
follow( local_declarations ): IF WHILE RETURN ; ( { } NUM ID
follow( statement_list ): }
follow( statement ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( expression_stmt ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( selection_stmt ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( selection_stmt_ ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( iteration_stmt ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( return_stmt ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( return_stmt_ ): IF ELSE WHILE RETURN ; ( { } NUM ID
follow( expression ): ; , )
follow( var ): + - * / < <= > >= == != = ; , ) ]
follow( var_ ): + - * / < <= > >= == != = ; , ) ]
follow( simple_expression ): ; , ) ]
follow( simple_expression_ ): ; , ) ]
follow( relop ): ( NUM ID
follow( additive_expression ): < <= > >= == != ; , ) ]
follow( additive_expression_ ): < <= > >= == != ; , ) ]
follow( addop ): ( NUM ID
follow( term ): + - < <= > >= == != ; , ) ]
follow( term_ ): + - < <= > >= == != ; , ) ]
follow( mulop ): ( NUM ID
follow( factor ): + - * / < <= > >= == != ; , ) ]
follow( call ): + - * / < <= > >= == != ; , ) ]
follow( args ): )
follow( arg_list ): )
follow( arg_list_ ): )
求得 M LL(1)集合:
$INTVOI IFELSWHIRET + - * / < <= > >= == != = ; , ( ) [ ] { }NUM ID
------------------------------------------------------------------------------------------
program : 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
declaration_list : 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
declaration_list_ : -1 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
declaration : 0 5 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
declaration_ : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 8 0 7 0 0 0 0 0
var_declaration : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 10 0 0 0 0 0
fun_declaration : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0
fun_declaration_ : 0 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
params : 0 13 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
param_list : 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
param_list_ : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 -1 0 0 0 0 0 0
param : 0 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
param_ : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 19 0 0 0 0 0
compound_stmt : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 0 0 0
local_declarations : 0 22 0 -1 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 -1 -1 -1 -1
statement_list : 0 0 0 24 0 24 24 0 0 0 0 0 0 0 0 0 0 0 24 0 24 0 0 0 24 -1 24 24
statement : 0 0 0 28 0 29 30 0 0 0 0 0 0 0 0 0 0 0 26 0 26 0 0 0 27 0 26 26
expression_stmt : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 0 31 0 0 0 0 0 31 31
selection_stmt : 0 0 0 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
selection_stmt_ : 0 0 0 -1 34 -1 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 -1 -1 -1 -1
iteration_stmt : 0 0 0 0 0 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
return_stmt : 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
return_stmt_ : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 39 0 0 0 0 0 39 39
expression : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 0 0 0 0 0 41 40
var : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42
var_ : 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 43 -1 0 0 0 0
simple_expression : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 0 0 0 0 0 45 45
simple_expression_ : 0 0 0 0 0 0 0 0 0 0 0 46 46 46 46 46 46 0 -1 -1 0 -1 0 -1 0 0 0 0
relop : 0 0 0 0 0 0 0 0 0 0 0 48 50 49 51 52 53 0 0 0 0 0 0 0 0 0 0 0
additive_expression : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 54 0 0 0 0 0 54 54
additive_expression_: 0 0 0 0 0 0 0 55 55 0 0 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 0 -1 0 0 0 0
addop