Beispiel #1
0
        public static bool Parse(TextReader Reader)
        {
            string right = "";
            string str   = "";

            Grammar.Clear();
            Accepted = false;
            Parser scanner = Scanner;

            scanner.Open(Reader);
            scanner.TrimReductions = false;
            bool flag = false;

            while (!flag)
            {
                short        num;
                short        num2;
                object[]     objArray;
                ParseMessage message = scanner.Parse();
                switch (((int)message))
                {
                case 0:
                    str = Conversions.ToString(scanner.CurrentToken().Data);
                    goto Label_0296;

                case 1:
                {
                    Parser    parser2          = scanner;
                    Reduction currentReduction = (Reduction)parser2.CurrentReduction;
                    parser2.CurrentReduction = currentReduction;
                    scanner.CurrentReduction = RuntimeHelpers.GetObjectValue(CreateNewObject(currentReduction));
                    goto Label_0296;
                }

                case 2:
                    flag = true;
                    goto Label_0296;

                case 3:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "INTERNAL ERROR", "The scanner was unable to be initialized. Please report this bug.", "");
                    flag = true;
                    goto Label_0296;

                case 4:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Lexical Error", "Cannot recognize the token after: " + str, Conversions.ToString(scanner.CurrentPosition().Line));
                    flag = true;
                    goto Label_0296;

                case 5:
                    if (scanner.ExpectedSymbols().Count() < 1)
                    {
                        goto Label_011B;
                    }
                    right = FriendlyTerminalName(scanner.ExpectedSymbols()[0]);
                    num2  = (short)(scanner.ExpectedSymbols().Count() - 1);
                    num   = 1;
                    goto Label_0112;

                case 6:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Runaway Comment", "You have a unterminated block comment.", "");
                    flag = true;
                    goto Label_0296;

                case 7:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "INTERNAL ERROR", "The scanner had an internal error. Please report this bug.", "");
                    flag = true;
                    goto Label_0296;

                default:
                    goto Label_0296;
                }
Label_00EC:
                right = right + ", " + FriendlyTerminalName(scanner.ExpectedSymbols()[num]);
                num   = (short)(num + 1);
Label_0112:
                if (num <= num2)
                {
                    goto Label_00EC;
                }
Label_011B:
                objArray = new object[2];
                Token token = scanner.CurrentToken();
                objArray[0] = RuntimeHelpers.GetObjectValue(token.Data);
                objArray[1] = false;
                object[] arguments = objArray;
                bool[]   copyBack  = new bool[] { true, false };
                if (copyBack[0])
                {
                    token.Data = RuntimeHelpers.GetObjectValue(arguments[0]);
                }
                BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Syntax Error", Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject("Read: ", NewLateBinding.LateGet(null, typeof(BuilderUtility), "DisplayText", arguments, null, null, copyBack)), "\r\n"), "Expecting: "), right)), Conversions.ToString(scanner.CurrentPosition().Line));
                flag = true;
Label_0296:
                Notify.Counter = scanner.CurrentPosition().Line;
            }
            Notify.Counter = scanner.CurrentPosition().Line;
            scanner        = null;
            return(Accepted);
        }
