Esempio n. 1
0
 protected bool checkToken(TokenKind tokKind)
 {
     if (CurrentToken.Kind != tokKind)
     {
         error(CurrentToken, CurrentToken.ToCode() + "不正确,应该是" + Token.GetTextByKind(tokKind));
         return(false);
     }
     else
     {
         return(true);
     }
 }
Esempio n. 2
0
        Stmt ParseAssignOrExprStmt( )
        {
            Exp startExpr = parseExp();

            if (CurrentToken.Kind == TokenKind.Assign)
            {
                return(parseAssign(startExpr));
            }
            else if (CurrentToken.Kind == TokenKind.AssignTo)
            {
                return(parseAssignTo(startExpr));
            }
            else if (CurrentKind == TokenKind.Semi || CurrentKind == TokenKind.EOF || isNewLine())
            {
                return(parseCall(startExpr));
            }
            else
            {
                error("ParseAssignOrExprStmt 无法识别" + CurrentToken.ToCode());
                return(null);
            }
        }
Esempio n. 3
0
        bool matchSemiOrNewLine()
        {
            if (CurrentKind == TokenKind.EOF)
            {
                return(true);
            }
            if (isNewLine())
            {
                return(true);
            }
            TokenKind semi = TokenKind.Semi;

            if (CurrentToken.Kind != semi)
            {
                error(CurrentToken, CurrentToken.ToCode() + "不正确,应该是" + Token.GetTextByKind(semi));
                return(false);
            }
            else
            {
                MoveNext();
                return(true);
            }
        }
Esempio n. 4
0
        protected void report(string str, int color = 1)
        {
            ConsoleColor c = Console.ForegroundColor;

            if (color == 1)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            else if (color == 2)
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }
            else if (color == 3)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else if (color == 4)
            {
                Console.ForegroundColor = ConsoleColor.Blue;
            }
            Console.WriteLine("DEBUG:" + index + " [" + CurrentToken.Line + "," + CurrentToken.Col + "]:" + CurrentToken.ToCode() + " --- " + str);
            Console.ForegroundColor = c;
        }