gpt4 book ai didi

c++ - 编译酷项目中的语法错误

转载 作者:行者123 更新时间:2023-11-28 07:02:14 25 4
gpt4 key购买 nike

我从 https://github.com/cchuahuico/COOL-Compiler

编译这段代码时:

class Main inherits SuperClass {
main(): Object {{
out_string("Enter an integer greater-than or equal-to 0: ");

let input: Int in
if input < 0 then
input
-- out_string("ERROR: Number must be greater-than or equal-to 0\n")
else {
-- out_string("The factorial of ").out_int(input);
-- out_string(" is ").out_int(factorial(input));
factorial(input);
}
fi;
}};

factorial(num: Int): Int {
if num = 0 then 1 else num * factorial(num - 1) fi
};
};

class SuperClass {
out_string(str:String){};
};

用mingw编译时出现这个错误

<stdin>:2:error:syntax error near or aat character or token '{'
<stdin>:5:error:syntax error near or aat character or token 'let'
<stdin>:14:error:syntax error near or aat character or token 'fi'
<stdin>:15:error:syntax error near or aat character or token '}'
<stdin>:23:error:syntax error near or aat character or token '('
<stdin>:24:error:syntax error near or aat character or token '}'
<stdin>:24:error:syntax error near or aat character or token ' '
copmilation halted due to lexical or syntax errors

最佳答案

mingw 编译器报错,因为语言不是标准的 C++:

  1. inherits 关键字。虽然,它可以是 #define 作为任何东西。

  2. fi 不是关键字。

  3. if 语句需要 parens () 表达式。

  4. let 不是关键字。

  5. then 不是关键字。

//还有很多

这是另一种语言吗?

关于c++ - 编译酷项目中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22272764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com