2017-09-18 5 views
-4

私は以下のコードに問題があります。私は無関係のコードを処分しました。ネストされたswitch文

私はコードをデバッグして、スイッチ(e-> u.op.oper)に入ることができないという問題を発見しました。

関数interpExp()には、ネストされたswitch文があります。そこに、私は文字列の出力、"良い"を見ることができます。そこで実行は明らかにそこに行きます。

しかし、私は"wow"出力を見ることができません。
「良い」が印刷されているため、「うわー」も印刷する必要があります。
しかし、私は(u.op.oper E->)は、第2の、ネストされた声明スイッチから を行うべきであると密接以下「すごい」出力を、見ることができません。

typedef struct A_exp_* A_exp; 
typedef enum {A_plus, A_minus, A_times, A_div} A_binop; 

struct IntAndTable interpExp(A_exp e, Table_ t) { 
    Table_ tempT; 
    switch (e->kind) { 
     case A_idExp : 
      return (struct IntAndTable) {lookup(t, e->u.id), t}; 
     case A_numExp : 
      printf("hi\n"); 
      printf("%d\n", e->u.num); 
      return (struct IntAndTable) {e->u.num, t}; 
     case A_opExp : 
      printf("good\n"); 
      switch (e->u.op.oper) { 
       printf("wowowowowow\n"); 
       struct IntAndTable left = interpExp(e->u.op.left, t); 
       struct IntAndTable right = interpExp(e->u.op.right, left.t); 
       case A_plus : 
        return (struct IntAndTable) {left.i + right.i, right.t}; 
       case A_minus : 
        return (struct IntAndTable) {left.i - right.i, right.t}; 
       case A_times : 
        return (struct IntAndTable) {left.i * right.i, right.t}; 
       case A_div : 
        return (struct IntAndTable) {left.i/right.i, right.t}; 
      } 
     case A_eseqExp : 
      tempT = interpStm(e->u.eseq.stm, t); 
      return interpExp(e->u.eseq.exp, tempT); 
    } 
} 


struct A_exp_ { 
    enum {A_idExp, A_numExp, A_opExp, A_eseqExp} kind; 
    union { 
     string id; 
     int num; 
     struct { 
      A_exp left; 
      A_binop oper; 
      A_exp right; 
     } op; 
     struct { 
      A_stm stm; 
      A_exp exp; 
     } eseq; 
    } u; 
}; 
+1

あなたの内側の 'switch'には、目的のprintfの前に' case'がありません。 – Yunnosch

+0

@AnttiHaapala申し訳ありませんが、私はこの質問のタイトルをチェックしていません。今すぐ修正しました。 –

+0

@Yunnosch文の実行コードを大文字と小文字の区別なしに切り替えませんか? –

答えて

2

あなたの内側のswitchbreakが実行されないことを決して前にコードを引き起こし全く希望printfcase、 を持っていません。

彼のコメントでC標準への有用なリンク、
exmple(またはその説明)の中で、あなたのようなコードには "到達できません"と明言されています。