Beispiel #2
0
        private Token ProduceToken()
        {
            bool  flag     = false;
            Token token4   = null;
            Token theToken = null;

            while (!flag)
            {
                bool flag2;
                theToken = this.LookaheadDFA();
                if (theToken.Type() == SymbolType.GroupStart)
                {
                    if (this.m_GroupStack.Count == 0)
                    {
                        flag2 = true;
                    }
                    else
                    {
                        flag2 = this.m_GroupStack.Top().Group().Nesting.Contains(theToken.Group().TableIndex);
                    }
                }
                else
                {
                    flag2 = false;
                }
                if (flag2)
                {
                    this.ConsumeBuffer(Conversions.ToInteger(NewLateBinding.LateGet(theToken.Data, null, "Length", new object[0], null, null, null)));
                    this.m_GroupStack.Push(theToken);
                }
                else if (this.m_GroupStack.Count == 0)
                {
                    this.ConsumeBuffer(Conversions.ToInteger(NewLateBinding.LateGet(theToken.Data, null, "Length", new object[0], null, null, null)));
                    token4 = theToken;
                    flag   = true;
                }
                else
                {
                    Token token6;
                    if (this.m_GroupStack.Top().Group().End == theToken.Parent)
                    {
                        Token token = this.m_GroupStack.Pop();
                        if (token.Group().Ending == EndingMode.Closed)
                        {
                            token6      = token;
                            token6.Data = Operators.ConcatenateObject(token6.Data, theToken.Data);
                            this.ConsumeBuffer(Conversions.ToInteger(NewLateBinding.LateGet(theToken.Data, null, "Length", new object[0], null, null, null)));
                        }
                        if (this.m_GroupStack.Count == 0)
                        {
                            token.Parent = token.Group().Container;
                            token4       = token;
                            flag         = true;
                        }
                        else
                        {
                            token6      = this.m_GroupStack.Top();
                            token6.Data = Operators.ConcatenateObject(token6.Data, token.Data);
                        }
                    }
                    else if (theToken.Type() == SymbolType.End)
                    {
                        token4 = theToken;
                        flag   = true;
                    }
                    else
                    {
                        Token token5 = this.m_GroupStack.Top();
                        if (token5.Group().Advance == AdvanceMode.Token)
                        {
                            token6      = token5;
                            token6.Data = Operators.ConcatenateObject(token6.Data, theToken.Data);
                            this.ConsumeBuffer(Conversions.ToInteger(NewLateBinding.LateGet(theToken.Data, null, "Length", new object[0], null, null, null)));
                        }
                        else
                        {
                            token6      = token5;
                            token6.Data = Operators.ConcatenateObject(token6.Data, NewLateBinding.LateGet(theToken.Data, null, "Chars", new object[] { 0 }, null, null, null));
                            this.ConsumeBuffer(1);
                        }
                    }
                }
            }
            return(token4);
        }
