コード例 #1
0
        private Token ScanBracketsExpression(System.IO.TextReader reader)
        {
            StringBuilder builder = new StringBuilder();
            char          c;

            reader.Read();
            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (c != ']')
                {
                    reader.Read();
                    builder.Append(c);
                }
                else
                {
                    reader.Read();
                    break;
                }
            }

            if (IsUserDefinedResultString(builder))
            {
                return(CreateStringTokenForUdr(builder));
            }

            Token  token;
            string input = builder.ToString();

            if (!complexTokens.TryGetValue(input, out token))
            {
                token = new VariableToken(input);
            }
            return(token);
        }
コード例 #2
0
        private Token ScanGramarToken(System.IO.TextReader reader)
        {
            StringBuilder builder = new StringBuilder();
            char          c;
            Token         tk;

            while (reader.Peek() != -1)
            {
                c = (char)reader.Peek();
                if (char.IsWhiteSpace(c))
                {
                    break;
                }
                else
                {
                    string str = builder.ToString();
                    if (simpleTokens.TryGetValue(c, out tk))
                    {
                        break;
                    }
                    if (complexTokens.TryGetValue(str, out tk))
                    {
                        if (complexTokens.TryGetValue(str + c, out tk))
                        {
                            reader.Read();
                            builder.Append(c);
                        }
                        break;
                    }

                    if (gramar.Contains(c) && str != string.Empty)
                    {
                        if (complexTokens.TryGetValue(str + c, out tk))
                        {
                            reader.Read();
                            builder.Append(c);
                        }
                        break;
                    }
                    reader.Read();
                    builder.Append(c);
                }
            }
            Token  token;
            string input = builder.ToString();

            /*
             *  All unknown letter-only strings default to varaibles.
             */
            if (!complexTokens.TryGetValue(input, out token))
            {
                token = new VariableToken(input);
            }
            return(token);
        }