示例#1
0
 private static bool character_literal()
 {
     if (Tokens.GetToken().type == Token.Type.Character)
     {
         string   value = Tokens.GetToken().lexeme.Replace("\'", "");
         string[] data  = new string[2];
         data[0] = "returnType:char";
         data[1] = "accessMod:public";
         Symbol symbol = new Symbol("g", ("H" + value.Trim()), "CHAR_" + value, "c**t", data);
         SymbolTable.Add(symbol);
         if (semanticPass)
         {
             SemanticActions.lPush(symbol, Tokens.GetToken(), scope);
         }
         return(true);
     }
     return(false);
 }
示例#2
0
 private static bool numeric_literal()
 {
     if (Tokens.GetToken().lexeme == "+" || Tokens.GetToken().lexeme == "-")
     {
         if (Tokens.PeekToken().type != Token.Type.Number)
         {
             return(false);
         }
         string sign = Tokens.GetToken().lexeme;
         if (sign == "+")
         {
             sign = "";
         }
         Tokens.NextToken();
         string[] data = new string[2];
         data[0] = "returnType:int";
         data[1] = "accessMod:public";
         Symbol symbol = new Symbol("g", ("N" + sign + Tokens.GetToken().lexeme), (sign + Tokens.GetToken().lexeme), "ilit", data);
         SymbolTable.Add(symbol);
         if (semanticPass)
         {
             SemanticActions.lPush(symbol, Tokens.GetToken(), scope);
         }
     }
     else if (Tokens.GetToken().type == Token.Type.Number)
     {
         string[] data = new string[2];
         data[0] = "returnType:int";
         data[1] = "accessMod:public";
         Symbol symbol = new Symbol("g", ("N" + Tokens.GetToken().lexeme), Tokens.GetToken().lexeme, "ilit", data);
         SymbolTable.Add(symbol);
         if (semanticPass)
         {
             SemanticActions.lPush(symbol, Tokens.GetToken(), scope);
         }
     }
     else
     {
         return(false);
     }
     return(true);
 }
示例#3
0
        private static bool Expression()
        {
            string lexeme = Tokens.GetToken().lexeme;

            if (lexeme == "(")
            {
                if (semanticPass)
                {
                    SemanticActions.oPush(Tokens.GetToken());
                }
                Tokens.NextToken();
                if (!Expression())
                {
                    SyntaxError(Tokens.GetToken(), "expression");
                }
                if (Tokens.GetToken().lexeme != ")")
                {
                    SyntaxError(Tokens.GetToken(), ")");
                }
                if (semanticPass)
                {
                    SemanticActions.ShuntYardAll();
                }
                Tokens.NextToken();
                Expressionz();
                return(true);
            }
            else if (lexeme == "+" || lexeme == "-" || lexeme == "true" || lexeme == "false" ||
                     lexeme == "null" || lexeme == "this" || Tokens.GetToken().type == Token.Type.Number ||
                     Tokens.GetToken().type == Token.Type.Character)
            {
                if (Tokens.GetToken().lexeme == "this")
                {
                    if (semanticPass)
                    {
                        SemanticActions.iPush(Tokens.GetToken(), scope);
                        SemanticActions.iExist();
                    }
                    Tokens.NextToken();
                    Member_Refz();
                    Expressionz();
                    return(true);
                }
                else if (lexeme == "true" || lexeme == "false" || lexeme == "null")
                {
                    string[] data = new string[2];
                    data[0] = "returnType:bool";
                    data[1] = "accessMod:public";
                    Symbol symbol;
                    if (lexeme == "true")
                    {
                        symbol = new Symbol("g", ("Btrue"), "1", "blit", data);
                    }
                    else if (lexeme == "false")
                    {
                        symbol = new Symbol("g", ("Bfalse"), "0", "blit", data);
                    }
                    else
                    {
                        data[0] = "returnType:null";
                        symbol  = new Symbol("g", "null", "2018", "null", data);
                    }
                    SymbolTable.Add(symbol);
                    if (semanticPass)
                    {
                        SemanticActions.lPush(symbol, Tokens.GetToken(), scope);
                    }
                    Tokens.NextToken();
                    Expressionz();
                    return(true);
                }
                else if (numeric_literal())
                {
                    Tokens.NextToken();
                    Expressionz();
                    return(true);
                }
                else if (character_literal())
                {
                    Tokens.NextToken();
                    Expressionz();
                    return(true);
                }
                return(false);
            }
            else if (Tokens.GetToken().type == Token.Type.Identifier)
            {
                currentIdentifier = Tokens.GetToken().lexeme;
                if (semanticPass)
                {
                    SemanticActions.iPush(Tokens.GetToken(), scope);
                }
                Tokens.NextToken();
                Fn_Arr_Member();
                if (semanticPass)
                {
                    SemanticActions.iExist();
                }
                Member_Refz();
                Expressionz();
                return(true);
            }
            return(false);
        }