Beispiel #3
0
        // Methods
        private static object CreateNewObject(Reduction TheReduction)
        {
            object    left = null;
            Reduction reduction2;
            int       num2;

            object[]   objArray;
            object[]   objArray2;
            bool[]     flagArray;
            RegExpItem item4;
            RegExpSeq  seq5;
            Reduction  reduction = TheReduction;

            switch (reduction.Parent.TableIndex)
            {
            case 13:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 14:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 15:
            {
                GrammarValueList instance = (GrammarValueList)reduction.get_Data(0);
                objArray    = new object[1];
                reduction2  = reduction;
                num2        = 3;
                objArray[0] = RuntimeHelpers.GetObjectValue(reduction2.get_Data(num2));
                objArray2   = objArray;
                flagArray   = new bool[] { true };
                NewLateBinding.LateCall(instance, null, "Add", objArray2, null, null, flagArray, true);
                if (flagArray[0])
                {
                    reduction2.set_Data(num2, RuntimeHelpers.GetObjectValue(objArray2[0]));
                }
                left = instance;
                break;
            }

            case 0x10:
            {
                GrammarValueList list2 = new GrammarValueList();
                objArray2    = new object[1];
                reduction2   = reduction;
                num2         = 0;
                objArray2[0] = RuntimeHelpers.GetObjectValue(reduction2.get_Data(num2));
                objArray     = objArray2;
                flagArray    = new bool[] { true };
                NewLateBinding.LateCall(list2, null, "Add", objArray, null, null, flagArray, true);
                if (flagArray[0])
                {
                    reduction2.set_Data(num2, RuntimeHelpers.GetObjectValue(objArray[0]));
                }
                left = list2;
                break;
            }

            case 0x11:
                left = Conversions.ToString(reduction.get_Data(0)) + " " + reduction.get_Data(1).ToString();
                break;

            case 0x12:
                left = RuntimeHelpers.GetObjectValue(reduction.get_Data(0));
                break;

            case 0x13:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 20:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 0x15:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 0x16:
            {
                string name = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                Grammar.AddProperty(name, ((GrammarValueList)reduction.get_Data(3)).ToString(), reduction[0].Position.Line);
                break;
            }

            case 0x17:
            {
                GrammarValueList list4 = (GrammarValueList)reduction.get_Data(0);
                GrammarValueList list  = (GrammarValueList)reduction.get_Data(3);
                list4.Add(list);
                left = list4;
                break;
            }

            case 0x18:
                left = RuntimeHelpers.GetObjectValue(reduction.get_Data(0));
                break;

            case 0x19:
            {
                GrammarAttribAssign assign = new GrammarAttribAssign
                {
                    Name   = Conversions.ToString(reduction.get_Data(0)),
                    Values = (GrammarAttribList)reduction.get_Data(4),
                    Line   = reduction[2].Position.Line
                };
                Grammar.AddSymbolAttrib(assign);
                break;
            }

            case 0x1a:
            {
                GrammarAttribAssign assign2 = new GrammarAttribAssign
                {
                    Name   = Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject(reduction.get_Data(0), " "), reduction.get_Data(1))),
                    Values = (GrammarAttribList)reduction.get_Data(5),
                    Line   = reduction[3].Position.Line
                };
                Grammar.AddGroupAttrib(assign2);
                break;
            }

            case 0x1b:
            {
                GrammarAttribList list6 = (GrammarAttribList)reduction.get_Data(0);
                list6.Add((GrammarAttrib)reduction.get_Data(3));
                left = list6;
                break;
            }

            case 0x1c:
            {
                GrammarAttribList list7 = new GrammarAttribList();
                list7.Add((GrammarAttrib)reduction.get_Data(0));
                left = list7;
                break;
            }

            case 0x1d:
            {
                GrammarAttrib attrib = new GrammarAttrib
                {
                    Name = Conversions.ToString(reduction.get_Data(0))
                };
                objArray2    = new object[1];
                reduction2   = reduction;
                num2         = 2;
                objArray2[0] = RuntimeHelpers.GetObjectValue(reduction2.get_Data(num2));
                objArray     = objArray2;
                flagArray    = new bool[] { true };
                NewLateBinding.LateCall(attrib.List, null, "Add", objArray, null, null, flagArray, true);
                if (flagArray[0])
                {
                    reduction2.set_Data(num2, RuntimeHelpers.GetObjectValue(objArray[0]));
                }
                attrib.IsSet = false;
                left         = attrib;
                break;
            }

            case 30:
            {
                GrammarAttrib attrib2 = new GrammarAttrib
                {
                    Name  = Conversions.ToString(reduction.get_Data(0)),
                    List  = (GrammarValueList)reduction.get_Data(3),
                    IsSet = true
                };
                left = attrib2;
                break;
            }

            case 0x1f:
            {
                Grammar.GrammarSet charSet = new Grammar.GrammarSet
                {
                    Name = Conversions.ToString(reduction.get_Data(1)),
                    Exp  = (ISetExpression)reduction.get_Data(5),
                    Line = reduction[0].Position.Line
                };
                Grammar.AddUserSet(charSet);
                break;
            }

            case 0x20:
                left = new SetExp((ISetExpression)reduction.get_Data(0), '+', (ISetExpression)reduction.get_Data(3));
                break;

            case 0x21:
                left = new SetExp((ISetExpression)reduction.get_Data(0), '-', (ISetExpression)reduction.get_Data(3));
                break;

            case 0x22:
                left = RuntimeHelpers.GetObjectValue(reduction.get_Data(0));
                break;

            case 0x23:
            {
                reduction2 = reduction;
                num2       = 0;
                string fullText = Conversions.ToString(reduction2.get_Data(num2));
                Grammar.WarnRegexSetLiteral(fullText, reduction[0].Position.Line);
                reduction2.set_Data(num2, fullText);
                left = new SetItem(new CharacterSetBuild(Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)))));
                break;
            }

            case 0x24:
                Grammar.AddUsedSetName(Conversions.ToString(reduction.get_Data(1)), reduction[0].Position.Line);
                left = new SetItem(SetItem.SetType.Name, Conversions.ToString(reduction.get_Data(1)));
                break;

            case 0x25:
            {
                CharacterSetBuild build = (CharacterSetBuild)reduction.get_Data(1);
                left = new SetItem(build);
                break;
            }

            case 0x26:
                left = Operators.ConcatenateObject(Operators.ConcatenateObject(reduction.get_Data(0), " "), reduction.get_Data(1));
                break;

            case 0x27:
                left = RuntimeHelpers.GetObjectValue(reduction.get_Data(0));
                break;

            case 40:
            {
                CharacterSetBuild build2 = (CharacterSetBuild)reduction.get_Data(0);
                CharacterSetRange range  = (CharacterSetRange)reduction.get_Data(3);
                build2.AddRange(range.First, range.Last);
                left = build2;
                break;
            }

            case 0x29:
            {
                CharacterSetBuild build3 = new CharacterSetBuild();
                CharacterSetRange range2 = (CharacterSetRange)reduction.get_Data(0);
                build3.AddRange(range2.First, range2.Last);
                left = build3;
                break;
            }

            case 0x2a:
                left = new CharacterSetRange(Conversions.ToInteger(reduction.get_Data(0)), Conversions.ToInteger(reduction.get_Data(0)));
                break;

            case 0x2b:
                left = new CharacterSetRange(Conversions.ToInteger(reduction.get_Data(0)), Conversions.ToInteger(reduction.get_Data(2)));
                break;

            case 0x2c:
                left = Grammar.GetHexValue(Conversions.ToString(reduction.get_Data(0)));
                if (Conversions.ToBoolean(Operators.OrObject(Operators.CompareObjectLess(left, 0, false), Operators.CompareObjectGreater(left, 0xffff, false))))
                {
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid set constant value", Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject("The value '", reduction.get_Data(0)), "' is not valid.")), Conversions.ToString(reduction[0].Position.Line));
                }
                break;

            case 0x2d:
                left = Grammar.GetDecValue(Conversions.ToString(reduction.get_Data(0)));
                if (Conversions.ToBoolean(Operators.OrObject(Operators.CompareObjectLess(left, 0, false), Operators.CompareObjectGreater(left, 0xffff, false))))
                {
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid set constant value", Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject("The value '", reduction.get_Data(0)), "' is not valid.")), Conversions.ToString(reduction[0].Position.Line));
                }
                break;

            case 0x2e:
            {
                string str3 = Conversions.ToString(reduction.get_Data(1));
                string str6 = str3.ToUpper();
                if (((str6 == "LINE") || (str6 == "START")) || (str6 == "END"))
                {
                    Grammar.GrammarGroup g = new Grammar.GrammarGroup(Conversions.ToString(reduction.get_Data(0)), Conversions.ToString(reduction.get_Data(1)), Conversions.ToString(reduction.get_Data(4)), reduction[1].Position.Line);
                    Grammar.AddGroup(g);
                }
                else
                {
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid group usage value", "The usage value '" + str3 + "' is not valid. It can be either Start, End or Line.", Conversions.ToString(reduction[1].Position.Line));
                }
                break;
            }

            case 0x2f:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 0x30:
                left = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0)));
                break;

            case 0x31:
            {
                Grammar.GrammarSymbol sym = new Grammar.GrammarSymbol
                {
                    Name = Conversions.ToString(reduction.get_Data(0)),
                    Exp  = (RegExp)reduction.get_Data(3),
                    Line = reduction[2].Position.Line,
                    Type = SymbolType.Content
                };
                Grammar.AddTerminalHead(sym);
                break;
            }

            case 50:
            {
                RegExp    exp = (RegExp)reduction.get_Data(0);
                RegExpSeq seq = (RegExpSeq)reduction.get_Data(3);
                seq.Priority = -1;
                exp.Add(seq);
                left = exp;
                break;
            }

            case 0x33:
            {
                RegExp    exp2 = new RegExp();
                RegExpSeq seq2 = (RegExpSeq)reduction.get_Data(0);
                seq2.Priority = -1;
                exp2.Add(seq2);
                left = exp2;
                break;
            }

            case 0x34:
            {
                RegExpSeq seq3 = (RegExpSeq)reduction.get_Data(0);
                reduction2 = reduction;
                num2       = 1;
                item4      = (RegExpItem)reduction2.get_Data(num2);
                seq3.Add(item4);
                reduction2.set_Data(num2, item4);
                left = seq3;
                break;
            }

            case 0x35:
            {
                RegExpSeq seq4 = new RegExpSeq();
                reduction2 = reduction;
                num2       = 0;
                item4      = (RegExpItem)reduction2.get_Data(num2);
                seq4.Add(item4);
                reduction2.set_Data(num2, item4);
                left = seq4;
                break;
            }

            case 0x36:
            {
                SetItem data = (SetItem)reduction.get_Data(0);
                left = new RegExpItem(data, Conversions.ToString(reduction.get_Data(1)));
                break;
            }

            case 0x37:
            {
                SetItem item2 = new SetItem(SetItem.SetType.Sequence, Grammar.TokenText(Conversions.ToString(reduction.get_Data(0))));
                left = new RegExpItem(item2, Conversions.ToString(reduction.get_Data(1)));
                break;
            }

            case 0x38:
            {
                SetItem item3 = new SetItem(SetItem.SetType.Sequence, Conversions.ToString(reduction.get_Data(0)));
                left = new RegExpItem(item3, Conversions.ToString(reduction.get_Data(1)));
                break;
            }

            case 0x39:
                left = new RegExpItem(RuntimeHelpers.GetObjectValue(reduction.get_Data(1)), Conversions.ToString(reduction.get_Data(3)));
                break;

            case 0x3a:
            {
                RegExp exp3 = (RegExp)reduction.get_Data(0);
                reduction2 = reduction;
                num2       = 2;
                seq5       = (RegExpSeq)reduction2.get_Data(num2);
                exp3.Add(seq5);
                reduction2.set_Data(num2, seq5);
                left = exp3;
                break;
            }

            case 0x3b:
            {
                RegExp exp4 = new RegExp();
                reduction2 = reduction;
                num2       = 0;
                seq5       = (RegExpSeq)reduction2.get_Data(num2);
                exp4.Add(seq5);
                reduction2.set_Data(num2, seq5);
                left = exp4;
                break;
            }

            case 60:
                left = "+";
                break;

            case 0x3d:
                left = "?";
                break;

            case 0x3e:
                left = "*";
                break;

            case 0x3f:
                left = "";
                break;

            case 0x40:
            {
                IEnumerator enumerator;
                Grammar.GrammarProductionList list8   = (Grammar.GrammarProductionList)reduction.get_Data(3);
                Grammar.GrammarSymbol         symbol2 = new Grammar.GrammarSymbol
                {
                    Name = Grammar.TokenText(Conversions.ToString(reduction.get_Data(0))),
                    Type = SymbolType.Nonterminal,
                    Line = reduction[2].Position.Line
                };
                try
                {
                    enumerator = list8.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Grammar.GrammarProduction current = (Grammar.GrammarProduction)enumerator.Current;
                        current.Head = symbol2;
                        Grammar.AddProduction(current);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                break;
            }

            case 0x41:
            {
                Grammar.GrammarProductionList list9 = (Grammar.GrammarProductionList)reduction.get_Data(0);
                Grammar.GrammarProduction     item  = new Grammar.GrammarProduction
                {
                    Handle = (Grammar.GrammarSymbolList)reduction.get_Data(3),
                    Line   = reduction[2].Position.Line
                };
                list9.Add(item);
                left = list9;
                break;
            }

            case 0x42:
            {
                Grammar.GrammarProductionList list10      = new Grammar.GrammarProductionList();
                Grammar.GrammarProduction     production3 = new Grammar.GrammarProduction
                {
                    Handle = (Grammar.GrammarSymbolList)reduction.get_Data(0)
                };
                list10.Add(production3);
                left = list10;
                break;
            }

            case 0x43:
            {
                Grammar.GrammarSymbolList list11 = (Grammar.GrammarSymbolList)reduction.get_Data(0);
                left = list11;
                break;
            }

            case 0x44:
            {
                Grammar.GrammarSymbolList list12 = new Grammar.GrammarSymbolList();
                left = list12;
                break;
            }

            case 0x45:
            {
                Grammar.GrammarSymbolList list13 = (Grammar.GrammarSymbolList)reduction.get_Data(0);
                list13.Add((Grammar.GrammarSymbol)reduction.get_Data(1));
                left = list13;
                break;
            }

            case 70:
            {
                Grammar.GrammarSymbolList list14 = new Grammar.GrammarSymbolList();
                left = list14;
                break;
            }

            case 0x47:
            {
                Grammar.GrammarSymbol symbol3 = new Grammar.GrammarSymbol(Conversions.ToString(reduction.get_Data(0)), SymbolType.Content, reduction[0].Position.Line);
                Grammar.AddHandleSymbol(symbol3);
                left = symbol3;
                break;
            }

            case 0x48:
            {
                Grammar.GrammarSymbol symbol4 = new Grammar.GrammarSymbol(Grammar.TokenText(Conversions.ToString(reduction.get_Data(0))), SymbolType.Nonterminal, reduction[0].Position.Line);
                Grammar.AddHandleSymbol(symbol4);
                left = symbol4;
                break;
            }
            }
            reduction = null;
            return(left);
        }
Beispiel #4
0
 internal bool IsEqualTo(Symbol sym)
 {
     return((Operators.CompareString(m_name.ToUpper(), sym.Name.ToUpper(), true) == 0) & (m_type == sym.Type));
 }