コード例 #1
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
 /// <summary>
 /// This level of abstraction of an expression includes logical expressions.
 /// Called everywhere where a logical or normal expression can be expected to be.
 /// </summary>
 void EXP_L()
 {
     EXP_R();
     while (la.kind == 35)           // "and"
     {
         Get();
         QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.and);
         EXP_R();
         try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.and)); }
         catch (Exception e) { SemErr(e.Message); }
     }
 }
コード例 #2
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
 /// <summary>
 /// The highest abstraction level for an expression. This type of expression includes
 /// logical and relational operations.
 /// This function is called everywhere where any type of expression can be expected to be.
 /// </summary>
 void SUPER_EXP()
 {
     EXP_L();
     while (la.kind == 34)           // or
     {
         Get();
         QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.or);
         EXP_L();
         try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.or)); }
         catch (Exception e) { SemErr(e.Message); }
     }
 }
コード例 #3
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
 /// <summary>
 /// This level of abstraction of an expression includes relational expressions.
 /// Called everywhere where a relational or normal expression can be expected to be.
 /// </summary>
 void EXP_R()
 {
     EXP();
     if (StartOf(5))
     {
         OP();
         SemanticCubeUtilities.Operators op = SemanticCubeUtilities.GetOperatorFromString(t.val);
         QuadrupleManager.PushOperator(op);
         EXP();
         try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(op)); }
         catch (Exception e) { SemErr(e.Message); }
     }
 }
コード例 #4
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
 /// <summary>
 /// Calls <see cref="FACTOR"/> and checks whether a multiplication or division is pending and
 /// if the next token is a multiplication or division.
 /// Called by <see cref="EXP"/>.
 /// </summary>
 void TERM()
 {
     FACTOR();
     try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.multiply)); }
     catch (Exception e) { SemErr(e.Message); }
     while (la.kind == 38 || la.kind == 39) // '*' or '/'
     {
         if (la.kind == 38)                 // '*'
         {
             Get();
             QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.multiply);
         }
         else                 // '/'
         {
             Get();
             QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.divide);
         }
         FACTOR();
         try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.multiply)); }
         catch (Exception e) { SemErr(e.Message); }
     }
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
 /// <summary>
 /// Function called when an expression is found.
 /// Checks for pending addition or substraction operations, and checks if the next
 /// token is an addition or substraction.
 /// </summary>
 void EXP()
 {
     TERM();
     try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.plus)); }
     catch (Exception e) { SemErr(e.Message); }
     while (la.kind == 36 || la.kind == 37) // '+' or '-'
     {
         if (la.kind == 36)                 // '+'
         {
             Get();
             QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.plus);
         }
         else                 // '-'
         {
             Get();
             QuadrupleManager.PushOperator(SemanticCubeUtilities.Operators.minus);
         }
         TERM();
         try { QuadrupleManager.PopOperator(SemanticCubeUtilities.OperatorToPriority(SemanticCubeUtilities.Operators.plus)); }
         catch (Exception e) { SemErr(e.Message); }
     }
 }
コード例 #6
0
ファイル: Parser.cs プロジェクト: katiearriagam/Marbles
    /// <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
        }
    }