Пример #1
0
    /// <summary>
    /// This is the lowest level of abstraction for an expression. Checks which is the
    /// factor being used as an expression, retrieves this information, and calls the
    /// necessesary functions in <see cref="QuadrupleManager"/> that handles each case
    /// individually.
    /// Called by <see cref="TERM"/>.
    /// </summary>
    void FACTOR()
    {
        if (la.kind == 10)           // '('
        // push a fake bottom
        {
            QuadrupleManager.PushFakeBottom();
            Get();
            SUPER_EXP();
            Expect(12);             // ')'
            // exit fake bottom
            QuadrupleManager.PopFakeBottom();
        }
        else if (StartOf(6))
        {
            if (la.kind == 37)               // negative sign
            {
                Get();
                QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.negative);
            }

            if (la.kind == 4)               // number constant
            {
                Get();
                try { QuadrupleManager.ReadConstantNumber(Int32.Parse(t.val)); }
                catch (Exception e) { SemErr(e.Message); }
            }
            else if (la.kind == 1)     // id
            {
                Get();
                string id = t.val;
                if (la.kind == 22) // '.' character
                {
                    try
                    {
                        QuadrupleManager.ReadAssetId(id);
                        Get();
                        ATTRIBUTE();                         // we don't need to verify the attribute as the UI forces the user to select a valid one
                    }
                    catch (Exception e) { SemErr(e.Message); }
                }
                else
                {
                    try { QuadrupleManager.ReadIDVariable(id); }
                    catch (Exception e) { SemErr(e.Message); }
                }
            }
            else if (la.kind == 19)                 // "call"
            {
                CALL_TO_FUNCTION();
            }
            else if (la.kind == 2 || la.kind == 3)                 // true or false
            {
                BOOL();
            }
            else if (la.kind == 5)                 // string constant
            {
                Get();
                try { QuadrupleManager.ReadConstantText(t.val); }
                catch (Exception e) { SemErr(e.Message); }
            }
            else
            {
                SynErr(60);                // invalid FACTOR
            }
            try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.negative)); }
            catch (Exception e) { SemErr(e.Message); }
        }
        else
        {
            SynErr(61);          // invalid FACTOR
        }
    }