Exemple #1
0
		private Token ProcessVar(Token segment)
		{
			if (segment != null && segment.SegmentType == TokenType.Variable)
			{
				interpreter.RegisterVariable(segment.Content);
			}
			return segment;
		}
Exemple #2
0
		public Token(TokenCollection tokens)
		{
			if (tokens != null && tokens.Count >= 1)
			{
				Token prev = tokens[tokens.Count - 1];
				prevToken = prev;
				prev.nextToken = this;
			}
		}
Exemple #3
0
		public Token Process(Token segment)
		{
			if (segment != null)
			{
				if (processors.ContainsKey(segment.Content))
				{
					try
					{
						return processors[segment.Content](segment.NextSegment);
					}
					catch (ScriptException error)
					{
						throw error;
					}
				}
				throw new ScriptException("No such keyword ({0}).", segment.Content);
			}
			throw new ScriptException("Keyword cannot be empty.");
		}
Exemple #4
0
		public Token ReadNextToken()
		{
			if (!string.IsNullOrEmpty(rawScript) && index >= 0 && index < rawScript.Length)
			{
				Token rlt = new Token(Tokens);

				for (; index <= rawScript.Length; index++)
				{
					if (cacheIndex < 1)
					{
						cacheIndex++;
					}
					if (index == rawScript.Length)
					{
						cache[cacheIndex] = '\0';
					}
					else
					{
						cache[cacheIndex] = rawScript[index];
						if (cache[0] == '\r' && cache[1] == '\n')
						{
							LineNumber++;
						}
						if (cacheIndex == 1 && index + 1 < rawScript.Length)
						{
							cache[cacheIndex + 1] = rawScript[index + 1];
							cacheIndex++;
							index++;
						}
					}
					if (rlt.Read(cache, index < rawScript.Length))
					{
						if ((cache[1] == '"' && rlt.TokenType == TokenType.String)
							|| (cacheIndex == 2 && (cache[1] == ' ' && rlt.TokenType != TokenType.String && rlt.TokenType != TokenType.Comment))
							|| (rlt.TokenType == TokenType.Comment && "/*".Equals(rlt.StartOpCode)))
						{
							index++;
							cache[0] = cache[1];
							cache[1] = cache[2];
						}
						break;
					}
					if (cacheIndex == 2)
					{
						cache[0] = cache[1];
						cache[1] = cache[2];
					}
				}

				if (Keywords.Contains(rlt.Content))
				{
					rlt.TokenType = TokenType.Keyword;
				}
				else if (rlt.TokenType == TokenType.NewLine)
				{
					rlt.TokenType = TokenType.Ignore;
				}
				AppendToken(rlt);
				return rlt;
			}
			else
			{
				Token rlt = new Token(null);
				if (index == rawScript.Length && cache[1] != '\0')
				{
					cache[2] = '\0';
					rlt.Read(cache, false);
					index++;
					AppendToken(rlt);
					return rlt;
				}
				else
				{
					return null;
				}
			}
		}
Exemple #5
0
		private void AppendToken(Token rlt)
		{
			if (rlt.TokenType != TokenType.Ignore)
			{
				Tokens.Add(rlt);
			}
		}