diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:55:17 -0700 |
| commit | 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch) | |
| tree | ed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/project-three/parser/Action.java | |
| download | misc-undergrad-main.tar.gz misc-undergrad-main.zip | |
Diffstat (limited to 'Homework/cs5300/project-three/parser/Action.java')
| -rw-r--r-- | Homework/cs5300/project-three/parser/Action.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Homework/cs5300/project-three/parser/Action.java b/Homework/cs5300/project-three/parser/Action.java new file mode 100644 index 0000000..040daab --- /dev/null +++ b/Homework/cs5300/project-three/parser/Action.java @@ -0,0 +1,70 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package parser; + +/** + * + * @author edwajohn + */ +public class Action { + + enum Act { + SHIFT, REDUCE, ACCEPT + }; + + private final Act act; + private final Integer state; + private final Rule rule; + + static Action createShift(Integer state) { + return new Action(Act.SHIFT, state, null); + } + + static Action createReduce(Rule rule) { + return new Action(Act.REDUCE, null, rule); + } + + static Action createAccept() { + return new Action(Act.ACCEPT, null, null); + } + + private Action(Act act, Integer state, Rule rule) { + this.act = act; + this.state = state; + this.rule = rule; + } + + public boolean isShift() { + return act == Act.SHIFT; + } + + public boolean isReduce() { + return act == Act.REDUCE; + } + + public boolean isAccept() { + return act == Act.ACCEPT; + } + + public Integer getState() { + return state; + } + + public Rule getRule() { + return rule; + } + + @Override + public String toString() { + if (isShift()) { + return "S" + state; + } + if (isReduce()) { + return "R" + rule.getName(); + } + return "acc"; + } +} |
