Ejemplo n.º 1
0
        public static ITypeDeclaration ParseBasicType(string Code, out DToken OptionalToken)
        {
            OptionalToken = null;

            var p = Create(new StringReader(Code));

            p.Step();
            // Exception: If we haven't got any basic types as our first token, return this token via OptionalToken
            if (!p.IsBasicType() || p.laKind == __LINE__ || p.laKind == __FILE__)
            {
                p.Step();
                p.Peek(1);
                OptionalToken = p.t;

                // Only if a dot follows a 'this' or 'super' token we go on parsing; Return otherwise
                if (!((p.t.Kind == This || p.t.Kind == Super) && p.laKind == Dot))
                {
                    return(null);
                }
            }

            var bt = p.BasicType();

            while (p.IsBasicType2())
            {
                var bt2 = p.BasicType2();
                bt2.InnerMost = bt;
                bt            = bt2;
            }
            return(bt);
        }
Ejemplo n.º 2
0
        DToken Peek(int n)
        {
            Lexer.StartPeek();
            DToken x = la;

            while (n > 0)
            {
                x = Lexer.Peek();
                n--;
            }
            return(x);
        }
Ejemplo n.º 3
0
        public static ITypeDeclaration ParseBasicType(string Code,out DToken OptionalToken)
        {
            OptionalToken = null;

            var p = Create(new StringReader(Code));
            p.Step();
            // Exception: If we haven't got any basic types as our first token, return this token via OptionalToken
            if (!p.IsBasicType() || p.laKind == __LINE__ || p.laKind == __FILE__)
            {
                p.Step();
                p.Peek(1);
                OptionalToken = p.t;

                // Only if a dot follows a 'this' or 'super' token we go on parsing; Return otherwise
                if (!((p.t.Kind == This || p.t.Kind == Super) && p.laKind == Dot))
                    return null;
            }
            
            var bt= p.BasicType();
            while (p.IsBasicType2())
            {
                var bt2 = p.BasicType2();
                bt2.InnerMost = bt;
                bt = bt2;
            }
            return bt;
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Skips to the end of the current code block.
		/// For this, the lexer must have read the next token AFTER the token opening the
		/// block (so that Lexer.DToken is the block-opening token, not Lexer.LookAhead).
		/// After the call, Lexer.LookAhead will be the block-closing token.
		/// </summary>
		public void SkipCurrentBlock()
		{
			int braceCount = 0;
			// Scan already parsed tokens
			var tok = lookaheadToken;
			while (tok != null)
			{
				if (tok.Kind == DTokens.OpenCurlyBrace)
					braceCount++;
				else if (tok.Kind == DTokens.CloseCurlyBrace)
				{
					braceCount--;
					if (braceCount < 0)
					{
						lookaheadToken = tok;
						laKind = tok.Kind;
						return;
					}
				}
				tok = tok.next;
			}

			// Scan/proceed tokens rawly (skip them only until braceCount<0)
			//recyclePrevToken();
			prevToken = LookAhead;
			int nextChar;
			while ((nextChar = ReaderRead()) != -1)
			{
				switch (nextChar)
				{
					// Handle line ends
					case '\r':
					case '\n':
						HandleLineEnd((char)nextChar);
						break;

					// Handle comments
					case '/':
						int peek = ReaderPeek();
						if (peek == '/' || peek == '*' || peek == '+')
						{
							ReadComment();
							continue;
						}
						break;

					// handle string literals
					case 'r':
						int pk = ReaderPeek();
						if (pk == '"')
						{
							ReaderRead();
							ReadVerbatimString('"');
						}
						break;
					case '`':
						ReadVerbatimString(nextChar);
						break;
					case '"':
						ReadString(nextChar);
						break;
					case '\'':
						ReadChar();
						break;

					case '{':
						braceCount++;
						continue;
					case '}':
						braceCount--;
						if (braceCount < 0)
						{
							lookaheadToken = Token(laKind = DTokens.CloseCurlyBrace, Col - 1, Line);
							StartPeek();
							Peek();
							return;
						}
						break;
				}
			}
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Reads the next token and gives it back.
		/// </summary>
		/// <returns>An <see cref="CurrentToken"/> object.</returns>
		public void NextToken()
		{
			if (lookaheadToken == null){
				lookaheadToken = Next();
				laKind = lookaheadToken.Kind;
				Peek();
			}
			else
			{
				recyclePrevToken();
				prevToken = curToken;

				curToken = lookaheadToken;

				if (lookaheadToken.next == null)
					lookaheadToken.next = Next();

				lookaheadToken = lookaheadToken.next;
				laKind = lookaheadToken.Kind;
				StartPeek();
				Peek();
			}
		}
Ejemplo n.º 6
0
		public void RestoreLookAheadBackup()
		{
			prevToken = null;
			curToken = null;
			
			lookaheadToken = laBackup.Pop();
			laKind = lookaheadToken.Kind;
			
			StartPeek();
			Peek();
		}
Ejemplo n.º 7
0
		public void PopLookAheadBackup()
		{
			prevToken = null;
			curToken = null;
			laBackup.Pop();
			/*
			var bk = laBackup.Pop();
			
			if(laBackup.Count == 0)
			{
				while(bk != lookaheadToken)
				{
					var n = bk.next;
					bk.next = null;
					bk.LiteralValue = null;
					tokenPool.Push(bk);
					if((bk = n) == null)
						return;
				}
			}*/
		}
Ejemplo n.º 8
0
		/// <summary>
		/// Gives back the next token. A second call to Peek() gives the next token after the last call for Peek() and so on.
		/// </summary>
		/// <returns>An <see cref="CurrentToken"/> object.</returns>
		public DToken Peek()
		{
			if (peekToken == null) StartPeek();
			if (peekToken.next == null)
				peekToken.next = Next();
			peekToken = peekToken.next;
			return peekToken;
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Must be called before a peek operation.
		/// </summary>
		public void StartPeek()
		{
			peekToken = lookaheadToken;
		}
Ejemplo n.º 10
0
		public void Dispose()
		{
			reader = null;
			prevToken = curToken = lookaheadToken = peekToken = null;
			//sb = originalValue = null;
			escapeSequenceBuffer = null;
			identBuffer = null;
			LexerErrors = null;
			Comments = null;
		}