Exemple #1
0
        void IfHeader()
        {
            Expect((int)TokenEnum.If);
            Expect((int)TokenEnum.LeftParenthesis);
            Expression();
            try {
                GraphicFooType type = Quadruple.typeStack.Pop();
                if (Semantics.ExpectType(type, GraphicFooType.Boolean))
                {
                    string id = Quadruple.operandStack.Pop();
                    Quadruple.CreateGotoFalseQuadruple(id);
                    Quadruple.PushJump();
                }
                else
                {
                    SemErr(
                        (int)SemanticEnum.TypeMismatch,
                        "expected boolean, found " + type
                        );
                }
            } catch (InvalidOperationException) {
                SynErr((int)TokenEnum.NoExpression);
            }

            Expect((int)TokenEnum.RightParenthesis);
        }
Exemple #2
0
 void Condition()
 {
     IfHeader();
     while (StartOf((int)TokenEnum.Number))
     {
         Statute();
     }
     if (la.kind == (int)TokenEnum.Else)
     {
         Get();
         Quadruple.PopJump(1);
         Quadruple.CreateGotoQuadruple();
         Quadruple.PushJump();
         while (StartOf((int)TokenEnum.Number))
         {
             Statute();
         }
     }
     EndIf();
 }