示例#1
0
        public Node Match(Token_Class ExpectedToken)
        {
            if (InputPointer < TokenStream.Count && ExpectedToken == TokenStream[InputPointer].token_type)
            {
                InputPointer++;
                Node newNode = new Node(ExpectedToken.ToString());

                return(newNode);
            }

            else
            {
                if (InputPointer < TokenStream.Count)
                {
                    Errors.Error_List.Add("Parsing Error: Expected "
                                          + ExpectedToken.ToString() + " and " +
                                          TokenStream[InputPointer].token_type.ToString() +
                                          " found\r\n"
                                          + " at " + InputPointer.ToString() + "\n");

                    InputPointer++;
                }
                else
                {
                    Errors.Error_List.Add("Parsing Error: Expected "
                                          + ExpectedToken.ToString() + " and nothing was found\r\n");
                }

                return(null);
            }
        }
示例#2
0
        public static TDNODE match(Token_Class t)
        {
            TDNODE match = new TDNODE();

            if (i < LT.Count() && LT[i].token_type == t)
            {
                match.token = LT[i];
                bing        = false;
                i++;
            }
            else
            {
                if (i >= LT.Count)
                {
                    string s = "Some essential lines doesn't exist.";
                    ErrorList.Add(s);
                }
                else if (!bing)
                {
                    int j = Scanner.NewLine.Count() - 1;
                    while (!(i <= Scanner.NewLine[j] && i > Scanner.NewLine[j - 1]))
                    {
                        j--;
                    }
                    if (i + 1 < LT.Count && LT[i + 1].token_type == t)
                    {
                        string s = "Extra ";
                        s += LT[i].lex;
                        ErrorList.Add(s);
                        match.token = LT[i + 1];
                        i          += 2;
                    }
                    else if (i == Scanner.NewLine[j - 1] + 1)
                    {
                        string s = "Expected ";
                        s += t.ToString();
                        s += " here.";
                        ErrorList.Add(s);
                        bing = true;
                    }
                    else //if (i + 1 < LT.Count && LT[i + 1].token_type != t)
                    {
                        string s = "Expected ";
                        s += t.ToString();
                        s += " instead of ";
                        s += LT[i].lex;
                        ErrorList.Add(s);
                        i++;
                    }
                }
            }
            return(match);
        }
示例#3
0
        public static Node match(Token_Class ExpectedToken)
        {
            // string temp = Enum.GetName(typeof(Token_Class), ExpectedToken);
            //Node node = new Node(temp);
            Node node = new Node();

            //  if (i < myTokens.Count)
            //{
            if (myTokens[i].token_type == ExpectedToken)
            {
                node.token = myTokens[i];
                i++;
            }
            else if (myTokens[i].token_type == Token_Class.Comment)
            {
                i++;
            }
            else
            {
                Errors.Error_List.Add(" " + "missing" + " ");
                Errors.Error_List.Add(ExpectedToken.ToString());
            }
            //}

            return(node);
        }
示例#4
0
        public Node match(Token_Class ExpectedToken)
        {
            if (ExpectedToken == TokenStream[InputPointer].token_type)
            {
                InputPointer++;
                Node newNode = new Node(ExpectedToken.ToString());

                return(newNode);
            }

            else
            {
                Errors.Error_List.Add(InputPointer + "Parsing Error: Expected "
                                      + ExpectedToken.ToString() + " and " +
                                      TokenStream[InputPointer].token_type.ToString() +
                                      "  found\r\n");
                InputPointer++;
                return(null);
            }
        }