/// <summary>
        /// Returns true if the parser successfully parses a BNF file. Else, check errorText.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool Parse(String input)
        {
            try
            {
                fileText = input.Trim(); ;
                rules = new List<NonterminalHeadD>();

                if (String.IsNullOrEmpty(fileText))
                    throw new Exception("Input is null or empty.");

                // lexical analysis
                LexicalAnalyser lexA = new LexicalAnalyser(fileText);
                if (!lexA.Analyse())
                {
                    errorText = lexA.ErrorMsg;
                    return false;
                }

                // syntactic analysis
                SyntaxAnalyser synA = new SyntaxAnalyser(lexA);
                if (!synA.Analyse())
                {
                    errorText = synA.ErrorMsg;
                    return false;
                }

                // semantic analysis
                SemanticAnalyser semA = new SemanticAnalyser(synA);

                if (!semA.Analyse())
                {
                    errorText = semA.ErrorMsg;
                    return false;
                }

                // save the rules form semantic analyser :-)
                rules = semA.Rules;
                if (rules == null || rules.Count == 0)
                    throw new Exception("The semantic analyser did not find any rules in the input text.");

                return true;
            }
            catch (Exception e)
            {
                errorText = e.Message;
                return false;
            }
        }
 public SyntaxAnalyser(LexicalAnalyser lexAIn)
 {
     Init(lexAIn);
 }
        private void Init(LexicalAnalyser lexAIn)
        {
            lexA = lexAIn;

            current = 0;

            productionRulesHead = new List<Lexeme>();
            productionRulesTail = new ArrayList();

            inRule = false;
        }