Example #1
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);
        }