C++
http://github.com/kik/cpppeg に置いた。 http://wiki.github.com/kik/cpppeg/usage 説明はここ。 まだ色々と不完全
今回のターゲット文法は epxr ::= int_lit | '(' op expr expr ')' int_lit ::= token(int_lit_s) op ::= token(op_s) int_lit_s ::= digit digit* op ::= alpha alpha* token(T) ::= T ' '*token(T)はジェネリックなルールであり、Tに対してTの後ろの空白文…
再帰下降パーザを書くだけなら誰でもできることなのだが、本当に一日中悩んでやっと低機能なものが動くようになった。 最終的にはPEGをサポートしたいところである。たとえば <hoge> ::= alpha alpha digit <foo> <foo> ::= digitなんて文法があったら #include <iostream> #include "p</iostream></foo></foo></hoge>…
struct X { typedef int Y; }; struct Y { struct Z { X foo(); }; }; struct Z { X::Y foo(); }; X::Y::Z::foo() { return 0; } これだと、最後の関数定義は X::Y (::Z::foo)();を定義してるのね
struct X { struct Y { struct Z { }; }; }; struct Y { struct Z { X foo(); }; }; struct Z { X::Y foo(); }; X::Y::Z foo(); X::Y::Z::foo() { return 0; } 最後の関数定義はいったいどの関数を定義しているのだろう…。C++の仕様書の生成規則だと X::Y::Z…
#include <stdio.h> int main() { enum E { E_A, E_B}; int x = 10; printf("%d, %d, %d, %d, %d, %d\n", E_A, E_B, 10, (E)10, x, (E)x); } 結果 $ g++ --version g++ (GCC) 3.4.1 Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see th</stdio.h>…