• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョンa1804ddebaf8f54f922716dcfe83d9726dd18493 (tree)
日時2009-06-13 06:40:04
作者Jack Palevich <jackpal@goog...>
コミッターJack Palevich

ログメッセージ

Allow local variables to be declared anywhere in a block.

変更サマリ

差分

--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -2254,8 +2254,9 @@ class Compiler : public ErrorSink {
22542254 next();
22552255 } else if (t == EOF ) {
22562256 error("Unexpected EOF.");
2257- } else if (t < TOK_UNDEFINED_SYMBOL) {
2258- error("Unexpected symbol or keyword");
2257+ } else if (!checkSymbol(t, &tString)) {
2258+ // Don't have to do anything special here, the error
2259+ // message was printed by checkSymbol() above.
22592260 } else {
22602261 if (t == TOK_UNDEFINED_SYMBOL) {
22612262 t = (intptr_t) mSymbolTable.addGlobal(
@@ -2370,7 +2371,10 @@ class Compiler : public ErrorSink {
23702371 void block(intptr_t l, bool outermostFunctionBlock) {
23712372 intptr_t a, n, t;
23722373
2373- if (tok == TOK_IF) {
2374+ if (tok == TOK_INT || tok == TOK_CHAR) {
2375+ /* declarations */
2376+ localDeclarations();
2377+ } else if (tok == TOK_IF) {
23742378 next();
23752379 skip('(');
23762380 a = test_expr();
@@ -2418,8 +2422,6 @@ class Compiler : public ErrorSink {
24182422 mSymbolTable.pushLevel();
24192423 }
24202424 next();
2421- /* declarations */
2422- localDeclarations();
24232425 while (tok != '}' && tok != EOF)
24242426 block(l, false);
24252427 skip('}');
@@ -2548,31 +2550,30 @@ class Compiler : public ErrorSink {
25482550 }
25492551
25502552 bool checkSymbol() {
2551- bool result = isSymbol();
2553+ return checkSymbol(tok, &mTokenString);
2554+ }
2555+
2556+ bool checkSymbol(int token, String* pText) {
2557+ bool result = token < EOF || token >= TOK_UNDEFINED_SYMBOL;
25522558 if (!result) {
25532559 String temp;
2554- if (tok == EOF ) {
2560+ if (token == EOF ) {
25552561 temp.printf("EOF");
2556- } else if (tok == TOK_NUM) {
2562+ } else if (token == TOK_NUM) {
25572563 temp.printf("numeric constant");
2558- } else if (tok >= 0 && tok < 256) {
2559- temp.printf("char \'%c\'", tok);
2560- } else if (tok >= TOK_KEYWORD && tok < TOK_UNSUPPORTED_KEYWORD) {
2561- temp.printf("keyword \"%s\"", mTokenString.getUnwrapped());
2564+ } else if (token >= 0 && token < 256) {
2565+ temp.printf("char \'%c\'", token);
2566+ } else if (token >= TOK_KEYWORD && token < TOK_UNSUPPORTED_KEYWORD) {
2567+ temp.printf("keyword \"%s\"", pText->getUnwrapped());
25622568 } else {
25632569 temp.printf("reserved keyword \"%s\"",
2564- mTokenString.getUnwrapped());
2570+ pText->getUnwrapped());
25652571 }
25662572 error("Expected symbol. Got %s", temp.getUnwrapped());
25672573 }
25682574 return result;
25692575 }
25702576
2571- /* Is a possibly undefined symbol */
2572- bool isSymbol() {
2573- return tok < EOF || tok >= TOK_UNDEFINED_SYMBOL;
2574- }
2575-
25762577 void globalDeclarations() {
25772578 while (tok != EOF) {
25782579 Type base;