Syntax and semantic implementation process
1 program ---> main {declared statement set}
2 declaration ---> int s; | EMPTY
3 s ---> v, s
4 s ---> v
5 V -> ID
6 V -> ID = DIGIT
7 Statement Set ---> Specific Statement Statement Set | EMPTY
8 Statement Set ---> Specific Statement | EMPTY
9 Specific Statement ---> Assignment Statement | Select Statement | Cyclic Schedule | Read Value Statement | Print Statement
10 Assignment statement ---> ID = E;
11 E ---> T E
12 E ---> T-E
13 E ---> T
14 T ---> ID | DIGIT
15 Judgment ---> T Relop T
16 Relop ---> <= | <|> |> = | == |! =
17 Select Statements ---> M
18 Select statements ---> m else h
19 m ---> IF (judgment) h
20 h ---> Brand 1 Statement Brand 2
21 Brand 1 ---> {| EMPTY
22 Brand 2 --->} | EMPTY
23 cycle statement ---> while (judgment) h
24 Read the value statement ---> read id;
25 printing statement ---> Print C;
26 c ---> b c
27 c ---> b - c
28 c ---> b
29 b ---> ID
First && Follow Table
Generate
First
FOLLOW
1 program ---> main {declared statement set}
{main}
{#}
2 declaration ---> int s; | EMPTY
{INT} {empty}
{} Id if while read print}
3 s ---> v, s
{Id}
{;
4 s ---> v
{Id}
{;
5 V -> ID
{Id}
{,;
6 V -> ID = DIGIT
{Id}
{,;
7 Statement Set ---> Specific Statement Statement Set | EMPTY
{ID {empty}
{}}
8 Statement Set ---> Specific Statement | EMPTY
{ID {empty}
{}}
9 Specific Statement ---> Assignment Statement | Select Statement | Cyclic Schedule | Read Value Statement | Print Statement
{Id} {if} {while} {read} {print}
{Id if while}}}
10 Assignment statement ---> ID = E;
{Id}
{Id if while}}}
11 E ---> T E
{ID DIGIT}
{;
12 E ---> T-E
{ID DIGIT}
{;
13 E ---> T
{ID DIGIT}
{;
14 T ---> ID | DIGIT
{ID} {DIGIT}
{ -;
15 Judgment ---> T Relop T
{ID DIGIT}
{)}
16 Relop ---> <= | <|> |> = | == |! =
{<=} {<} {>} {> =} {==} {! =}
{ID DIGIT}
17 Select Statements ---> M
{if}
{Id if while}}}
18 Select statements ---> m else h
{if}
{Id if while}}}
19 m ---> IF (judgment) h {i}
{Id if while readprint} else}
20 h ---> Brand 1 Statement Brand 2
{{Id if while}
{Id if while readprint} else}
21 Brand 1 ---> {| EMPTY
{{} {EMPTY}
{Id if while}}}
22 Brand 2 --->} | EMPTY
{}} {EMPTY}
{Id if while readprint} else}
23 cycle statement ---> while (judgment) h
{while}
{Id if while}}}
24 Read the value statement ---> read id;
{read}
{Id if while}}}
25 printing statement ---> Print C;
{print}
{Id if while}}}
26 c ---> b c
{Id}
{;
27 c ---> b - c
{Id}
{;
28 c ---> b
{Id}
{;
29 b ---> ID
{Id}
{ -;
LL (1) analysis table
Main {} int Digit ID if else While Read Print Program -> Main {Declaration Statement Set}
statement
Declaration -> EMPTY Declaration -> INT S;
Disclaimer -> EMPTY Declaration -> EMPTY
Disclaimer -> EMPTY Declaration -> EMPTY Declaration -> EMPTY S
S-> v, s S-> V
V
V-> id v-> id = DIGIT
Statement set
Statement Set -> EMPTY
Statement Set -> Specific Statement Statement Set Statement Set -> Specific Statement Statement Set -> Specific Statement Statement Set Statement Set -> Specific Statement
Statement Set -> Specific Statement Statement Collection -> Specific Statement Statement Set -> Specific Statement Statement Set -> Specific Statement Statement Set Statement Set -> Specific Statement
Specific statement -> assignment statement
Specific statement -> Select statement
Specific statement -> cycle statement specific statement -> read value statement specific statement -> Print statement assignment statement
Assignment Statement -> ID = E;
E
E-> T E E-> T-E E-> T E-> T E E-> T-E E-> T
T
T-> Digit T-> ID
Judgment
Judgment -> e Relop E Judgment -> e Relop E
Select statement
Select Statements -> M Select Statements -> M Else H
M
M-> IF (judgment) h
Hide
H-> Brand 1 Statement Brand 2
H-> Brand 1 statement package 2 h-> Brand 1 statement package bracket 2
H-> Brand 1 Statement Brand 2 H-> Brand 1 Statement Brand 2 H-> Brand 1 Statement Brand 2 Brand 1
Brand 1 -> {Brand 1-> EMPTY
Brand 1-> EMPTY Brand 1-> EMPTY
Brand 1-> EMPTY Braces 1-> EMPTY Brand 1-> EMPTY Brand 2
Brand 2->} Brand 2-> EMPTY
Brand 2-> EMPTY Braces 2-> EMPTY Braces 2-> EMPTY Brand 2-> EMPTY Brand 2-> EMPTY Brand 2-> EMPTY Cycle
Circular statement -> while (judgment) h
Read value statement
Read value statement -> read id;
Print statement
Print statement -> Print C; cc-> b c c-> b-c c-> b
B
B-> ID
Examples of running the following: main () // Very good! {INT A = 5, C, D, E; INT B = 7; c = 56; E = 10; Read D; / * Read value statement * / Print D; if (c