Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging F中简单解析器规范中的错误#_Debugging_F#_Fsyacc - Fatal编程技术网

Debugging F中简单解析器规范中的错误#

Debugging F中简单解析器规范中的错误#,debugging,f#,fsyacc,Debugging,F#,Fsyacc,我想知道下面的解析器规范哪里出错了。解析器旨在解析和计算表达式,如2+3*4到14。它将与FsLexYacc一起运行 %{ %} %token <int> CSTINT %token PLUS MINUS MUL %token LPAR RPAR %token EOF %left MINUS PLUS /* lowest precedence */ %left TIMES DIV /* highest precedence */ %start M

我想知道下面的解析器规范哪里出错了。解析器旨在解析和计算表达式,如2+3*4到14。它将与FsLexYacc一起运行

%{
%}

%token <int> CSTINT
%token PLUS MINUS MUL
%token LPAR RPAR
%token EOF

%left MINUS PLUS        /* lowest precedence  */
%left TIMES DIV         /* highest precedence */

%start Main
%type int Main 

%%

Main:
    Expr EOF                            { $1 }
;

Expr:
  | CSTINT                              { $1           }
  | MINUS CSTINT                        {  - $2       }
  | LPAR Expr RPAR                      { $2 }
  | Expr MUL Expr                     {  $1 * $3 }
  | Expr PLUS  Expr                     {  $1+$3 }  
  | Expr MINUS Expr                     {  $1-$3 } 
;

第18行是指“Main”之前的一行。bug在哪里?

我认为
%type
指定的类型应该在尖括号中:

%type <int> Main 
%type Main
%type <int> Main