/// <summary> /// Returns a look-ahead set with all conflicts between /// alternatives in a production pattern. /// </summary> /// <param name="pattern">The production pattern</param> /// <param name="maxLength">The maximum token sequence length</param> /// <returns>A look-ahead set with the conflicts found</returns> /// <exception cref="ParserCreationException"> /// If an inherent ambiguity was found among the look-ahead sets /// </exception> private LookAheadSet FindConflicts( ProductionPattern pattern, int maxLength) { LookAheadSet result = new LookAheadSet(maxLength); LookAheadSet set1; LookAheadSet set2; for (int i = 0; i < pattern.Count; i++) { set1 = pattern[i].LookAhead; for (int j = 0; j < i; j++) { set2 = pattern[j].LookAhead; result.AddAll(set1.CreateIntersection(set2)); } } if (result.IsRepetitive) { this.ThrowAmbiguityException(pattern.Name, null, result); } return(result); }
/// <summary> /// Checks a production pattern for completeness. If some rule /// in the pattern referenced an production pattern not added /// to this parser, a parser creation exception will be thrown. /// </summary> /// <param name="pattern">The production pattern to check</param> /// <exception cref="ParserCreationException"> /// If the pattern referenced a pattern not added to this parser /// </exception> private void CheckPattern(ProductionPattern pattern) { for (int i = 0; i < pattern.Count; i++) { this.CheckAlternative(pattern.Name, pattern[i]); } }
/** * Finds the look-ahead set for a production pattern. The maximum * look-ahead length must be specified. It is also possible to * specify a look-ahead set filter, which will make sure that * unnecessary token sequences will be avoided. * * @param pattern the production pattern * @param length the maximum look-ahead length * @param stack the call stack used for loop detection * @param filter the look-ahead set filter * * @return the look-ahead set for the production pattern * * @throws ParserCreationException if an infinite loop was found * in the grammar */ private LookAheadSet FindLookAhead(ProductionPattern pattern, int length, CallStack stack, LookAheadSet filter) { LookAheadSet result; LookAheadSet temp; // Check for infinite loop if (stack.Contains(pattern.Name, length)) { throw new ParserCreationException( ParserCreationException.ErrorType.INFINITE_LOOP, pattern.Name, (String)null); } // Find pattern look-ahead stack.Push(pattern.Name, length); result = new LookAheadSet(length); for (int i = 0; i < pattern.Count; i++) { temp = FindLookAhead(pattern[i], length, 0, stack, filter); result.AddAll(temp); } stack.Pop(); return(result); }
/** * Checks if the next tokens match a production pattern. The * pattern look-ahead set will be used if existing, otherwise * this method returns false. * * @param pattern the pattern to check * * @return true if the next tokens match, or * false otherwise */ private bool IsNext(ProductionPattern pattern) { LookAheadSet set = pattern.LookAhead; if (set == null) { return(false); } else { return(set.IsNext(this)); } }
/// <summary> /// Returns a string representation of a production pattern. /// </summary> /// <param name="prod">The production pattern</param> /// <returns> /// A detailed string representation of the pattern /// </returns> private string ToString(ProductionPattern prod) { StringBuilder buffer = new StringBuilder(); StringBuilder indent = new StringBuilder(); LookAheadSet set; int i; buffer.Append(prod.Name); buffer.Append(" ("); buffer.Append(prod.Id); buffer.Append(") "); for (i = 0; i < buffer.Length; i++) { indent.Append(" "); } buffer.Append("= "); indent.Append("| "); for (i = 0; i < prod.Count; i++) { if (i > 0) { buffer.Append(indent); } buffer.Append(this.ToString(prod[i])); buffer.Append("\n"); } for (i = 0; i < prod.Count; i++) { set = prod[i].LookAhead; if (set.MaxLength > 1) { buffer.Append("Using "); buffer.Append(set.MaxLength); buffer.Append(" token look-ahead for alternative "); buffer.Append(i + 1); buffer.Append(": "); buffer.Append(set.ToString(this.tokenizer)); buffer.Append("\n"); } } return(buffer.ToString()); }
/** * Parses a production pattern. A parse tree node may or may * not be created depending on the analyzer callbacks. * * @param pattern the production pattern to parse * * @return the parse tree node created, or null * * @throws ParseException if the input couldn't be parsed * correctly */ private Node ParsePattern(ProductionPattern pattern) { ProductionPatternAlternative alt; ProductionPatternAlternative defaultAlt; defaultAlt = pattern.DefaultAlternative; for (int i = 0; i < pattern.Count; i++) { alt = pattern[i]; if (defaultAlt != alt && IsNext(alt)) { return(ParseAlternative(alt)); } } if (defaultAlt == null || !IsNext(defaultAlt)) { ThrowParseException(FindUnion(pattern)); } return(ParseAlternative(defaultAlt)); }
/** * Adds a new production pattern to the parser. The first pattern * added is assumed to be the starting point in the grammar. The * patterns added may be validated to some extent. * * @param pattern the pattern to add * * @throws ParserCreationException if the pattern couldn't be * added correctly to the parser */ public virtual void AddPattern(ProductionPattern pattern) { if (pattern.Count <= 0) { throw new ParserCreationException( ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "no production alternatives are present (must have at " + "least one)"); } if (patternIds.ContainsKey(pattern.Id)) { throw new ParserCreationException( ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "another pattern with the same id (" + pattern.Id + ") has already been added"); } patterns.Add(pattern); patternIds.Add(pattern.Id, pattern); SetInitialized(false); }
/** * Returns the union of all alternative look-ahead sets in a * production pattern. * * @param pattern the production pattern * * @return a unified look-ahead set */ private LookAheadSet FindUnion(ProductionPattern pattern) { LookAheadSet result; int length = 0; int i; for (i = 0; i < pattern.Count; i++) { result = pattern[i].LookAhead; if (result.GetMaxLength() > length) { length = result.GetMaxLength(); } } result = new LookAheadSet(length); for (i = 0; i < pattern.Count; i++) { result.AddAll(pattern[i].LookAhead); } return(result); }
/** * Adds a new production pattern to the parser. The pattern * will be added last in the list. The first pattern added is * assumed to be the starting point in the grammar. The * pattern will be validated against the grammar type to some * extent. * * @param pattern the pattern to add * * @throws ParserCreationException if the pattern couldn't be * added correctly to the parser */ public override void AddPattern(ProductionPattern pattern) { // Check for empty matches if (pattern.IsMatchingEmpty()) { throw new ParserCreationException( ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "zero elements can be matched (minimum is one)"); } // Check for left-recusive patterns if (pattern.IsLeftRecursive()) { throw new ParserCreationException( ParserCreationException.ErrorType.INVALID_PRODUCTION, pattern.Name, "left recursive patterns are not allowed"); } // Add pattern base.AddPattern(pattern); }
/// <summary> /// Adds a new production pattern to the parser. The first pattern /// added is assumed to be the starting point in the grammar. The /// patterns added may be validated to some extent. /// </summary> /// <param name="pattern">The pattern to add</param> /// <exception cref="ParserCreationException"> /// If the pattern couldn't be added correctly to the parser /// </exception> public virtual void AddPattern(ProductionPattern pattern) { if (pattern.Count <= 0) { throw new ParserCreationException( ParserCreationException.ErrorType.InvalidProduction, pattern.Name, "no production alternatives are present (must have at least one)"); } if (this.patternIds.ContainsKey(pattern.Id)) { string msg = "another pattern with the same id (" + pattern.Id + ") has already been added"; throw new ParserCreationException( ParserCreationException.ErrorType.InvalidProduction, pattern.Name, msg); } this.patterns.Add(pattern); this.patternIds.Add(pattern.Id, pattern); this.Initialized = false; }
/** * Checks a production pattern for completeness. If some rule * in the pattern referenced an production pattern not added * to this parser, a parser creation exception will be thrown. * * @param pattern the production pattern to check * * @throws ParserCreationException if the pattern referenced a * pattern not added to this parser */ private void CheckPattern(ProductionPattern pattern) { for (int i = 0; i < pattern.Count; i++) { CheckAlternative(pattern.Name, pattern[i]); } }
/** * Parses a production pattern. A parse tree node may or may * not be created depending on the analyzer callbacks. * * @param pattern the production pattern to parse * * @return the parse tree node created, or null * * @throws ParseException if the input couldn't be parsed * correctly */ private Node ParsePattern(ProductionPattern pattern) { ProductionPatternAlternative alt; ProductionPatternAlternative defaultAlt; defaultAlt = pattern.DefaultAlternative; for (int i = 0; i < pattern.Count; i++) { alt = pattern[i]; if (defaultAlt != alt && IsNext(alt)) { return ParseAlternative(alt); } } if (defaultAlt == null || !IsNext(defaultAlt)) { ThrowParseException(FindUnion(pattern)); } return ParseAlternative(defaultAlt); }
/** * Creates a new production node. * * @param pattern the production pattern */ public Production(ProductionPattern pattern) { this.pattern = pattern; this.Children = new List <Node>(); }
/** * Calculates the look-ahead needed for the specified production * pattern. This method attempts to resolve any conflicts and * stores the results in the pattern look-ahead object. * * @param pattern the production pattern * * @throws ParserCreationException if the look-ahead set couldn't * be determined due to inherent ambiguities */ private void CalculateLookAhead(ProductionPattern pattern) { ProductionPatternAlternative alt; LookAheadSet result; LookAheadSet[] alternatives; LookAheadSet conflicts; LookAheadSet previous = new LookAheadSet(0); int length = 1; int i; CallStack stack = new CallStack(); // Calculate simple look-ahead stack.Push(pattern.Name, 1); result = new LookAheadSet(1); alternatives = new LookAheadSet[pattern.Count]; for (i = 0; i < pattern.Count; i++) { alt = pattern[i]; alternatives[i] = FindLookAhead(alt, 1, 0, stack, null); alt.LookAhead = alternatives[i]; result.AddAll(alternatives[i]); } if (pattern.LookAhead == null) { pattern.LookAhead = result; } conflicts = FindConflicts(pattern, 1); // Resolve conflicts while (conflicts.Size() > 0) { length++; stack.Clear(); stack.Push(pattern.Name, length); conflicts.AddAll(previous); for (i = 0; i < pattern.Count; i++) { alt = pattern[i]; if (alternatives[i].Intersects(conflicts)) { alternatives[i] = FindLookAhead(alt, length, 0, stack, conflicts); alt.LookAhead = alternatives[i]; } if (alternatives[i].Intersects(conflicts)) { if (pattern.DefaultAlternative == null) { pattern.DefaultAlternative = alt; } else if (pattern.DefaultAlternative != alt) { result = alternatives[i].CreateIntersection(conflicts); ThrowAmbiguityException(pattern.Name, null, result); } } } previous = conflicts; conflicts = FindConflicts(pattern, length); } // Resolve conflicts inside rules for (i = 0; i < pattern.Count; i++) { CalculateLookAhead(pattern[i], 0); } }
/** * Returns the union of all alternative look-ahead sets in a * production pattern. * * @param pattern the production pattern * * @return a unified look-ahead set */ private LookAheadSet FindUnion(ProductionPattern pattern) { LookAheadSet result; int length = 0; int i; for (i = 0; i < pattern.Count; i++) { result = pattern[i].LookAhead; if (result.GetMaxLength() > length) { length = result.GetMaxLength(); } } result = new LookAheadSet(length); for (i = 0; i < pattern.Count; i++) { result.AddAll(pattern[i].LookAhead); } return result; }
/** * Changes the production pattern containing this alternative. * This method should only be called by the production pattern * class. * * @param pattern the new production pattern */ internal void SetPattern(ProductionPattern pattern) { this.pattern = pattern; }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) GherkinConstants.FEATURE, "Feature"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TAGS, 0, 1); alt.AddProduction((int) GherkinConstants.FEATURE_HEADER, 1, 1); alt.AddProduction((int) GherkinConstants.BLANK_LINE, 0, -1); alt.AddProduction((int) GherkinConstants.BACKGROUND, 0, 1); alt.AddProduction((int) GherkinConstants.FEATURE_ITEM, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.FEATURE_HEADER, "FeatureHeader"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_FEATURE, 1, 1); alt.AddProduction((int) GherkinConstants.SUMMARY_LINE, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.SUMMARY_LINE, "SummaryLine"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.FREE_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.BACKGROUND, "Background"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.BACKGROUND_HEADER, 1, 1); alt.AddProduction((int) GherkinConstants.STEP, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.BACKGROUND_HEADER, "BackgroundHeader"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_BACKGROUND, 1, 1); alt.AddProduction((int) GherkinConstants.FREE_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.FEATURE_ITEM, "FeatureItem"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TAGS, 0, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_1, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.SCENARIO, "Scenario"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.SCENARIO_HEADER, 1, 1); alt.AddProduction((int) GherkinConstants.STEP, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.SCENARIO_HEADER, "ScenarioHeader"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_SCENARIO, 1, 1); alt.AddProduction((int) GherkinConstants.FREE_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.SCENARIO_OUTLINE, "ScenarioOutline"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.SCENARIO_OUTLINE_HEADER, 1, 1); alt.AddProduction((int) GherkinConstants.STEP, 1, -1); alt.AddProduction((int) GherkinConstants.EXAMPLES, 1, 1); alt.AddProduction((int) GherkinConstants.BLANK_LINE, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.SCENARIO_OUTLINE_HEADER, "ScenarioOutlineHeader"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_SCENARIO_OUTLINE, 1, 1); alt.AddProduction((int) GherkinConstants.FREE_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.EXAMPLES, "Examples"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.EXAMPLES_HEADER, 1, 1); alt.AddProduction((int) GherkinConstants.TABLE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.EXAMPLES_HEADER, "ExamplesHeader"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_EXAMPLES, 1, 1); alt.AddProduction((int) GherkinConstants.FREE_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.STEP, "Step"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.WHITESPACE, 0, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_2, 1, 1); alt.AddProduction((int) GherkinConstants.TEXT, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_3, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.BLANK_LINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TABLE, "Table"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TABLE_ROW, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TABLE_ROW, "TableRow"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.WHITESPACE, 0, 1); alt.AddToken((int) GherkinConstants.PIPE, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_4, 1, -1); alt.AddToken((int) GherkinConstants.EOL, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TABLE_COLUMN, "TableColumn"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TEXT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.WHITESPACE, "Whitespace"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.HORIZONTAL_WHITESPACE, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.FREE_LINE, "FreeLine"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TEXT, 0, 1); alt.AddToken((int) GherkinConstants.EOL, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.BLANK_LINE, "BlankLine"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.EOL, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TEXT, "Text"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.WHITESPACE, 0, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_5, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_6, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TAGS, "Tags"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TAG, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_7, 0, -1); alt.AddToken((int) GherkinConstants.EOL, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GherkinConstants.TAG, "Tag"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.AT, 1, 1); alt.AddToken((int) GherkinConstants.TEXT_CHAR, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_1, "Subproduction1"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.SCENARIO, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.SCENARIO_OUTLINE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_2, "Subproduction2"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_GIVEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_WHEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_THEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_AND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_BUT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_3, "Subproduction3"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.EOL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.COLON, 1, 1); alt.AddToken((int) GherkinConstants.EOL, 1, 1); alt.AddProduction((int) GherkinConstants.TABLE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_4, "Subproduction4"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.TABLE_COLUMN, 1, 1); alt.AddToken((int) GherkinConstants.PIPE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_5, "Subproduction5"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.TEXT_CHAR, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.AT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_FEATURE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_GIVEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_WHEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_THEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_AND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_BUT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_6, "Subproduction6"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.HORIZONTAL_WHITESPACE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.TEXT_CHAR, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.AT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_FEATURE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_BACKGROUND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_SCENARIO, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_SCENARIO_OUTLINE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_EXAMPLES, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_GIVEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_WHEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_THEN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_AND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GherkinConstants.T_BUT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_7, "Subproduction7"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) GherkinConstants.WHITESPACE, 1, 1); alt.AddProduction((int) GherkinConstants.TAG, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Finds the look-ahead set for a production pattern. The maximum * look-ahead length must be specified. It is also possible to * specify a look-ahead set filter, which will make sure that * unnecessary token sequences will be avoided. * * @param pattern the production pattern * @param length the maximum look-ahead length * @param stack the call stack used for loop detection * @param filter the look-ahead set filter * * @return the look-ahead set for the production pattern * * @throws ParserCreationException if an infinite loop was found * in the grammar */ private LookAheadSet FindLookAhead(ProductionPattern pattern, int length, CallStack stack, LookAheadSet filter) { LookAheadSet result; LookAheadSet temp; // Check for infinite loop if (stack.Contains(pattern.Name, length)) { throw new ParserCreationException( ParserCreationException.ErrorType.INFINITE_LOOP, pattern.Name, (String) null); } // Find pattern look-ahead stack.Push(pattern.Name, length); result = new LookAheadSet(length); for (int i = 0; i < pattern.Count; i++) { temp = FindLookAhead(pattern[i], length, 0, stack, filter); result.AddAll(temp); } stack.Pop(); return result; }
/** * Creates a new production node. * * @param pattern the production pattern */ public Production(ProductionPattern pattern) { this.pattern = pattern; this.children = new ArrayList(); }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) DokiScriptConstants.DOKI, "Doki"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.PART, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.PART, "Part"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.BLOCK, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.FLAG, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.OPTION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.JUMP, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.BLOCK, "Block"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.WORLD, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_1, 1, -1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.RETURN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_2, 1, -1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.RETURN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.ACTION, "Action"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TAB, 1, 1); alt.AddProduction((int) DokiScriptConstants.VOICE_ACTION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TAB, 1, 1); alt.AddProduction((int) DokiScriptConstants.OTHER_ACTION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TAB, 1, 1); alt.AddToken((int) DokiScriptConstants.TEXT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.VOICE_ACTION, "VoiceAction"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.VOICE, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_3, 0, -1); alt.AddToken((int) DokiScriptConstants.TEXT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.OTHER_ACTION, "OtherAction"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.TAG, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_4, 0, -1); alt.AddToken((int) DokiScriptConstants.SEMICOLON, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.TAG, "Tag"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.BACKGROUND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.WEATHER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.SOUND, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.BGM, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.VIDEO, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.MOVE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.POSTURE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.ROLE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.OTHER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.KEY, "Key"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.SRC, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TRANSITION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TIME, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TYPE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.LEVEL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.MODE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.POSITION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.NAME, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.ANCHOR, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.TAG_PARAMETER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY1, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY2, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY3, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY4, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY5, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY6, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY7, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY8, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.KEY9, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.LIVE2D, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.ZOOM, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.VALUE, "Value"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.PARENTHESE_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.COMMA, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.COMMA, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_RIGHT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.PARENTHESE_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.COMMA, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_RIGHT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.DECIMAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.QUOTED_TEXT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.FLAG, "Flag"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.SQUARE_BRACKET_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.QUOTED_TEXT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.COMMA, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_RIGHT, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_5, 0, -1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.SQUARE_BRACKET_RIGHT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.RETURN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.OPTION, "Option"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.ANGLE_BRACKET_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.CLICK, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.RETURN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) DokiScriptConstants.JUMP, "Jump"); alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.PARENTHESE_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_RIGHT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.RETURN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_1, "Subproduction1"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.RETURN, 0, 1); alt.AddProduction((int) DokiScriptConstants.ACTION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_2, "Subproduction2"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.RETURN, 0, 1); alt.AddProduction((int) DokiScriptConstants.ACTION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_3, "Subproduction3"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.KEY, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.EQUAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddProduction((int) DokiScriptConstants.VALUE, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_4, "Subproduction4"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) DokiScriptConstants.KEY, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.EQUAL, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddProduction((int) DokiScriptConstants.VALUE, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_5, "Subproduction5"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.OR, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.QUOTED_TEXT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_LEFT, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.COMMA, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.IDENTIFIER, 1, 1); alt.AddToken((int) DokiScriptConstants.SPACE, 0, 1); alt.AddToken((int) DokiScriptConstants.PARENTHESE_RIGHT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Returns a string representation of a production pattern. * * @param prod the production pattern * * @return a detailed string representation of the pattern */ private string ToString(ProductionPattern prod) { StringBuilder buffer = new StringBuilder(); StringBuilder indent = new StringBuilder(); LookAheadSet set; int i; buffer.Append(prod.Name); buffer.Append(" ("); buffer.Append(prod.Id); buffer.Append(") "); for (i = 0; i < buffer.Length; i++) { indent.Append(" "); } buffer.Append("= "); indent.Append("| "); for (i = 0; i < prod.Count; i++) { if (i > 0) { buffer.Append(indent); } buffer.Append(ToString(prod[i])); buffer.Append("\n"); } for (i = 0; i < prod.Count; i++) { set = prod[i].LookAhead; if (set.GetMaxLength() > 1) { buffer.Append("Using "); buffer.Append(set.GetMaxLength()); buffer.Append(" token look-ahead for alternative "); buffer.Append(i + 1); buffer.Append(": "); buffer.Append(set.ToString(tokenizer)); buffer.Append("\n"); } } return buffer.ToString(); }
/** * Factory method to create a new production node. This method * can be overridden to provide other production implementations * than the default one. * * @param pattern the production pattern * * @return the new production node * * @since 1.5 */ protected virtual Production NewProduction(ProductionPattern pattern) { return analyzer.NewProduction(pattern); }
/** * Checks if the next tokens match a production pattern. The * pattern look-ahead set will be used if existing, otherwise * this method returns false. * * @param pattern the pattern to check * * @return true if the next tokens match, or * false otherwise */ private bool IsNext(ProductionPattern pattern) { LookAheadSet set = pattern.LookAhead; if (set == null) { return false; } else { return set.IsNext(this); } }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) LogicalConstants.FORMULE, "FORMULE"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.NOT, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.FORALL, 1, 1); alt.AddToken((int) LogicalConstants.VAR, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EXISTS, 1, 1); alt.AddToken((int) LogicalConstants.VAR, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) LogicalConstants.PREDICAT, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE_PRED, 0, -1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE_BIN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.FORMULE_PRED, "FORMULE_PRED"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AND, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.OR, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.IMPLY, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.FORMULE_BIN, "FORMULE_BIN"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AND, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.OR, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.IMPLY, 1, 1); alt.AddProduction((int) LogicalConstants.FORMULE, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.ATOM, "ATOM"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.CSTE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.VAR, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.PREDICAT, "PREDICAT"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) LogicalConstants.PRED1, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) LogicalConstants.PRED2, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) LogicalConstants.PRED3, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.PRED1, "PRED1"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.ROSE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.PAQUERETTE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.TULIPE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_GRAND, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_MOYEN, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_PETIT, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_ROUGE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_ROSE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_BLANC, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.A_L_EST, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.A_L_OUEST, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AU_SUD, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AU_NORD, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.PRED2, "PRED2"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.A_L_EST_DE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.A_L_OUEST_DE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AU_SUD_DE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.AU_NORD_DE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.MEME_LONGITUDE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.MEME_LATITUDE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.PLUS_GRAND_QUE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.PLUS_PETIT_QUE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.MEME_TAILLE_QUE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.MEME_COULEUR_QUE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EGAL, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) LogicalConstants.PRED3, "PRED3"); alt = new ProductionPatternAlternative(); alt.AddToken((int) LogicalConstants.EST_ENTRE, 1, 1); alt.AddToken((int) LogicalConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.COMMA, 1, 1); alt.AddProduction((int) LogicalConstants.ATOM, 1, 1); alt.AddToken((int) LogicalConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Returns a look-ahead set with all conflics between * alternatives in a production pattern. * * @param pattern the production pattern * @param maxLength the maximum token sequence length * * @return a look-ahead set with the conflicts found * * @throws ParserCreationException if an inherent ambiguity was * found among the look-ahead sets */ private LookAheadSet FindConflicts(ProductionPattern pattern, int maxLength) { LookAheadSet result = new LookAheadSet(maxLength); LookAheadSet set1; LookAheadSet set2; for (int i = 0; i < pattern.Count; i++) { set1 = pattern[i].LookAhead; for (int j = 0; j < i; j++) { set2 = pattern[j].LookAhead; result.AddAll(set1.CreateIntersection(set2)); } } if (result.IsRepetitive()) { ThrowAmbiguityException(pattern.Name, null, result); } return result; }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) CommandGrammarConstants.COMMANDS, "Commands"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) CommandGrammarConstants.COMMAND, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_1, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) CommandGrammarConstants.COMMAND, "Command"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) CommandGrammarConstants.EXPRESSION, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) CommandGrammarConstants.EXPRESSION, "Expression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) CommandGrammarConstants.TEXT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) CommandGrammarConstants.STRING, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) CommandGrammarConstants.PARAMETER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) CommandGrammarConstants.COMMAND_START, 1, 1); alt.AddProduction((int) CommandGrammarConstants.COMMAND, 1, 1); alt.AddToken((int) CommandGrammarConstants.COMMAND_END, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_1, "Subproduction1"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) CommandGrammarConstants.COMMAND_SEPARATOR, 1, 1); alt.AddProduction((int) CommandGrammarConstants.COMMAND, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Factory method to create a new production node. This method * can be overridden to provide other production implementations * than the default one. * * @param pattern the production pattern * * @return the new production node * * @since 1.5 */ public virtual Production NewProduction(ProductionPattern pattern) { return new Production(pattern); }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) PicoConstants.PROGRAM, "Program"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.SEPARATOR, 0, 1); alt.AddProduction((int) PicoConstants.SYMBOLS, 1, 1); alt.AddProduction((int) PicoConstants.ORIGIN, 1, 1); alt.AddProduction((int) PicoConstants.LINES, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.SEPARATOR, "Separator"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.ENTER, 1, 1); alt.AddToken((int) PicoConstants.ENTER, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.SYMBOLS, "Symbols"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.SYMBOL, 1, 1); alt.AddProduction((int) PicoConstants.SYMBOL, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.SYMBOL, "Symbol"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.IDENTIFIER, 1, 1); alt.AddToken((int) PicoConstants.EQUALS, 1, 1); alt.AddProduction((int) PicoConstants.INTEGER, 1, 1); alt.AddProduction((int) PicoConstants.SEPARATOR, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.INTEGER, "Integer"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.SIGN, 0, 1); alt.AddToken((int) PicoConstants.NUMBER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ORIGIN, "Origin"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.ORG, 1, 1); alt.AddToken((int) PicoConstants.NUMBER, 1, 1); alt.AddProduction((int) PicoConstants.SEPARATOR, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.LINES, "Lines"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.LINE, 1, 1); alt.AddProduction((int) PicoConstants.LINE, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.LINE, "Line"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_1, 0, 1); alt.AddProduction((int) PicoConstants.INSTRUCTION, 1, 1); alt.AddProduction((int) PicoConstants.SEPARATOR, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.INSTRUCTION, "Instruction"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.MOVE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARITHMETIC, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.BRANCH, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.IO, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.CALL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.RETURN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.END, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.MOVE, "Move"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.MOV, 1, 1); alt.AddProduction((int) PicoConstants.MOVE_ARGS, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARITHMETIC, "Arithmetic"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_2, 1, 1); alt.AddProduction((int) PicoConstants.ARITHMETIC_ARGS, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.BRANCH, "Branch"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_3, 1, 1); alt.AddProduction((int) PicoConstants.BRANCH_ARGS, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.IO, "IO"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_4, 1, 1); alt.AddProduction((int) PicoConstants.IOARGS, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.CALL, "Call"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.JSR, 1, 1); alt.AddProduction((int) PicoConstants.ARG3, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.RETURN, "Return"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.RTS, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.END, "End"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.STOP, 1, 1); alt.AddProduction((int) PicoConstants.END_ARGS, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.MOVE_ARGS, "MoveArgs"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_5, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARITHMETIC_ARGS, "ArithmeticArgs"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_6, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.BRANCH_ARGS, "BranchArgs"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_8, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.IOARGS, "IOArgs"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_9, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.END_ARGS, "EndArgs"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_11, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG12, "Arg12"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG2, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG34, "Arg34"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG3, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG4, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG123, "Arg123"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG2, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG3, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG1234, "Arg1234"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG2, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG3, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG4, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG1, "Arg1"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.INTEGER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG2, "Arg2"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.HASH, 1, 1); alt.AddToken((int) PicoConstants.IDENTIFIER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG3, "Arg3"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.IDENTIFIER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) PicoConstants.ARG4, "Arg4"); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.LEFT_PAREN, 1, 1); alt.AddToken((int) PicoConstants.IDENTIFIER, 1, 1); alt.AddToken((int) PicoConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_1, "Subproduction1"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.IDENTIFIER, 1, 1); alt.AddToken((int) PicoConstants.COLON, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_2, "Subproduction2"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.ADD, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.SUB, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.MUL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.DIV, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_3, "Subproduction3"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.BEQ, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.BGT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_4, "Subproduction4"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.IN, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.OUT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_5, "Subproduction5"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1234, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG123, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_6, "Subproduction6"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG1234, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG12, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_7, "Subproduction7"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_8, "Subproduction8"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_7, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) PicoConstants.ARG1, 1, 1); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_9, "Subproduction9"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG1234, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_10, "Subproduction10"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_11, "Subproduction11"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) PicoConstants.COMMA, 1, 1); alt.AddProduction((int) PicoConstants.ARG34, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_10, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Factory method to create a new production node. This method * can be overridden to provide other production implementations * than the default one. * * @param pattern the production pattern * * @return the new production node * * @since 1.5 */ public virtual Production NewProduction(ProductionPattern pattern) { return(new Production(pattern)); }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) IrfConstants.IRF_DOCUMENT, "IrfDocument"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) IrfConstants.ROOT_NODE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.ROOT_NODE, "RootNode"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.LT, 1, 1); alt.AddToken((int) IrfConstants.PLAYER_NOTES, 1, 1); alt.AddProduction((int) IrfConstants.USER_NODE, 0, 1); alt.AddToken((int) IrfConstants.GT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.USER_NODE, "UserNode"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.LT, 1, 1); alt.AddToken((int) IrfConstants.PLAYER_NOTE_SET, 1, 1); alt.AddToken((int) IrfConstants.USER_NAME, 1, 1); alt.AddProduction((int) IrfConstants.PLAYER_NOTE_NODE, 1, -1); alt.AddToken((int) IrfConstants.GT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.PLAYER_NOTE_NODE, "PlayerNoteNode"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.LT, 1, 1); alt.AddToken((int) IrfConstants.PLAYER_NOTE, 1, 1); alt.AddProduction((int) IrfConstants.PLAYER_NAME_ATTRIBUTE, 1, 1); alt.AddProduction((int) IrfConstants.NOTE_TEXT_ATTRIBUTE, 0, 1); alt.AddProduction((int) IrfConstants.TIMESTAMP_ATTRIBUTE, 0, 1); alt.AddProduction((int) IrfConstants.CLASSIFICATION_ATTRIBUTE, 0, 1); alt.AddToken((int) IrfConstants.GT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.PLAYER_NAME_ATTRIBUTE, "PlayerNameAttribute"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.PLAYER_NAME, 1, 1); alt.AddToken((int) IrfConstants.EQUAL, 1, 1); alt.AddToken((int) IrfConstants.QUOTED_STRING, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.NOTE_TEXT_ATTRIBUTE, "NoteTextAttribute"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.NOTE_TEXT, 1, 1); alt.AddToken((int) IrfConstants.EQUAL, 1, 1); alt.AddToken((int) IrfConstants.QUOTED_STRING, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.TIMESTAMP_ATTRIBUTE, "TimestampAttribute"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.TIMESTAMP, 1, 1); alt.AddToken((int) IrfConstants.EQUAL, 1, 1); alt.AddToken((int) IrfConstants.QUOTED_STRING, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) IrfConstants.CLASSIFICATION_ATTRIBUTE, "ClassificationAttribute"); alt = new ProductionPatternAlternative(); alt.AddToken((int) IrfConstants.CLASSIFICATION, 1, 1); alt.AddToken((int) IrfConstants.EQUAL, 1, 1); alt.AddToken((int) IrfConstants.QUOTED_STRING, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) ExpressionConstants.EXPRESSION, "Expression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.XOR_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.XOR_EXPRESSION, "XorExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.OR_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_1, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.OR_EXPRESSION, "OrExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.AND_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_2, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.AND_EXPRESSION, "AndExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.NOT_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_3, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.NOT_EXPRESSION, "NotExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.NOT, 0, 1); alt.AddProduction((int) ExpressionConstants.IN_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.IN_EXPRESSION, "InExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.COMPARE_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_4, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.IN_TARGET_EXPRESSION, "InTargetExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.FIELD_PROPERTY_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.IN_LIST_TARGET_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.IN_LIST_TARGET_EXPRESSION, "InListTargetExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) ExpressionConstants.ARGUMENT_LIST, 1, 1); alt.AddToken((int) ExpressionConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.COMPARE_EXPRESSION, "CompareExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.SHIFT_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_6, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.SHIFT_EXPRESSION, "ShiftExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.ADDITIVE_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_8, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.ADDITIVE_EXPRESSION, "AdditiveExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.MULTIPLICATIVE_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_10, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.MULTIPLICATIVE_EXPRESSION, "MultiplicativeExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.POWER_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_12, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.POWER_EXPRESSION, "PowerExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.NEGATE_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_13, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.NEGATE_EXPRESSION, "NegateExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.SUB, 0, 1); alt.AddProduction((int) ExpressionConstants.MEMBER_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.MEMBER_EXPRESSION, "MemberExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.BASIC_EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_14, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.MEMBER_ACCESS_EXPRESSION, "MemberAccessExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.DOT, 1, 1); alt.AddProduction((int) ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.BASIC_EXPRESSION, "BasicExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.LITERAL_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.EXPRESSION_GROUP, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.SPECIAL_FUNCTION_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.MEMBER_FUNCTION_EXPRESSION, "MemberFunctionExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.FIELD_PROPERTY_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.FUNCTION_CALL_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.FIELD_PROPERTY_EXPRESSION, "FieldPropertyExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.IDENTIFIER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.SPECIAL_FUNCTION_EXPRESSION, "SpecialFunctionExpression"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.IF_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.CAST_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.IF_EXPRESSION, "IfExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.IF, 1, 1); alt.AddToken((int) ExpressionConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.CAST_EXPRESSION, "CastExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.CAST, 1, 1); alt.AddToken((int) ExpressionConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1); alt.AddProduction((int) ExpressionConstants.CAST_TYPE_EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.CAST_TYPE_EXPRESSION, "CastTypeExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.IDENTIFIER, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_15, 0, -1); alt.AddToken((int) ExpressionConstants.ARRAY_BRACES, 0, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.INDEX_EXPRESSION, "IndexExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LEFT_BRACE, 1, 1); alt.AddProduction((int) ExpressionConstants.ARGUMENT_LIST, 1, 1); alt.AddToken((int) ExpressionConstants.RIGHT_BRACE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.FUNCTION_CALL_EXPRESSION, "FunctionCallExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.IDENTIFIER, 1, 1); alt.AddToken((int) ExpressionConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) ExpressionConstants.ARGUMENT_LIST, 0, 1); alt.AddToken((int) ExpressionConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.ARGUMENT_LIST, "ArgumentList"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_16, 0, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.LITERAL_EXPRESSION, "LiteralExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.INTEGER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.REAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.STRING_LITERAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.BOOLEAN_LITERAL_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.HEX_LITERAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.CHAR_LITERAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.NULL_LITERAL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.DATETIME, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.TIMESPAN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.BOOLEAN_LITERAL_EXPRESSION, "BooleanLiteralExpression"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.TRUE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.FALSE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) ExpressionConstants.EXPRESSION_GROUP, "ExpressionGroup"); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LEFT_PAREN, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); alt.AddToken((int) ExpressionConstants.RIGHT_PAREN, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_1, "Subproduction1"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.XOR, 1, 1); alt.AddProduction((int) ExpressionConstants.OR_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_2, "Subproduction2"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.OR, 1, 1); alt.AddProduction((int) ExpressionConstants.AND_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_3, "Subproduction3"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.AND, 1, 1); alt.AddProduction((int) ExpressionConstants.NOT_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_4, "Subproduction4"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.IN, 1, 1); alt.AddProduction((int) ExpressionConstants.IN_TARGET_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_5, "Subproduction5"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.EQ, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.GT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.GTE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LTE, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.NE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_6, "Subproduction6"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_5, 1, 1); alt.AddProduction((int) ExpressionConstants.SHIFT_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_7, "Subproduction7"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.LEFT_SHIFT, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.RIGHT_SHIFT, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_8, "Subproduction8"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_7, 1, 1); alt.AddProduction((int) ExpressionConstants.ADDITIVE_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_9, "Subproduction9"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.ADD, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.SUB, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_10, "Subproduction10"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_9, 1, 1); alt.AddProduction((int) ExpressionConstants.MULTIPLICATIVE_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_11, "Subproduction11"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.MUL, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.DIV, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.MOD, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_12, "Subproduction12"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) SynteticPatterns.SUBPRODUCTION_11, 1, 1); alt.AddProduction((int) ExpressionConstants.POWER_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_13, "Subproduction13"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.POWER, 1, 1); alt.AddProduction((int) ExpressionConstants.NEGATE_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_14, "Subproduction14"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.MEMBER_ACCESS_EXPRESSION, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddProduction((int) ExpressionConstants.INDEX_EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_15, "Subproduction15"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.DOT, 1, 1); alt.AddToken((int) ExpressionConstants.IDENTIFIER, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) SynteticPatterns.SUBPRODUCTION_16, "Subproduction16"); pattern.Synthetic = true; alt = new ProductionPatternAlternative(); alt.AddToken((int) ExpressionConstants.ARGUMENT_SEPARATOR, 1, 1); alt.AddProduction((int) ExpressionConstants.EXPRESSION, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/// <summary> /// Factory method to create a new production node. This method /// can be overridden to provide other production implementations /// than the default one. /// </summary> /// <param name="pattern">The production pattern</param> /// <returns>The new production node</returns> protected virtual Production NewProduction(ProductionPattern pattern) { return(this.analyzer.NewProduction(pattern)); }
/** * <summary>Initializes the parser by creating all the production * patterns.</summary> * * <exception cref='ParserCreationException'>if the parser * couldn't be initialized correctly</exception> */ private void CreatePatterns() { ProductionPattern pattern; ProductionPatternAlternative alt; pattern = new ProductionPattern((int) GrammarConstants.DOCUMENT, "DOCUMENT"); alt = new ProductionPatternAlternative(); alt.AddProduction((int) GrammarConstants.TEXT, 1, -1); pattern.AddAlternative(alt); AddPattern(pattern); pattern = new ProductionPattern((int) GrammarConstants.TEXT, "TEXT"); alt = new ProductionPatternAlternative(); alt.AddToken((int) GrammarConstants.EVERYTHING, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GrammarConstants.CHARACTER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GrammarConstants.NUMBER, 1, 1); pattern.AddAlternative(alt); alt = new ProductionPatternAlternative(); alt.AddToken((int) GrammarConstants.WHITESPACE, 1, 1); pattern.AddAlternative(alt); AddPattern(pattern); }
/** * Creates a new production node. * * @param pattern the production pattern */ public Production(ProductionPattern pattern) { pattern = pattern; children = new ArrayList(); }