public static SyntacticalNFAState BuildNFA <T, TLiteral>(this ILiteralReferenceProductionRuleItem <T, TLiteral> item, IGrammarSymbolSet symbols, ControlledDictionary <IOilexerGrammarProductionRuleEntry, SyntacticalDFARootState> lookup, Dictionary <IProductionRuleSource, IProductionRuleCaptureStructuralItem> replacements) where TLiteral : ILiteralTokenItem <T> { SyntacticalNFAState state = new SyntacticalNFAState(lookup, (GrammarSymbolSet)symbols); GrammarVocabulary movement = new GrammarVocabulary(symbols, symbols[item.Literal]); var stateEnd = new SyntacticalNFAState(lookup, (GrammarSymbolSet)symbols); state.MoveTo(movement, stateEnd); return(state); }
public static bool AllSourcesAreSameIdentity(this IEnumerable <IProductionRuleSource> sources) { var firstSource = sources.First(); if (firstSource is ILiteralReferenceProductionRuleItem) { ILiteralReferenceProductionRuleItem sourceItem = (ILiteralReferenceProductionRuleItem)(firstSource); return(sources.Skip(1).All(s => s is ILiteralReferenceProductionRuleItem && ((ILiteralReferenceProductionRuleItem)s).Literal == sourceItem.Literal)); } else { Debug.Assert(false, "Unknown entity type for flag item."); } return(false); }
internal static object Evaluate(this IPreprocessorCEqualityExp expression, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { IOilexerGrammarTokenEntry lookup; ILiteralTokenItem reference = null; //Hack #1. if (expression.Rule == 1 || expression.Rule == 2) { string name = null; //If the left side is a parameter reference and the right side //is an identifier... if (expression.PreCEqualityExp.Rule == 3 && expression.PreCPrimary.Rule == 4 && expression.PreCEqualityExp.PreCPrimary.Rule == 4 && argumentLookup.ContainsParameter(name = expression.PreCEqualityExp.PreCPrimary.Identifier.Name)) { //Obtain the parameter IProductionRuleTemplatePart part = argumentLookup.GetParameter(name); if (part.SpecialExpectancy == TemplatePartExpectedSpecial.None && part.ExpectedSpecific != null) { //If the specific expectency is a production rule reference... if (part.ExpectedSpecific is ITokenReferenceProductionRuleItem) { //Lookup the expectency. ILiteralTokenItem secondHalf = null; lookup = ((ITokenReferenceProductionRuleItem)(part.ExpectedSpecific)).Reference; //Lookup the right-hand requirement for the condition. ITokenItem sRef = lookup.FindTokenItem(expression.PreCPrimary.Identifier.Name); if (sRef is ILiteralTokenItem) { reference = ((ILiteralTokenItem)(sRef)); } else { goto notValidReference; } //Obtain the expression series for the left-hand side. IProductionRuleSeries series = argumentLookup[part]; //If it's a single unit. if (series.Count == 1 && series[0].Count == 1) { //If it's a soft-reference item... IProductionRuleItem e = series[0][0]; if (e is ISoftReferenceProductionRuleItem) { ISoftReferenceProductionRuleItem sre = ((ISoftReferenceProductionRuleItem)e); if (((sre.SecondaryName == null || sre.SecondaryName == string.Empty)) && sre.PrimaryName != null) { secondHalf = (ILiteralTokenItem)lookup.FindTokenItemByValue(sre.PrimaryName, file, true); } } //If they used the fully qualified name... else if (e is ILiteralReferenceProductionRuleItem) { ILiteralReferenceProductionRuleItem lr = ((ILiteralReferenceProductionRuleItem)e); //So much easier... secondHalf = lr.Literal; } if (expression.Rule == 1) { return(secondHalf == reference); } else if (expression.Rule == 2) { return(secondHalf != reference); } } } } } else if (expression.PreCEqualityExp.Rule == 3 && expression.PreCPrimary.Rule == 5 && expression.PreCEqualityExp.PreCPrimary.Rule == 4 && expression.PreCEqualityExp.PreCPrimary.Identifier.Name.ToLower() == "index") { if (expression.Rule == 1) { return(expression.PreCPrimary.Number.GetCleanValue() == argumentLookup.Index); } else if (expression.Rule == 2) { return(expression.PreCPrimary.Number.GetCleanValue() != argumentLookup.Index); } } } notValidReference: switch (expression.Rule) { case 1: //PreprocessorCEqualityExp "==" PreprocessorCPrimary return(expression.PreCEqualityExp.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors) == expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors)); case 2: //PreprocessorCEqualityExp "!=" PreprocessorCPrimary return(expression.PreCEqualityExp.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors) != expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors)); case 3: //PreprocessorCPrimary return(expression.PreCPrimary.Evaluate(currentEntry, availableStock, argumentLookup, entry, file, errors)); } return(false); }