public void visit(ChoiceLineD choiceLineD) { foreach (GrammarNodeD node in choiceLineD.Children) { representation += currentNonterminalHead.Name + ruleOperator; node.accept(this); representation += endOfRuleOperator + choiceLineOperator; } }
public void visit(ChoiceLineD choiceLineD) { if (!found) { foreach (GrammarNodeD node in choiceLineD.Children) node.accept(this); } }
public void visit(ChoiceLineD choiceLineD) { List<GrammarNodeV> children = new List<GrammarNodeV>(); foreach (GrammarNodeD child in choiceLineD.Children) { // make children child.accept(this); children.Add(current); } ChoiceLineV choiceLineV = new ChoiceLineV(children, choiceLineD); choiceLineD.AddReference(choiceLineV); current = choiceLineV; }
/// <summary> /// Returns the rule structure, without the ChoiceLineD /// </summary> /// <param name="productionRuleLexemes"></param> /// <returns></returns> private void CreateRuleDataStructure(List<Lexeme> productionRuleLexemes, ChoiceLineD choiceLineD) { //GrammarNodeD returnVal; OperationD current = choiceLineD; // points to which level we are at //returnVal = current; // Split by Choice as this has the highest precedence List<Lexeme> choiceLexemes = new List<Lexeme>(); ArrayList choices = new ArrayList(); foreach (Lexeme lexeme in productionRuleLexemes) { if (lexeme.Type == LexemeType.Choice) { choices.Add(choiceLexemes); choiceLexemes = new List<Lexeme>(); } else { choiceLexemes.Add(lexeme); } } // add last choice list choices.Add(choiceLexemes); // put in a choiceD ChoiceD choiceD = new ChoiceD(current); current.appendChild(choiceD); current = choiceD; // move down a level // add the concatenated items for each Choice foreach (List<Lexeme> concatLexemes in choices) { ConcatenationD concatenation = new ConcatenationD(current); foreach (Lexeme lexeme in concatLexemes) { if (lexeme.Type == LexemeType.Nonterminal) { // create nonterminal tail from the nonterminalhead NonterminalHeadD nontHead = getNonterminalHead(lexeme.Value); if (nontHead == null) throw new Exception("Could not find a defined rule for the Nonterminal: " + lexeme.Value); NonterminalTailD nontTail = new NonterminalTailD(nontHead, concatenation); // add the tail to current children concatenation.appendChild(nontTail); } else if (lexeme.Type == LexemeType.Terminal) { TerminalD terminalD = new TerminalD(lexeme.Value, concatenation); concatenation.appendChild(terminalD); } else if (lexeme.Type == LexemeType.Undefined) { UndefinedD undefinedD = new UndefinedD(concatenation); concatenation.appendChild(undefinedD); } else if (lexeme.Type != LexemeType.Concatenation) { // Lexes should only be of type Nont, T and Concat. Error throw new Exception("Lexeme was not of type Nonterminal, Terminal or Concatenation"); } } current.appendChild(concatenation); } }
/// <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; }
public void visit(ChoiceLineD choiceLineD) { foreach (GrammarNodeD node in choiceLineD.Children) { representation.Inlines.Add(new Run(currentNonterminalHead.Name + ruleOperator)); node.accept(this); representation.Inlines.Add(new Run(endOfRuleOperator)); } }
private void Init(List<GrammarNodeV> childrenIn, ChoiceLineD refIn) { children = childrenIn; reference = refIn; }
public ChoiceLineV(List<GrammarNodeV> children, ChoiceLineD refIn) { Init(children, refIn); }
public ChoiceLineV(ChoiceLineD refIn) { Init(new List<GrammarNodeV>(), refIn); }