Esempio n. 1
0
        internal static bool IsDefined(this IPreprocessorCLogicalOrConditionExp expression, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors)
        {
            if (expression.Left == null && expression.Right.Left == null && expression.Right.Right.Rule == 3 && expression.Right.Right.PreCPrimary.Rule == 4)
            {
                string name = expression.Right.Right.PreCPrimary.Identifier.Name;
                if (argumentLookup.ContainsParameter(name))
                {
                    IProductionRuleTemplatePart iprtp = argumentLookup.GetParameter(name);
                    if (iprtp.SpecialExpectancy == TemplatePartExpectedSpecial.Rule)
                    {
                        IProductionRuleSeries iprs = argumentLookup[name];
                        if (iprs.Count == 1 && iprs[0].Count == 1)
                        {
                            IProductionRuleItem ipri = iprs[0][0];
                            if (ipri != null)
                            {
                                if (ipri is IRuleReferenceProductionRuleItem)
                                {
                                    name = ((IRuleReferenceProductionRuleItem)(ipri)).Reference.Name;
                                }
                                else if (ipri is ISoftReferenceProductionRuleItem)
                                {
                                    //No guarantee that just being a soft-reference guarantees
                                    //lack of definition.

                                    //Reason: if another template defines this later,
                                    //it exists, but hasn't been resolved. -- It will be later in the expansion/resolution phase.
                                    name = ((ISoftReferenceProductionRuleItem)(ipri)).PrimaryName;
                                }
                            }
                        }
                    }
                    else
                    {
                        errors.SourceError(OilexerGrammarCore.CompilerErrors.IsDefinedTemplateParameterMustExpectRule, new LineColumnPair(expression.Line, expression.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), name);
                    }
                }
                foreach (IOilexerGrammarEntry ientry in file.ToArray())
                {
                    if (ientry is IOilexerGrammarProductionRuleEntry && (!(ientry is IOilexerGrammarProductionRuleTemplateEntry)))
                    {
                        if (((IOilexerGrammarProductionRuleEntry)ientry).Name == name)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            errors.SourceError(OilexerGrammarCore.CompilerErrors.InvalidDefinedTarget, new LineColumnPair(expression.Line, expression.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), expression.ToString());
            return(false);
        }
Esempio n. 2
0
 public IProductionRuleSeries this[IProductionRuleTemplatePart part]
 {
     get
     {
         if (this.Lookup == null)
         {
             throw new InvalidOperationException("Object not in a valid state to perform this action.");
         }
         if (this.Lookup.ContainsKey(part))
         {
             return(this.Lookup[part].Replacement);
         }
         throw new ArgumentOutOfRangeException("name");
     }
 }
Esempio n. 3
0
        internal static void Expand(this IPreprocessorAddRuleDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors)
        {
            string search = directive.InsertTarget;

            if (search != null && search != string.Empty)
            {
                OilexerGrammarProductionRuleEntry foundItem = null;
                if (argumentLookup.ContainsParameter(search))
                {
                    IProductionRuleTemplatePart part = argumentLookup.GetParameter(search);
                    IProductionRuleSeries       iprs = argumentLookup[part];
                    if (iprs.Count == 1 && iprs[0].Count == 1)
                    {
                        IProductionRuleItem ipri = iprs[0][0];
                        if (ipri is ISoftReferenceProductionRuleItem)
                        {
                            ISoftReferenceProductionRuleItem n = (ISoftReferenceProductionRuleItem)ipri;
                            search = n.PrimaryName;
                        }
                        else if (ipri is IRuleReferenceProductionRuleItem)
                        {
                            foundItem = (OilexerGrammarProductionRuleEntry)((IRuleReferenceProductionRuleItem)(ipri)).Reference;
                        }
                    }
                }
                if (foundItem == null)
                {
                    foreach (IOilexerGrammarEntry ie in file)
                    {
                        if (ie is OilexerGrammarProductionRuleEntry && ((OilexerGrammarProductionRuleEntry)ie).Name == search)
                        {
                            foundItem = ie as OilexerGrammarProductionRuleEntry;
                            break;
                        }
                    }
                }
                if (foundItem == null)
                {
                    errors.SourceError(OilexerGrammarCore.CompilerErrors.UndefinedAddRuleTarget, new LineColumnPair(directive.Line, directive.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), string.Join <IProductionRule>(" | ", directive.Rules), search);
                    return;
                }
                foreach (IProductionRule ipr in directive.Rules)
                {
                    foundItem.Add(ipr.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors));
                }
            }
        }
Esempio n. 4
0
        internal static void Expand(this IPreprocessorDefineRuleDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors)
        {
            string search = directive.DeclareTarget;

            if (search != null && search != string.Empty)
            {
                if (argumentLookup.ContainsParameter(search))
                {
                    IProductionRuleTemplatePart part = argumentLookup.GetParameter(search);
                    IProductionRuleSeries       iprs = argumentLookup[part];
                    if (iprs.Count == 1 && iprs[0].Count == 1)
                    {
                        IProductionRuleItem ipri = iprs[0][0];
                        if (ipri is ISoftReferenceProductionRuleItem)
                        {
                            ISoftReferenceProductionRuleItem n = (ISoftReferenceProductionRuleItem)ipri;
                            search = n.PrimaryName;
                        }
                    }
                }
                /* ToDo: Evaluate the depth necessary to institute a lock associated to the base list on the oilexer grammar file type. */
                IOilexerGrammarEntry[] fileElements;
                lock (file)
                    fileElements = file.ToArray();
                foreach (IOilexerGrammarEntry ie in fileElements)
                {
                    if (ie is IOilexerGrammarNamedEntry && ((IOilexerGrammarNamedEntry)ie).Name == search)
                    {
                        errors.SourceError(OilexerGrammarCore.CompilerErrors.DuplicateTermDefined, new LineColumnPair(directive.Line, directive.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), search);
                        return;
                    }
                }
                OilexerGrammarProductionRuleEntry insertedItem = new OilexerGrammarProductionRuleEntry(search, entry.ScanMode, entry.FileName, directive.Column, directive.Line, directive.Position);
                lock (file)
                    file.Add(insertedItem);
                foreach (IProductionRule ipr in directive.DefinedRules)
                {
                    IProductionRule expanded = ipr.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors);
                    insertedItem.Add(expanded);
                }
            }
        }
Esempio n. 5
0
 protected override void DefineRuleTemplateParameterIdentifier(OilexerGrammarTokens.IdentifierToken id, IProductionRuleTemplatePart currentPart)
 {
     this.Handler.ReclassifyToken(id, currentPart);
 }
 internal void ReclassifyToken(OilexerGrammarTokens.IdentifierToken identifierToken, IProductionRuleTemplatePart item)
 {
     if (reclassifications.ContainsKey(identifierToken))
     {
         return;
     }
     reclassifications.Add(identifierToken, OilexerGrammarTokenType.RuleTemplateParameterReference);
 }
 public void ResolvedSinglePartToTemplateParameter(IOilexerGrammarProductionRuleTemplateEntry entry, IProductionRuleTemplatePart iprtp, ISoftReferenceProductionRuleItem item)
 {
     if (item.PrimaryToken != null)
     {
         this.handler.ReclassifyToken(item.PrimaryToken, iprtp);
     }
 }
Esempio n. 8
0
 internal ArgumentData(IProductionRuleTemplatePart relative, IProductionRuleSeries replacement)
 {
     this.Relative    = relative;
     this.Replacement = replacement;
 }
Esempio n. 9
0
 /// <summary>
 /// Creates a new <see cref="TemplateParamReferenceProductionRuleItem"/> with the
 /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>.
 /// </summary>
 /// <param name="column">The column on <paramref name="line"/> at which the <see cref="TemplateParamReferenceProductionRuleItem"/> was
 /// defined.</param>
 /// <param name="line">The line at which the <see cref="TemplateParamReferenceProductionRuleItem"/> was defined.</param>
 /// <param name="position">The byte in the file at which the <see cref="TemplateParamReferenceProductionRuleItem"/> was declared.</param>
 public TemplateParamReferenceProductionRuleItem(IOilexerGrammarProductionRuleTemplateEntry source, IProductionRuleTemplatePart reference, int column, int line, long position)
     : base(column, line, position)
 {
     this.source    = source;
     this.reference = reference;
 }
Esempio n. 10
0
        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);
        }