Append() private method

private Append ( char chr ) : void
chr char
return void
Example #1
0
        private bool Directive_EvalFloat()
        {
            double value;
            long   tmp;

            if (Evaluate(out tmp, out value, false) == false)
            {
                return(false);
            }

            idLexer script = _scriptStack.Peek();
            idToken token  = new idToken();

            token.Line = script.LineNumber;
            token.Append(idMath.Abs((float)value).ToString("00"));
            token.Type    = TokenType.Number;
            token.SubType = TokenSubType.Float | TokenSubType.Long | TokenSubType.Decimal;

            UnreadSourceToken(token);

            if (value < 0)
            {
                UnreadSignToken();
            }

            return(true);
        }
Example #2
0
        private bool Directive_Eval()
        {
            long   value;
            double tmp;

            if (Evaluate(out value, out tmp, true) == false)
            {
                return(false);
            }

            idLexer script = _scriptStack.Peek();
            idToken token  = new idToken();

            token.Line = script.LineNumber;
            token.Append(value.ToString());
            token.Type    = TokenType.Number;
            token.SubType = TokenSubType.Integer | TokenSubType.Long | TokenSubType.Decimal;

            UnreadSourceToken(token);

            if (value < 0)
            {
                UnreadSignToken();
            }

            return(true);
        }
Example #3
0
		private bool ReadString(idToken token, char quote)
		{
			char ch;
			int tmpScriptPosition;
			int tmpLine;

			if(quote == '"')
			{
				token.Type = TokenType.String;
			}
			else
			{
				token.Type = TokenType.Literal;
			}

			// leading quote
			_scriptPosition++;

			while(true)
			{
				// if there is an escape character and escape characters are allowed.
				if((GetBufferCharacter(_scriptPosition) == '\\') && ((_options & LexerOptions.NoStringEscapeCharacters) == 0))
				{
					if(ReadEscapeCharacter(out ch) == false)
					{
						return false;
					}

					token.Append(ch);
				}
				// if a trailing quote
				else if(GetBufferCharacter(_scriptPosition) == quote)
				{
					// step over the quote
					_scriptPosition++;

					// if consecutive strings should not be concatenated
					if(((_options & LexerOptions.NoStringConcatination) == LexerOptions.NoStringConcatination) 
						&& (((_options & LexerOptions.AllowBackslashStringConcatination) == 0) || (quote != '"')))
					{
						break;
					}

					tmpScriptPosition = _scriptPosition;
					tmpLine = _line;

					// read white space between possible two consecutive strings
					if(ReadWhiteSpace() == false)
					{
						_scriptPosition = tmpScriptPosition;
						_line = tmpLine;

						break;
					}

					if((_options & LexerOptions.NoStringConcatination) == LexerOptions.NoStringConcatination)
					{
						if(GetBufferCharacter(_scriptPosition) != '\\')
						{
							_scriptPosition = tmpScriptPosition;
							_line = tmpLine;

							break;
						}

						// step over the '\\'
						_scriptPosition++;

						if((ReadWhiteSpace() == false) || (GetBufferCharacter(_scriptPosition) != quote))
						{
							Error("expecting string after '\\' terminated line");
							return false;
						}
					}

					// if there's no leading qoute
					if(GetBufferCharacter(_scriptPosition) != quote)
					{
						_scriptPosition = tmpScriptPosition;
						_line = tmpLine;

						break;
					}

					// step over the new leading quote
					_scriptPosition++;
				}
				else
				{
					if(GetBufferCharacter(_scriptPosition) == '\0')
					{
						Error("missing trailing quote");
						return false;
					}

					if(GetBufferCharacter(_scriptPosition) == '\n')
					{
						Error("newline inside string");
						return false;
					}

					token.Append(GetBufferCharacter(_scriptPosition++));
				}
			}

			if(token.Type == TokenType.Literal)
			{
				if((_options & LexerOptions.AllowMultiCharacterLiterals) == 0)
				{
					if(token.Length != 1)
					{
						Warning("literal is not one character long");
					}
				}

				token.SubType = (TokenSubType) token.ToString()[0];
			}
			else
			{
				// the sub type is the length of the string
				token.SubType = (TokenSubType) token.ToString().Length;
			}

			return true;
		}
