gcc - yyparse (compstmt)
さて、これもいきなりダンプから。少し飽きてきた感もある。
/* stmt.c */ int main() { char msg[] = "hello\n"; printf(msg); return 0; }
やっと hello world が出てくるわけ。さて compstmt のダンプは、
compstmt = @1 compound_stmt line: 2 next: @2 @2 scope_stmt line: 3 begn clnp next: @3 @3 decl_stmt line: 3 decl: @4 next: @5 @4 var_decl name: @6 type: @7 scpe: @8 srcp: stmt.c:3 chan: @9 init: @10 size: @11 algn: 8 used: 1 @5 expr_stmt line: 4 expr: @12 next: @13 @6 identifier_node strg: msg lngt: 3 @7 array_type size: @11 algn: 8 elts: @14 domn: @15 @8 function_decl name: @16 type: @17 scpe: @18 srcp: stmt.c:2 extern body: @19 @9 function_decl name: @20 type: @21 scpe: @18 srcp::0 undefined extern @10 string_cst type: @22 strg: hello lngt: 7 @11 integer_cst type: @23 low : 56 @12 call_expr type: @24 fn : @25 args: @26 @13 return_stmt line: 5 expr: @27 next: @28 @14 integer_type name: @29 size: @30 algn: 8 prec: 8 min : @31 max : @32 @15 integer_type size: @33 algn: 32 prec: 32 min : @34 max : @35 @16 identifier_node strg: main lngt: 4 @17 function_type unql: @36 size: @37 algn: 64 retn: @24 @18 translation_unit_decl srcp: :0 @19 expr_stmt line: 0 expr: @38 next: @1 @20 identifier_node strg: printf lngt: 6 @21 function_type size: @37 algn: 64 retn: @24 prms: @39 @22 array_type size: @11 algn: 8 elts: @14 domn: @15 @23 integer_type name: @40 size: @37 algn: 64 prec: 36 unsigned min : @41 max : @42 @24 integer_type name: @43 size: @33 algn: 32 prec: 32 min : @44 max : @45 @25 addr_expr type: @46 op 0: @9 @26 tree_list valu: @47 @27 modify_expr type: @24 op 0: @48 op 1: @49 @28 scope_stmt line: 6 end clnp
ステートメントは next で接続するようだ。 @1 => @2 => @3 => @5 => @13 => @28 と接続されている。 @1 は全体の親ノード、 @2 でスコープ開始 ('{' に対応)、 @3 は char msg[] 、 @5 は printf 、 @13 は return 、 @28 はスコープ終了。
そしてその stmt 達にぶらさがっているノードはだいたい予想通りなものだ。たぶん適切なセッタで適切に代入されているのだろう。 declarator でそれなりに詳細に処理を追っかけたわけだしその詳細はとりあえず追っかけないことにする (@@@)。