// $ANTLR : "program.g" -> "programParser.java"$

import edu.neu.ccs.demeter.*;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class programParser extends antlr.LLkParser       implements programParserTokenTypes
 {

  static char unescapifyChar(String s) {
    char c = s.charAt(0);
    if (c == '\\') {
      switch (s.charAt(1)) {
      case 'n': c = '\n'; break;
      case 't': c = '\t'; break;
      case 'b': c = '\b'; break;
      case 'r': c = '\r'; break;
      case 'f': c = '\f'; break;
      case '\\': c = '\\'; break;
      case '\'': c = '\''; break;
      case '\"': c = '\"'; break;
      default:
       c = (char) Integer.parseInt(s.substring(1, s.length()), 8);
       break;
      }
    }
    return c;
  }
  static String unescapify(String s) {
    char str[] = new char[s.length()];
    int i = 0, o = 0;
    while (i < s.length()) {
      char c = s.charAt(i++);
      if (c == '\\') {
       int j = i + 1;
       while (j < s.length() &&
              Character.digit(s.charAt(j), 8) != -1) {
         j++;
       }
       c = unescapifyChar(s.substring(i-1, j));
       i = j;
      }
      str[o++] = c;
    }
    return String.valueOf(str, 0, o);
  }

protected programParser(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public programParser(TokenBuffer tokenBuf) {
  this(tokenBuf,1);
}

protected programParser(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public programParser(TokenStream lexer) {
  this(lexer,1);
}

public programParser(ParserSharedInputState state) {
  super(state,1);
  tokenNames = _tokenNames;
}

	public final ChineseWallPolicyChecker  parseChineseWallPolicyChecker() throws RecognitionException, TokenStreamException {
		ChineseWallPolicyChecker it;
		
		
		it = new ChineseWallPolicyChecker();
		ChineseWallAutomaton_List the_chineseWallAutomaton_List = null;
		
		
		the_chineseWallAutomaton_List=parseChineseWallAutomaton_List();
		it.chineseWallAutomaton_List = the_chineseWallAutomaton_List;
		match(Token.EOF_TYPE);
		return it;
	}
	
	public final ChineseWallAutomaton_List  parseChineseWallAutomaton_List() throws RecognitionException, TokenStreamException {
		ChineseWallAutomaton_List it;
		
		
		it = new ChineseWallAutomaton_List();
		ChineseWallAutomaton the_repeatedPart = null;
		
		
		match(15);
		{
		_loop17:
		do {
			if ((LA(1)==LITERAL_Chinese)) {
				the_repeatedPart=parseChineseWallAutomaton();
				it.add(the_repeatedPart);
			}
			else {
				break _loop17;
			}
			
		} while (true);
		}
		match(16);
		return it;
	}
	
	public final ChineseWallAutomaton  parseChineseWallAutomaton() throws RecognitionException, TokenStreamException {
		ChineseWallAutomaton it;
		
		
		it = new ChineseWallAutomaton();
		AutomatonName the_automatonName = null;
		State the_currentState = null;
		State the_startState = null;
		Transition_List the_transition = null;
		Group_List the_groups = null;
		CIType_List the_citypes = null;
		Access_List the_history = null;
		
		
		match(LITERAL_Chinese);
		match(LITERAL_Wall);
		match(LITERAL_automaton);
		the_automatonName=parseAutomatonName();
		it.automatonName = the_automatonName;
		match(LITERAL_currentState);
		the_currentState=parseState();
		it.currentState = the_currentState;
		{
		switch ( LA(1)) {
		case LITERAL_startState:
		{
			match(LITERAL_startState);
			the_startState=parseState();
			it.startState = the_startState;
			break;
		}
		case LITERAL_transitions:
		case LITERAL_groups:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
		{
		switch ( LA(1)) {
		case LITERAL_transitions:
		{
			match(LITERAL_transitions);
			the_transition=parseTransition_List();
			it.transition = the_transition;
			break;
		}
		case LITERAL_groups:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
		match(LITERAL_groups);
		the_groups=parseGroup_List();
		it.groups = the_groups;
		match(LITERAL_citypes);
		the_citypes=parseCIType_List();
		it.citypes = the_citypes;
		match(LITERAL_history);
		the_history=parseAccess_List();
		it.history = the_history;
		return it;
	}
	
	public final AutomatonName  parseAutomatonName() throws RecognitionException, TokenStreamException {
		AutomatonName it;
		
		
		it = new AutomatonName();
		Ident the_ident = null;
		
		
		the_ident=parseIdent();
		it.ident = the_ident;
		return it;
	}
	
	public final State  parseState() throws RecognitionException, TokenStreamException {
		State it;
		
		
		it = new State();
		Group_List the_g_accesses = null;
		CIType_List the_t_accesses = null;
		
		
		the_g_accesses=parseGroup_List();
		it.g_accesses = the_g_accesses;
		the_t_accesses=parseCIType_List();
		it.t_accesses = the_t_accesses;
		return it;
	}
	
	public final Transition_List  parseTransition_List() throws RecognitionException, TokenStreamException {
		Transition_List it;
		
		
		it = new Transition_List();
		Transition the_repeatedPart = null;
		
		
		match(15);
		{
		_loop20:
		do {
			if ((LA(1)==IDENT)) {
				the_repeatedPart=parseTransition();
				it.add(the_repeatedPart);
			}
			else {
				break _loop20;
			}
			
		} while (true);
		}
		match(16);
		return it;
	}
	
	public final Group_List  parseGroup_List() throws RecognitionException, TokenStreamException {
		Group_List it;
		
		
		it = new Group_List();
		Group the_repeatedPart = null;
		
		
		match(15);
		{
		_loop23:
		do {
			if ((LA(1)==IDENT)) {
				the_repeatedPart=parseGroup();
				it.add(the_repeatedPart);
			}
			else {
				break _loop23;
			}
			
		} while (true);
		}
		match(16);
		return it;
	}
	
	public final CIType_List  parseCIType_List() throws RecognitionException, TokenStreamException {
		CIType_List it;
		
		
		it = new CIType_List();
		CIType the_repeatedPart = null;
		
		
		match(15);
		{
		_loop26:
		do {
			if ((LA(1)==IDENT)) {
				the_repeatedPart=parseCIType();
				it.add(the_repeatedPart);
			}
			else {
				break _loop26;
			}
			
		} while (true);
		}
		match(16);
		return it;
	}
	
	public final Access_List  parseAccess_List() throws RecognitionException, TokenStreamException {
		Access_List it;
		
		
		it = new Access_List();
		Access the_repeatedPart = null;
		
		
		match(15);
		{
		_loop29:
		do {
			if ((LA(1)==IDENT)) {
				the_repeatedPart=parseAccess();
				it.add(the_repeatedPart);
			}
			else {
				break _loop29;
			}
			
		} while (true);
		}
		match(16);
		return it;
	}
	
	public final Access  parseAccess() throws RecognitionException, TokenStreamException {
		Access it;
		
		
		it = new Access();
		ObjektId the_objektId = null;
		Group the_group = null;
		
		
		the_objektId=parseObjektId();
		it.objektId = the_objektId;
		match(LITERAL_group);
		the_group=parseGroup();
		it.group = the_group;
		return it;
	}
	
	public final ObjektId  parseObjektId() throws RecognitionException, TokenStreamException {
		ObjektId it;
		
		
		it = new ObjektId();
		Ident the_ident = null;
		
		
		the_ident=parseIdent();
		it.ident = the_ident;
		return it;
	}
	
	public final Group  parseGroup() throws RecognitionException, TokenStreamException {
		Group it;
		
		
		it = new Group();
		GroupName the_groupName = null;
		CIType the_cIType = null;
		
		
		the_groupName=parseGroupName();
		it.groupName = the_groupName;
		{
		switch ( LA(1)) {
		case LITERAL_citype:
		{
			match(LITERAL_citype);
			the_cIType=parseCIType();
			it.cIType = the_cIType;
			break;
		}
		case 16:
		case IDENT:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
		return it;
	}
	
	public final GroupName  parseGroupName() throws RecognitionException, TokenStreamException {
		GroupName it;
		
		
		it = new GroupName();
		Ident the_ident = null;
		
		
		the_ident=parseIdent();
		it.ident = the_ident;
		return it;
	}
	
	public final CIType  parseCIType() throws RecognitionException, TokenStreamException {
		CIType it;
		
		
		it = new CIType();
		CITypeName the_cITypeName = null;
		
		
		the_cITypeName=parseCITypeName();
		it.cITypeName = the_cITypeName;
		return it;
	}
	
	public final CITypeName  parseCITypeName() throws RecognitionException, TokenStreamException {
		CITypeName it;
		
		
		it = new CITypeName();
		Ident the_ident = null;
		
		
		the_ident=parseIdent();
		it.ident = the_ident;
		return it;
	}
	
	public final Transition  parseTransition() throws RecognitionException, TokenStreamException {
		Transition it;
		
		
		it = new Transition();
		Access the_newAccess = null;
		
		
		the_newAccess=parseAccess();
		it.newAccess = the_newAccess;
		return it;
	}
	
	public final Ident  parseIdent() throws RecognitionException, TokenStreamException {
		Ident it;
		
		Token  t = null;
		
		t = LT(1);
		match(IDENT);
		it = new Ident(t.getText());
		return it;
	}
	
	public final boolean  parseboolean() throws RecognitionException, TokenStreamException {
		boolean it;
		
		
		switch ( LA(1)) {
		case LITERAL_true:
		{
			match(LITERAL_true);
			it = true;
			break;
		}
		case LITERAL_false:
		{
			match(LITERAL_false);
			it = false;
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		return it;
	}
	
	public final char  parsechar() throws RecognitionException, TokenStreamException {
		char it;
		
		Token  t = null;
		
		t = LT(1);
		match(CHAR_LITERAL);
		String s = t.getText();
		it = unescapifyChar(s.substring(1, s.length()-1));
		return it;
	}
	
	public final byte  parsebyte() throws RecognitionException, TokenStreamException {
		byte it;
		
		int i;
		
		i=parseint();
		it = (byte) i;
		return it;
	}
	
	public final int  parseint() throws RecognitionException, TokenStreamException {
		int it;
		
		Token  t = null;
		
		t = LT(1);
		match(NUM_INT);
		it = Integer.parseInt(t.getText());
		return it;
	}
	
	public final short  parseshort() throws RecognitionException, TokenStreamException {
		short it;
		
		int i;
		
		i=parseint();
		it = (short) i;
		return it;
	}
	
	public final long  parselong() throws RecognitionException, TokenStreamException {
		long it;
		
		Token  t = null;
		
		t = LT(1);
		match(NUM_LONG);
		String s = t.getText();
		it = Long.parseLong(s.substring(0,s.length()-1));
		return it;
	}
	
	public final float  parsefloat() throws RecognitionException, TokenStreamException {
		float it;
		
		Token  t = null;
		
		t = LT(1);
		match(NUM_FLOAT);
		String s = t.getText();
		it = Float.parseFloat(s.substring(0,s.length()-1));
		return it;
	}
	
	public final double  parsedouble() throws RecognitionException, TokenStreamException {
		double it;
		
		Token  t = null;
		
		t = LT(1);
		match(NUM_DOUBLE);
		String s = t.getText();
		if (s.endsWith("D") || s.endsWith("d"))
		it = Double.parseDouble(s.substring(0,s.length()-1));
		else
		it = Double.parseDouble(s);
		return it;
	}
	
	public final Boolean  parseBoolean() throws RecognitionException, TokenStreamException {
		Boolean it;
		
		
		switch ( LA(1)) {
		case LITERAL_true:
		{
			match(LITERAL_true);
			it = Boolean.TRUE;
			break;
		}
		case LITERAL_false:
		{
			match(LITERAL_false);
			it = Boolean.FALSE;
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		return it;
	}
	
	public final Character  parseCharacter() throws RecognitionException, TokenStreamException {
		Character it;
		
		char c;
		
		c=parsechar();
		it = new Character(c);
		return it;
	}
	
	public final Byte  parseByte() throws RecognitionException, TokenStreamException {
		Byte it;
		
		byte b;
		
		b=parsebyte();
		it = new Byte(b);
		return it;
	}
	
	public final Integer  parseInteger() throws RecognitionException, TokenStreamException {
		Integer it;
		
		int i;
		
		i=parseint();
		it = new Integer(i);
		return it;
	}
	
	public final Long  parseLong() throws RecognitionException, TokenStreamException {
		Long it;
		
		long l;
		
		l=parselong();
		it = new Long(l);
		return it;
	}
	
	public final Float  parseFloat() throws RecognitionException, TokenStreamException {
		Float it;
		
		float f;
		
		f=parsefloat();
		it = new Float(f);
		return it;
	}
	
	public final Double  parseDouble() throws RecognitionException, TokenStreamException {
		Double it;
		
		double d;
		
		d=parsedouble();
		it = new Double(d);
		return it;
	}
	
	public final Number  parseNumber() throws RecognitionException, TokenStreamException {
		Number it;
		
		
		switch ( LA(1)) {
		case NUM_INT:
		{
			it=parseInteger();
			break;
		}
		case NUM_LONG:
		{
			it=parseLong();
			break;
		}
		case NUM_FLOAT:
		{
			it=parseFloat();
			break;
		}
		case NUM_DOUBLE:
		{
			it=parseDouble();
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		return it;
	}
	
	public final String  parseString() throws RecognitionException, TokenStreamException {
		String it;
		
		Token  t = null;
		
		t = LT(1);
		match(STRING_LITERAL);
		String s = t.getText();
		it = unescapify(s.substring(1, s.length()-1));
		return it;
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"\"Chinese\"",
		"\"Wall\"",
		"\"automaton\"",
		"\"currentState\"",
		"\"startState\"",
		"\"transitions\"",
		"\"groups\"",
		"\"citypes\"",
		"\"history\"",
		"\"group\"",
		"\"citype\"",
		"\"(\"",
		"\")\"",
		"\"true\"",
		"\"false\"",
		"CHAR_LITERAL",
		"NUM_INT",
		"NUM_LONG",
		"NUM_FLOAT",
		"NUM_DOUBLE",
		"STRING_LITERAL",
		"IDENT",
		"DOT",
		"WS",
		"SL_COMMENT",
		"ML_COMMENT",
		"ESC",
		"HEX_DIGIT",
		"VOCAB",
		"EXPONENT",
		"FLOAT_SUFFIX"
	};
	
	
	}