Example #4
0
		private bool ReadPunctuation(idToken token)
		{
			int i, l;
			string p;
			LexerPunctuation punc;
			int puncCount = _punctuation.Length;
			int bufferLength = _buffer.Length;
			int puncMarkLength;

			// TODO
			/*#ifdef PUNCTABLE
			for (n = idLexer::punctuationtable[(unsigned int)*(idLexer::script_p)]; n >= 0; n = idLexer::nextpunctuation[n])
			{
				punc = &(idLexer::punctuations[n]);
			#else*/

			for(i = 0; i < puncCount; i++)
			{
				punc = _punctuation[i];

				/*#endif*/

				p = punc.P;
				puncMarkLength = p.Length;

				// check for this punctuation in the script
				for(l = 0; ((l < puncMarkLength) && ((_scriptPosition + l) < bufferLength)); l++)
				{
					if(GetBufferCharacter(_scriptPosition + l) != p[l])
					{
						break;
					}
				}

				if(l >= puncMarkLength)
				{
					for(i = 0; i < l; i++)
					{
						token.Append(p[i]);
					}

					_scriptPosition += l;

					token.Type = TokenType.Punctuation;
					token.SubType = (TokenSubType) punc.N;

					return true;
				}
			}

			return false;
		}
Example #5
0
		private bool ReadNumber(idToken token)
		{
			token.Type = TokenType.Number;
			token.SubType = 0;
			token.SetInteger(0);
			token.SetFloat(0);

			char c = GetBufferCharacter(_scriptPosition);
			char c2 = GetBufferCharacter(_scriptPosition + 1);

			if((c == '0') && (c2 != '.'))
			{
				if((c2 == 'x') || (c2 == 'X'))
				{
					token.Append(GetBufferCharacter(_scriptPosition++));
					token.Append(GetBufferCharacter(_scriptPosition++));

					c = GetBufferCharacter(_scriptPosition);

					while(((c >= 0) && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')))
					{
						token.Append(c);
						c = GetBufferCharacter(++_scriptPosition);
					}

					token.SubType = TokenSubType.Hex | TokenSubType.Integer;
				}
				// check for a binary number
				else if((c2 == 'b') || (c2 == 'B'))
				{
					token.Append(GetBufferCharacter(_scriptPosition++));
					token.Append(GetBufferCharacter(_scriptPosition++));

					c = GetBufferCharacter(_scriptPosition);

					while((c == '0') || (c == '1'))
					{
						token.Append(c);
						c = GetBufferCharacter(++_scriptPosition);
					}

					token.SubType = TokenSubType.Binary | TokenSubType.Integer;
				}
				// its an octal number
				else
				{
					token.Append(GetBufferCharacter(_scriptPosition++));
					c = GetBufferCharacter(_scriptPosition);

					while((c >= '0') && (c <= '7'))
					{
						token.Append(c);
						c = GetBufferCharacter(++_scriptPosition);
					}

					token.SubType = TokenSubType.Octal | TokenSubType.Integer;
				}
			}
			else
			{
				// decimal integer or floating point number or ip address
				int dot = 0;

				while(true)
				{
					if((c >= '0') && (c <= '9'))
					{

					}
					else if(c == '.')
					{
						dot++;
					}
					else
					{
						break;
					}

					token.Append(c);
					c = GetBufferCharacter(++_scriptPosition);
				}

				if((c == 'e') && (dot == 0))
				{
					//We have scientific notation without a decimal point
					dot++;
				}

				// if a floating point number
				if(dot == 1)
				{
					token.SubType = TokenSubType.Decimal | TokenSubType.Float;

					// check for floating point exponent
					if(c == 'e')
					{
						//Append the e so that GetFloatValue code works
						token.Append(c);
						c = GetBufferCharacter(++_scriptPosition);

						if((c == '-') || (c == '+'))
						{
							token.Append(c);
							c = GetBufferCharacter(++_scriptPosition);
						}

						while((c >= '0') || (c <= '9'))
						{
							token.Append(c);
							c = GetBufferCharacter(++_scriptPosition);
						}
					}
					// check for floating point exception infinite 1.#INF or indefinite 1.#IND or NaN
					else if(c == '#')
					{
						c2 = (char) 4;

						if(CheckString("INF") == true)
						{
							token.SubType |= TokenSubType.Infinite;
						}
						else if(CheckString("IND") == true)
						{
							token.SubType |= TokenSubType.Indefinite;
						}
						else if(CheckString("NAN") == true)
						{
							token.SubType |= TokenSubType.NaN;
						}
						else if(CheckString("QNAN") == true)
						{
							token.SubType |= TokenSubType.NaN;
							c2++;
						}

						for(int i = 0; i < c2; i++)
						{
							token.Append(c);
							c = GetBufferCharacter(++_scriptPosition);
						}

						while((c >= '0') && (c <= '9'))
						{
							token.Append(c);
							c = GetBufferCharacter(++_scriptPosition);
						}

						if((_options & LexerOptions.AllowFloatExceptions) == 0)
						{
							Error("parsed {0}", token);
						}
					}
				}
				else if(dot > 1)
				{
					if((_options & LexerOptions.AllowIPAddresses) == 0)
					{
						Error("more than one dot in number");
						return false;
					}

					if(dot != 3)
					{
						Error("ip address should have three dots");

						return false;
					}

					token.SubType = TokenSubType.IPAddress;
				}
				else
				{
					token.SubType = TokenSubType.Decimal | TokenSubType.Integer;
				}
			}

			if((token.SubType & TokenSubType.Float) == TokenSubType.Float)
			{
				if(c > ' ')
				{
					// single-precision: float
					if((c == 'f') || (c == 'F'))
					{
						token.SubType |= TokenSubType.SinglePrecision;
						_scriptPosition++;
					}
					// extended-precision: long double
					else if((c == 'l') || (c == 'L'))
					{
						token.SubType |= TokenSubType.ExtendedPrecision;
						_scriptPosition++;
					}
					// default is double-precision: double
					else
					{
						token.SubType |= TokenSubType.DoublePrecision;
					}
				}
				else
				{
					token.SubType |= TokenSubType.DoublePrecision;
				}
			}
			else if((token.SubType & TokenSubType.Integer) == TokenSubType.Integer)
			{
				if(c > ' ')
				{
					// default: signed long
					for(int i = 0; i < 2; i++)
					{
						// long integer
						if((c == 'l') || (c == 'L'))
						{
							token.SubType |= TokenSubType.Long;
						}
						// unsigned integer
						else if((c == 'u') || (c == 'U'))
						{
							token.SubType |= TokenSubType.Unsigned;
						}
						else
						{
							break;
						}

						c = GetBufferCharacter(++_scriptPosition);

					}
				}
			}
			else if((token.SubType & TokenSubType.IPAddress) == TokenSubType.IPAddress)
			{
				if(c == ':')
				{
					token.Append(c);
					c = GetBufferCharacter(++_scriptPosition);

					while((c >= '0') && (c <= '9'))
					{
						token.Append(c);
						c = GetBufferCharacter(++_scriptPosition);
					}

					token.SubType |= TokenSubType.IPPort;
				}
			}

			return true;
		}
Example #6
0
		private bool ReadName(idToken token)
		{
			char c;
			token.Type = TokenType.Name;

			do
			{
				token.Append(GetBufferCharacter(_scriptPosition++));
				c = GetBufferCharacter(_scriptPosition);
			}
			while(((c >= 'a') && (c <= 'z'))
			|| ((c >= 'A') && (c <= 'Z'))
			|| ((c >= '0') && (c <= '9'))
			|| (c == '_')
				// if treating all tokens as strings, don't parse '-' as a seperate token
			|| (((_options & LexerOptions.OnlyStrings) == LexerOptions.OnlyStrings) && (c == '-'))
				// if special path name characters are allowed
			|| (((_options & LexerOptions.AllowPathNames) == LexerOptions.AllowPathNames) && ((c == '/') || (c == '\\') || (c == ':') || (c == '.'))));

			//the sub type is the length of the name
			token.SubType = (TokenSubType) token.ToString().Length;

			return true;
		}
Example #7
0
		private bool Directive_EvalFloat()
		{
			double value;
			long tmp;

			if(Evaluate(out tmp, out value, false) == false)
			{
				return false;
			}

			idLexer script = _scriptStack.Peek();
			idToken token = new idToken();
			token.Line = script.LineNumber;
			token.Append(idMath.Abs((float) value).ToString("00"));
			token.Type = TokenType.Number;
			token.SubType = TokenSubType.Float | TokenSubType.Long | TokenSubType.Decimal;

			UnreadSourceToken(token);

			if(value < 0)
			{
				UnreadSignToken();
			}

			return true;
		}
Example #8
0
		private bool Directive_Eval()
		{
			long value;
			double tmp;

			if(Evaluate(out value, out tmp, true) == false)
			{
				return false;
			}

			idLexer script = _scriptStack.Peek();
			idToken token = new idToken();
			token.Line = script.LineNumber;
			token.Append(value.ToString());
			token.Type = TokenType.Number;
			token.SubType = TokenSubType.Integer | TokenSubType.Long | TokenSubType.Decimal;

			UnreadSourceToken(token);

			if(value < 0)
			{
				UnreadSignToken();
			}

			return true;
		}