C++ “‘(’ token”错误之前预期的主表达式

发布于 2024-11-09 04:32:01 字数 1175 浏览 0 评论 0原文

我有这个代码:

FILE *f = fopen(intPath, "r");
Node *n;
if (f) {
    try {
        n = parse(f, intPath);
    } catch (SyntaxError e) {
        fclose(f); /***** line 536 *****/
        throw LangException(
            builtin_classes::exception_class::create_ImportError(
                String::fromAscii(e.filename)->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.line))->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.col))->
                append(String::fromAscii(": syntax error: "))->
                append(String::fromAscii(e.message))
        );
    }
    fclose(f);
    return n->eval(scope);
} else {
    throw LangException(
        builtin_classes::exception_class::create_ImportError(
            String::fromAscii("failed to open file for reading")
        ),
        line,
        col
    );
}

编译器给出了这个错误:

nodes.cpp:537:40: 错误:'(' 标记之前需要主表达式
nodes.cpp:544:94: 错误:在 ';' 令牌之前应有 ')'

我不知道它可能是什么,特别是因为该代码示例有另一个语句它做同样的事情,并且不会导致错误。

I have this code:

FILE *f = fopen(intPath, "r");
Node *n;
if (f) {
    try {
        n = parse(f, intPath);
    } catch (SyntaxError e) {
        fclose(f); /***** line 536 *****/
        throw LangException(
            builtin_classes::exception_class::create_ImportError(
                String::fromAscii(e.filename)->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.line))->
                append(String::fromAscii(":"))->
                append(String::fromInt(e.col))->
                append(String::fromAscii(": syntax error: "))->
                append(String::fromAscii(e.message))
        );
    }
    fclose(f);
    return n->eval(scope);
} else {
    throw LangException(
        builtin_classes::exception_class::create_ImportError(
            String::fromAscii("failed to open file for reading")
        ),
        line,
        col
    );
}

And the compiler gives this error:

nodes.cpp:537:40: error: expected primary-expression before ‘(’ token
nodes.cpp:544:94: error: expected ‘)’ before ‘;’ token

I have no clue what it could be, especially since that code sample has another statement which does the same thing, and it doesn't cause an error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

入画浅相思 2024-11-16 04:32:01
throw LangException(
   builtin_classes::exception_class::create_ImportError(
      String::fromAscii(e.filename)->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.line))->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.col))->
      append(String::fromAscii(": syntax error: "))->
      append(String::fromAscii(e.message))
   )  // This closes the function call
; // You didn't close the throw here!
throw LangException(
   builtin_classes::exception_class::create_ImportError(
      String::fromAscii(e.filename)->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.line))->
      append(String::fromAscii(":"))->
      append(String::fromInt(e.col))->
      append(String::fromAscii(": syntax error: "))->
      append(String::fromAscii(e.message))
   )  // This closes the function call
; // You didn't close the throw here!
旧伤还要旧人安 2024-11-16 04:32:01

您的 () 在那个大的第一个 throw LangException 块中不匹配。

Your ( and your ) don't match in that large, first throw LangException block.

喵星人汪星人 2024-11-16 04:32:01

编译器会告诉你哪里出了问题。 throw LangException( 没有 )

The compiler tells you what is wrong. The throw LangException( doesn't have a ).

九八野马 2024-11-16 04:32:01

正是它所说的。该行的 ';' 标记之前缺少 ')'

LangException(...

没有关闭。

Exactly what it says. You are missing a ‘)’ before ‘;’ token on that line.

LangException(...

is not closed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文