なかだです。

parse.yを-Wallでコンパイルしたら結構いろいろ警告が出たので確認
したところ、

* yylex: nextc() は入力の終りで0ではなく-1を返すはず

* new_evstr: なんかメチャクチャ(^^;。

というバグが見付かりました。

あと、intern.hにあるyyparse()のプロトタイプ宣言は、ここでは
ruby_yyparse()じゃないと意味がないようです。

keywordsのstruct kwtableのidの初期化は、{}つけるとコンパイルで
きないような処理系ってありましたっけ。


Index: intern.h =================================================================== RCS file: /cvs/ruby/src/ruby/intern.h,v retrieving revision 1.96 diff -u -2 -p -r1.96 intern.h --- intern.h 5 Sep 2002 20:00:52 -0000 1.96 +++ intern.h 22 Sep 2002 17:56:10 -0000 @@ -288,5 +288,5 @@ double rb_str_to_dbl _((VALUE, int)); EXTERN int ruby_sourceline; EXTERN char *ruby_sourcefile; -int yyparse _((void)); +int ruby_yyparse _((void)); ID rb_id_attrset _((ID)); void rb_parser_append_print _((void)); Index: keywords =================================================================== RCS file: /cvs/ruby/src/ruby/keywords,v retrieving revision 1.5 diff -u -2 -p -r1.5 keywords --- keywords 20 Aug 2001 04:29:56 -0000 1.5 +++ keywords 22 Sep 2002 17:56:42 -0000 @@ -1,42 +1,42 @@ struct kwtable {char *name; int id[2]; enum lex_state state;}; %% -__LINE__, k__LINE__, k__LINE__, EXPR_END -__FILE__, k__FILE__, k__FILE__, EXPR_END -BEGIN, klBEGIN, klBEGIN, EXPR_END -END, klEND, klEND, EXPR_END -alias, kALIAS, kALIAS, EXPR_FNAME -and, kAND, kAND, EXPR_BEG -begin, kBEGIN, kBEGIN, EXPR_BEG -break, kBREAK, kBREAK, EXPR_MID -case, kCASE, kCASE, EXPR_BEG -class, kCLASS, kCLASS, EXPR_CLASS -def, kDEF, kDEF, EXPR_FNAME -defined?, kDEFINED, kDEFINED, EXPR_ARG -do, kDO, kDO, EXPR_BEG -else, kELSE, kELSE, EXPR_BEG -elsif, kELSIF, kELSIF, EXPR_BEG -end, kEND, kEND, EXPR_END -ensure, kENSURE, kENSURE, EXPR_BEG -false, kFALSE, kFALSE, EXPR_END -for, kFOR, kFOR, EXPR_BEG -if, kIF, kIF_MOD, EXPR_BEG -in, kIN, kIN, EXPR_BEG -module, kMODULE, kMODULE, EXPR_BEG -next, kNEXT, kNEXT, EXPR_MID -nil, kNIL, kNIL, EXPR_END -not, kNOT, kNOT, EXPR_BEG -or, kOR, kOR, EXPR_BEG -redo, kREDO, kREDO, EXPR_END -rescue, kRESCUE, kRESCUE_MOD, EXPR_MID -retry, kRETRY, kRETRY, EXPR_END -return, kRETURN, kRETURN, EXPR_MID -self, kSELF, kSELF, EXPR_END -super, kSUPER, kSUPER, EXPR_ARG -then, kTHEN, kTHEN, EXPR_BEG -true, kTRUE, kTRUE, EXPR_END -undef, kUNDEF, kUNDEF, EXPR_FNAME -unless, kUNLESS, kUNLESS_MOD, EXPR_BEG -until, kUNTIL, kUNTIL_MOD, EXPR_BEG -when, kWHEN, kWHEN, EXPR_BEG -while, kWHILE, kWHILE_MOD, EXPR_BEG -yield, kYIELD, kYIELD, EXPR_ARG +__LINE__, {k__LINE__, k__LINE__}, EXPR_END +__FILE__, {k__FILE__, k__FILE__}, EXPR_END +BEGIN, {klBEGIN, klBEGIN}, EXPR_END +END, {klEND, klEND}, EXPR_END +alias, {kALIAS, kALIAS}, EXPR_FNAME +and, {kAND, kAND}, EXPR_BEG +begin, {kBEGIN, kBEGIN}, EXPR_BEG +break, {kBREAK, kBREAK}, EXPR_MID +case, {kCASE, kCASE}, EXPR_BEG +class, {kCLASS, kCLASS}, EXPR_CLASS +def, {kDEF, kDEF}, EXPR_FNAME +defined?, {kDEFINED, kDEFINED}, EXPR_ARG +do, {kDO, kDO}, EXPR_BEG +else, {kELSE, kELSE}, EXPR_BEG +elsif, {kELSIF, kELSIF}, EXPR_BEG +end, {kEND, kEND}, EXPR_END +ensure, {kENSURE, kENSURE}, EXPR_BEG +false, {kFALSE, kFALSE}, EXPR_END +for, {kFOR, kFOR}, EXPR_BEG +if, {kIF, kIF_MOD}, EXPR_BEG +in, {kIN, kIN}, EXPR_BEG +module, {kMODULE, kMODULE}, EXPR_BEG +next, {kNEXT, kNEXT}, EXPR_MID +nil, {kNIL, kNIL}, EXPR_END +not, {kNOT, kNOT}, EXPR_BEG +or, {kOR, kOR}, EXPR_BEG +redo, {kREDO, kREDO}, EXPR_END +rescue, {kRESCUE, kRESCUE_MOD}, EXPR_MID +retry, {kRETRY, kRETRY}, EXPR_END +return, {kRETURN, kRETURN}, EXPR_MID +self, {kSELF, kSELF}, EXPR_END +super, {kSUPER, kSUPER}, EXPR_ARG +then, {kTHEN, kTHEN}, EXPR_BEG +true, {kTRUE, kTRUE}, EXPR_END +undef, {kUNDEF, kUNDEF}, EXPR_FNAME +unless, {kUNLESS, kUNLESS_MOD}, EXPR_BEG +until, {kUNTIL, kUNTIL_MOD}, EXPR_BEG +when, {kWHEN, kWHEN}, EXPR_BEG +while, {kWHILE, kWHILE_MOD}, EXPR_BEG +yield, {kYIELD, kYIELD}, EXPR_ARG Index: parse.y =================================================================== RCS file: /cvs/ruby/src/ruby/parse.y,v retrieving revision 1.218 diff -u -2 -p -r1.218 parse.y --- parse.y 22 Sep 2002 12:52:18 -0000 1.218 +++ parse.y 23 Sep 2002 04:01:14 -0000 @@ -3556,5 +3556,5 @@ yylex() nondigit = 0; tokadd(c); - } while (c = nextc()); + } while ((c = nextc()) >= 0); } pushback(c); @@ -3580,5 +3580,5 @@ yylex() nondigit = 0; tokadd(c); - } while (c = nextc()); + } while ((c = nextc()) >= 0); } pushback(c); @@ -3604,5 +3604,5 @@ yylex() nondigit = 0; tokadd(c); - } while (c = nextc()); + } while ((c = nextc()) >= 0); } pushback(c); @@ -3638,5 +3638,5 @@ yylex() nondigit = 0; tokadd(c); - } while (c = nextc()); + } while ((c = nextc()) >= 0); if (toklen() > start) { pushback(c); @@ -4148,5 +4148,5 @@ yylex() if (lex_state == EXPR_FNAME) { if ((c = nextc()) == '=' && !peek('~') && !peek('>') && - (!peek('=') || lex_p + 1 < lex_pend && lex_p[1] == '>')) { + (!peek('=') || (lex_p + 1 < lex_pend && lex_p[1] == '>'))) { result = tIDENTIFIER; tokadd(c); @@ -4259,4 +4259,5 @@ newline_node(node) NODE *nl = 0; if (node) { + if (nd_type(node) == NODE_NEWLINE) return node; nl = NEW_NEWLINE(node); fixpos(nl, node); @@ -4398,5 +4399,5 @@ literal_concat(head, tail) list_append(head, tail); } - return head; + break; case NODE_DSTR: @@ -4412,5 +4413,5 @@ literal_concat(head, tail) list_concat(head, tail); } - return head; + break; case NODE_EVSTR: @@ -4419,6 +4420,7 @@ literal_concat(head, tail) } list_append(head, tail); - return head; + break; } + return head; } @@ -4427,22 +4429,17 @@ new_evstr(node) NODE *node; { - NODE *n; + NODE *head = node; + again: if (node) { switch (nd_type(node)) { case NODE_STR: case NODE_DSTR: case NODE_EVSTR: return node; - case NODE_BLOCK: - for (n = node; n->nd_next; n = n->nd_next) { - NODE *h = n->nd_head; - enum node_type t; - if (!h) continue; - if (t != NODE_STR && t != NODE_LIT) goto evstr; - } - return n->nd_head; + case NODE_NEWLINE: + node = node->nd_next; + goto again; } } - evstr: - return NEW_EVSTR(node); + return NEW_EVSTR(head); }
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