1 8 9 package net.sourceforge.chaperon.process.extended; 10 11 import net.sourceforge.chaperon.model.extended.Pattern; 12 13 17 public class ReduceAction 18 { 19 public final String symbol; 20 public final Pattern pattern; 21 public final int length; 22 23 public ReduceAction(String symbol, int length) 24 { 25 if (symbol==null) 26 throw new IllegalArgumentException ("Symbol is null"); 27 28 if ((length!=0) && (length!=2)) 29 throw new IllegalArgumentException ("Only reduce lengths 0 and 2 are allowed"); 30 31 this.symbol = symbol; 32 this.pattern = null; 33 this.length = length; 34 } 35 36 public ReduceAction(Pattern pattern, int length) 37 { 38 if (pattern==null) 39 throw new IllegalArgumentException ("Pattern is null"); 40 41 if ((length!=0) && (length!=2)) 42 throw new IllegalArgumentException ("Only reduce lengths 0 and 2 are allowed"); 43 44 this.symbol = null; 45 this.pattern = pattern; 46 this.length = length; 47 } 48 49 public boolean equals(Object o) 50 { 51 if (o instanceof ReduceAction) 52 { 53 ReduceAction reduceAction = (ReduceAction)o; 54 55 if (symbol!=null) 56 return (reduceAction.symbol!=null) && (symbol.equals(reduceAction.symbol)) && 57 (length==reduceAction.length); 58 59 return (pattern==reduceAction.pattern) && (length==reduceAction.length); 60 } 61 62 return false; 63 } 64 65 public String toString() 66 { 67 return "reduce "+((symbol!=null) ? (symbol+"("+length+")") : (pattern+"("+length+")")); 68 } 69 } 70 | Popular Tags |