1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 import com.daffodilwoods.daffodildb.server.sql99.token._TOKEN; 4 import com.daffodilwoods.daffodildb.server.sql99.token.regularidentifier; 5 import com.daffodilwoods.database.resource.*; 6 import com.daffodilwoods.database.utility.P; 7 8 public class TokenProductionRule extends ProductionRules implements _TOKEN { 9 10 String name; 11 char []array; 12 private int Type; 13 14 public TokenProductionRule(String productionRuleName,String name, 15 char[] array,ClassLoader classLoader0,int type0) 16 { 17 super(classLoader0); 18 nameOfRule = name; 19 Type = type0; 20 this.name = productionRuleName; 21 this.array = array; 22 } 23 24 public int getType(){ 25 return Type; 26 } 27 28 29 public String toString(){ 30 return nameOfRule; 31 } 32 33 public Object getComparableObject(){ 34 return result; 35 } 36 37 public Object getComparableObjectArray(){ 38 if ( result instanceof String [] ) 39 return result; 40 return new String []{(String )result}; 41 } 42 43 Object parsePart(ParseElements pe){ 44 if ( pe.position > (pe.tokens.length - 1) ){ 45 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 46 return pe.parseException; 47 } 48 int cmp = checkString(pe.queryTokenCharacterArray[pe.position],array,pe.position); 49 if ( cmp == 0 ){ 50 pe.position++; 51 return pe.tokens[(pe.position)-1]; 52 } 53 cmp = cmp > 0 ? 1 : cmp < 0 ? -1 : 0; 54 if ( Type == 4 && (((_TOKEN)pe.tokens[pe.position]).getType() == _TOKEN.NONRESERVEDWORD ) ) 55 cmp = 1; 56 else if ( Type == 3 && (((_TOKEN)pe.tokens[pe.position]).getType() == _TOKEN.NONRESERVEDWORD ) ){ 57 return getRegularIdenifier(pe); 58 } 59 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 60 pe.parseException.setReturnType(cmp); 61 return pe.parseException; 62 } 63 64 private regularidentifier getRegularIdenifier(ParseElements pe){ 65 regularidentifier ri = new regularidentifier(); 66 ri._regularidentifier0 = pe.tokens[pe.position].toString().trim(); 67 ++pe.position; 68 return ri; 69 } 70 71 private int checkString(char []source, char[] target,int position){ 72 77 int compare = 0; 78 for(int i = 0,j = 0; i < source.length && j < target.length && compare == 0; ++j,++i) 79 compare = source[i] - target[j]; 80 if (compare != 0 ) 81 return compare; 82 return source.length - target.length; 83 } 84 } 85 86 87 | Popular Tags |