2004-05-03から1日間の記事一覧

gcc - yyparse (original expansion: foreach)

今までの知識を使って C 言語を勝手に拡張してみよう。 foreach ステートメントを導入する。以下のようなコードをコンパイルできるようにしたいわけだ。 /* foreach.c */ int main() { int i; char msg[] = "hello\n"; foreach (i; msg) { printf("%c", msg[…

gcc - yyparse (for_stmt)

前回の stmt は雑に飛ばしたのだが、少しやってみたいことがあるのでもう少し stmt に留まる。今回は for 文。 /* for_stmt.c */ int main() { int i; char msg[] = "hello\n"; for (i = 0; i このダンプでは、 compstmt は二つ出力される。 for 文の中身の…

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 …

gcc - yyparse (declarator)

次は declarator 。型に対して後置される修飾子がこちらに含まれるというのは前に述べた通り。その部分を無視すると、 '(' の後に parmlist_or_identifiers と来ている。 identifiers をいきなり書くのは K&R 記法で、普通は parmlist の方が来るのだろう。…

gcc - yyparse (declspecs_ts)

では declspecs ができるまで追ってみる。 declspecs_ts は declspecs_ts: declspecs_nosc_ts_nosa_noea | declspecs_nosc_ts_nosa_ea | declspecs_nosc_ts_sa_noea | declspecs_nosc_ts_sa_ea | declspecs_sc_ts_nosa_noea | declspecs_sc_ts_nosa_ea | dec…

gcc - yyparse (printf debug with dump-tree)

init は飛ばして(@@@) 字句解析もつまらんから飛ばして (@@@) 、構文解析を見ていこうと思う。(*lang_hooks.parse_file) (set_yydebug); と呼ばれているフックの先は c_common_parse_file のようだ。 pch_init なんてのがあってさすが 3.4 と思った。 c_pars…

まだ挫折していない。ていうかこの部分の gcc のソースコードは無茶苦茶読みやすいし、読んでいて楽しい。誰だ gcc のソースが読めないとかほざいた奴は。間違いなく君だよ。

なにかあれば下記メールアドレスへ。
shinichiro.hamaji _at_ gmail.com
shinichiro.h