-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.cup
63 lines (59 loc) · 1.95 KB
/
state.cup
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
package main;
import main.ast.*;
import java.util.ArrayList;
terminal START, LALRWRD, COLON, LSQ, RSQ, LCUR, RCUR, DERSYM, COMMA, DOTSYM, TRANWRD,
STATEWRD, SEP;
terminal Integer ID;
terminal String SNUM;
nonterminal StartStateNode StartState;
nonterminal StatesNode States;
nonterminal StateNode State;
nonterminal ItemsNode Items;
nonterminal ItemNode Item;
nonterminal TransNode Trans;
nonterminal TranNode Tran;
nonterminal SentFormNode SentForm;
nonterminal ArrayList<Integer> Ids;
StartState ::= START States:s
{: RESULT = new StartStateNode(s); :}
;
States ::= State:s States:ss
{: RESULT = new StatesNode(s, ss); :}
| State:s
{: RESULT = new StatesNode(s); :}
;
State ::= LALRWRD LSQ SNUM:n RSQ COLON LCUR Items:i RCUR Trans:t SEP
{: RESULT = new StateNode(n, i, t); :}
| LALRWRD LSQ SNUM:n RSQ COLON LCUR Items:i RCUR SEP /* Items complete */
{: RESULT = new StateNode(n, i); :}
;
Items ::= Item:i Items:ii
{: RESULT = new ItemsNode(i, ii); :}
| Item:i
{: RESULT = new ItemsNode(i); :}
;
Item ::= LSQ ID:nt DERSYM SentForm:sf COMMA LCUR Ids:fs RCUR RSQ
{: RESULT = new ItemNode(nt, sf, fs); :}
;
SentForm ::= DOTSYM Ids:i
{: RESULT = new SentFormNode(DotSymPos.BEGIN, i); :}
| Ids:i DOTSYM
{: RESULT = new SentFormNode(DotSymPos.END, i); :}
| Ids:i1 DOTSYM Ids:i2
{: RESULT = new SentFormNode(i1, i2); :}
| DOTSYM /* this happens with empty productions */
{: RESULT = new SentFormNode(); :}
;
Ids ::= ID:i Ids:ii
{: RESULT = new ArrayList<>(); RESULT.add(i); RESULT.addAll(ii); :}
| ID:i
{: RESULT = new ArrayList<>(); RESULT.add(i); :}
;
Trans ::= Tran:t Trans:tt
{: RESULT = new TransNode(t, tt); :}
| Tran:t
{: RESULT = new TransNode(t); :}
;
Tran ::= TRANWRD ID:i STATEWRD LSQ SNUM:n RSQ
{: RESULT = new TranNode(i, n); :}
;