public void visit(NonterminalHeadD nonterminalHeadD)
        {
            nonterminalHeadD.IsSelected = false;

            // visit rule where representation is done for each choiceLineD
            nonterminalHeadD.Rule.accept(this);
        }
        public void visit(NonterminalHeadD nonterminalHeadD)
        {
            representation = "";
            currentNonterminalHead = nonterminalHeadD;

            // visit rule where representation is done for each choiceLineD
            nonterminalHeadD.Rule.accept(this);
        }
        public GrammarNodeD AddAfter(NonterminalHeadD nonterminalHeadD, GrammarNodeV target, VADG.Global.SymbolType symbolType)
        {
            GrammarNodeDAddAfterVisitor visitor = new GrammarNodeDAddAfterVisitor();
            visitor.Target = target.getReference();
            visitor.SymbolType = symbolType;

            visitor.visit(nonterminalHeadD);

            return visitor.Item;
        }
        public GrammarNodeD AddBefore(NonterminalHeadD nonterminalHeadD, GrammarNodeV grammarNodeV, VADG.Global.SymbolType symbolType)
        {
            GrammarNodeDAddBeforeVisitor visitor = new GrammarNodeDAddBeforeVisitor();
            visitor.Target = grammarNodeV.getReference();
            visitor.SymbolType = symbolType;

            visitor.visit(nonterminalHeadD);

            return visitor.Item;
        }
        public void visit(NonterminalHeadD nonterminalHeadD)
        {
            representation = new Paragraph();

            if (nonterminalHeadD.IsSelected)
                representation.FontWeight = FontWeights.Bold;

            currentNonterminalHead = nonterminalHeadD;

            // visit rule where representation is done for each choiceLineD
            nonterminalHeadD.Rule.accept(this);
        }
        public bool Analyse()
        {
            try
            {
                if (synA.ProductionRulesHead == null || synA.ProductionRulesHead.Count == 0
                    || synA.ProductionRulesTail == null || synA.ProductionRulesTail.Count == 0)
                {
                    errorMsg = "There are no rules found. Possible empty file / Syntactic Analyser failed?";
                    return false;
                }

                // create nonterminal heads
                foreach (Lexeme nonterminalLexeme in synA.ProductionRulesHead)
                {
                    //if (getNonterminalHead(nonterminalLexeme.Value) == null)
                    //{
                        // create the nont, add to rules
                    // create the nonterminal

                    NonterminalHeadD nontHead = new NonterminalHeadD(nonterminalLexeme.Value);
                    nontHead.Rule = new ChoiceLineD(nontHead);
                    rules.Add(nontHead);
                    // otherwise do nothing now, add to choiceLineD when analysing rules
                }

                // create tree structure for each rule
                for (int i=0; i<synA.ProductionRulesHead.Count; i++)
                {
                    Lexeme nonterminalLexeme = synA.ProductionRulesHead[i];
                    NonterminalHeadD nontTerminalHead = getNonterminalHead(nonterminalLexeme.Value);
                    if (nontTerminalHead == null)
                        throw new Exception("There was an unknown error during the processing of rules");

                    List<Lexeme> productionRuleLexemes = synA.ProductionRulesTail[i] as List<Lexeme>;
                    if (productionRuleLexemes == null)
                        throw new Exception("The given rule " + nontTerminalHead.Name + " has no production rule associated with it.");

                    CreateRuleDataStructure(productionRuleLexemes, nontTerminalHead.Rule);
                    //nontTerminalHead.Rule.appendChild(ruleStructure);
                }

                return true;
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
        }
        public void visit(NonterminalHeadD nonterminalHeadD)
        {
            rulesVisited.Add(nonterminalHeadD);

            if (symbolType == SymbolType.Nonterminal)
            {
                if (nonterminalHeadD.Name.Equals(name))
                {
                    found = true;
                    return;
                }
            }

            // visit rule where representation is done for each choiceLineD
            nonterminalHeadD.Rule.accept(this);
        }
        public void visit(NonterminalHeadD nonterminalHeadD)
        {
            //this is the start of the visit, we create a nonterminalheadV - note one in grammar
            // if this is called again then something has gone wrong
            if (current != null)
                throw new Exception("You should only be calling visit on a NonterminalHeadD node once when creating a visualised grammar. Also use the visitor pattern once, then re-initialize");

            // visit rule
            nonterminalHeadD.Rule.accept(this);
            // current should now be a ChoiceLineV with the rest of the visualised grammar

            NonterminalHeadV startSymbolV = nonterminalHeadD.CreateNonterminalHeadV();

            if (!(current is ChoiceLineV))
                throw new Exception("the current node is not of type ChoiceLineV, is the definitive grammar constructed properly?");

            startSymbolV.Rule = (ChoiceLineV)current;

            current = startSymbolV;
        }
 private void createNonterminalD(Lexeme nonterminalLexeme)
 {
     NonterminalHeadD nont = new NonterminalHeadD(nonterminalLexeme.Value);
     nont.Rule = new ChoiceLineD(nont);
     rules.Add(nont);
 }
        /// <summary>
        /// Creates a new nonterminal and add's it to the defintive grammar. 
        /// It's rule is a simple Nont -> ChoiceLineD -> ConcatD -> Undefined
        /// </summary>
        /// <param name="name"></param>
        public NonterminalHeadD CreateNewNonterminal(String name)
        {
            if (model.DefinitiveGrammar.getNonterminal(name) != null)
                throw new Exception("The given name already exists as a nonterminal, dummy");

            // build nonterminal
            NonterminalHeadD newNonterminal = new NonterminalHeadD(name);
            ChoiceLineD choiceLineD = new ChoiceLineD(newNonterminal);
            newNonterminal.Rule = choiceLineD;

            ChoiceD choiceD = new ChoiceD(choiceLineD);
            newNonterminal.Rule.appendChild(choiceD);

            ConcatenationD concatD = new ConcatenationD(choiceD);
            choiceD.appendChild(concatD);

            concatD.appendChild(new UndefinedD(concatD));

            // add to model
            model.DefinitiveGrammar.Nonterminals.Add(newNonterminal);

            return newNonterminal;
        }
        /// <summary>
        /// Returns the nonterminal head with the name given. Null if not found.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private NonterminalHeadD getNonterminalHead(String name)
        {
            foreach (NonterminalHeadD nonterminalHead in rules)
            {
                if (nonterminalHead.Name.Equals(name))
                    return nonterminalHead;
            }

            // create the nonterminal
            NonterminalHeadD returnVal = new NonterminalHeadD(name);
            returnVal.Rule = new ChoiceLineD(returnVal);
            rules.Add(returnVal);
            synA.ProductionRulesHead.Add(new Lexeme(LexemeType.Nonterminal, name, -1));

            // create the rule tail
            List<Lexeme> newRule = new List<Lexeme>();
            newRule.Add(new Lexeme(LexemeType.Undefined, -1));
            synA.ProductionRulesTail.Add(newRule);

            return returnVal;
        }
 internal void setRule(TerminalV terminalV)
 {
     rule = terminalV.Reference.getMyRule();
 }
 /// <summary>
 /// Creates a new nonterminal head for use in the visuualised grammar, with references to it's nonterminal head D passed.
 /// </summary>
 /// <param name="nonterminalHeadD"></param>
 public NonterminalHeadV(NonterminalHeadD nonterminalHeadD)
 {
     Init(nonterminalHeadD);
 }
 private void Init(NonterminalHeadD nonterminalHeadD)
 {
     reference = nonterminalHeadD;
 }
 internal DefinitiveGrammar(List<NonterminalHeadD> nonterminalsIn, NonterminalHeadD startSymbolIn)
 {
     Init(nonterminalsIn, startSymbolIn);
 }
 internal void setRule(NonterminalTailV nonterminalTailV)
 {
     rule = nonterminalTailV.Reference.getMyRule();
 }
 internal void setStartSymbol(NonterminalHeadD nonterminalHeadD)
 {
     if (nonterminals.Contains(nonterminalHeadD))
         startSymbol = nonterminalHeadD;
     else
         throw new Exception("That start symbol is not in the grammar.");
 }
 internal void setRule(UndefinedV undefinedV)
 {
     rule = undefinedV.Reference.getMyRule();
 }
 private void Init(NonterminalHeadD nonterminalHeadD)
 {
     this.nameTextBox.Text = nonterminalHeadD.Name;
 }
 public void DeleteRule(NonterminalHeadD rule)
 {
     model.DefinitiveGrammar.Nonterminals.Remove(rule);
 }
 public void Rename(NonterminalHeadD nont, string newName)
 {
     nont.Name = newName;
 }
 public Factorisation(SubRule subRuleIn, NonterminalHeadD nontHeadIn)
 {
     subRule = subRuleIn;
     nontHeads = new List<NonterminalHeadD>();
     nontHeads.Add(nontHeadIn);
 }
        void controller_OfferDeleteRule(NonterminalHeadD rule)
        {
            string message = "The rule '" + rule.Name + "' is not used within your grammar any more."
                    + "\nDo you want to remove the rule now?";

            MessageBoxResult result = MessageBox.Show(message, "Rule Deletion Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);

            if (result == MessageBoxResult.Yes)
            {
                model.Functions.DeleteRule(rule);
            }
        }
 public SubRule(List<Lexeme> rulesIn, NonterminalHeadD nontHeadIn)
 {
     Rule = rulesIn;
     NonterminalHeadD = nontHeadIn;
 }
 /// <summary>
 /// Creates a new class that has a reference to a nonterminal head D. For use in the definitive grammar when defining a rule.
 /// </summary>
 /// <param name="nonterminalHeadD"></param>
 public NonterminalTailD(NonterminalHeadD nonterminalHeadD, GrammarNodeD parentIn)
 {
     Init(nonterminalHeadD, parentIn);
 }
 private void Init(List<NonterminalHeadD> nonterminalsIn, NonterminalHeadD startSymbolIn)
 {
     nonterminals = nonterminalsIn;
     startSymbol = startSymbolIn;
 }
 private void Init(NonterminalHeadD nonterminalHeadD, GrammarNodeD parentIn)
 {
     reference = nonterminalHeadD;
     parent = parentIn;
 }
        /// <summary>
        /// Returns all sub rules for a given rule in string representation
        /// </summary>
        /// <param name="nontHead"></param>
        /// <returns></returns>
        private static List<SubRule> SubRules(NonterminalHeadD nontHead)
        {
            // assert that choiceLineD has 1 child and it is of type ChoiceD
            if (nontHead.Rule.Children.Count > 1)
                throw new Exception("The choiceLineD has more than one child, cannot analyse.");

            if (!(nontHead.Rule.Children[0] is ChoiceD))
                throw new Exception("The rule does not have the structure ChoiceLineD -> ChoiceD -> ...");

            List<SubRule> returnVal = new List<SubRule>();

            // get the lexemes from the nonthead rule
            List<Lexeme> totalLexemes = LexemeGenerator.Reverse(nontHead.Rule.Children[0]);
            SubRule totalRule = new SubRule(totalLexemes, nontHead);

            for (int stepSize = 2; stepSize <= totalRule.SymbolCount; stepSize++)
            {
                for (int position = 0; position <= totalRule.SymbolCount - stepSize; position++)
                {
                    List<Lexeme> lexemes = totalRule.getSubRule(position, stepSize);
                    SubRule subRule = new SubRule(lexemes, nontHead);
                    returnVal.Add(subRule);
                }
            }

            return returnVal;
        }
 internal void setRule(NonterminalHeadV nonterminalHeadV)
 {
     rule = nonterminalHeadV.Reference;
 }