编译酷项目中的语法错误

时间:2014-03-08 17:41:58

标签: c++ compiler-construction makefile mingw

我从中获得项目 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

1 个答案:

答案 0 :(得分:1)

mingw编译器抱怨,因为该语言不是标准的C ++:

  1. inherits个关键字。虽然,它可能是#define 任何东西。

  2. fi不是关键字。

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

  4. let不是关键字。

  5. then不是关键字。

  6. //还有更多

    这是另一种语言吗?