1 int x; 2 int f1() 3 { 4 2*3; 5 12+13; 6 } 7 8 int f2(int i) 9 { 10 int a; 11 12 a=2; 13 14 while(a <5) 15 { 16 a=a+1; 17 printf("a < 5, a: %d\n", a); 18 } 19 3+i; 20 a*i; 21 printf("a*i: %d\n", a*i); 22 } 23 int main() 24 { 25 int z; 26 27 z=6; 28 if (z > 1) 29 { 30 printf("z > 1\n"); 31 } 32 else 33 { 34 printf("z <= 1\n"); 35 } 36 printf("z: %d, 1+2=%d, 5*6 = %d\n", z, 1+2, 5*6); 37 f2(5); 38 }
39 ./c_parser < test_pattern/p3 40 41 \tree( root( prog( var(x |int |global))( f1 |int |func( func_body( *(2)(3))( +(12)(13))))( f2 |int |func( para(i |int))( func_body( var(a |int))( =(a)(2))( while( <(a)(5))( while_block( =(a)( +(a)(1)))( printf(a < 5, a: %d 42 )(a))))( +(3)(i))( *(a)(i))( printf(a*i: %d 43 )( *(a)(i)))))( main |int |func( func_body( var(z |int))( =(z)(6))( if( >(z)(1))( then_block( printf(z > 1 44 )))( else_block( printf(z <= 1 45 ))))( printf(z: %d, 1+2=%d, 5*6 = %d 46 )(z)( +(1)(2))( *(5)(6)))( f2(5))))(main))) 47 op: root 48 can not handle op: f1, ast type: NAME 49 can not handle op: f2, ast type: NAME 50 can not handle op: main, ast type: NAME 51 z > 1 52 z: 6, 1+2=3, 5*6 = 30 53 a < 5, a: 3 54 a < 5, a: 4 55 a < 5, a: 5 56 a*i: 25
沒有留言:
張貼留言