2011-04-22 26 views
4

我開始玩Fslex/Fsyacc。當嘗試使用該輸入Fsyacc:已添加同一個鍵的項目

Parser.fsy生成解析器:

%{ 
open Ast 
%} 

// The start token becomes a parser function in the compiled code: 
%start start 

// These are the terminal tokens of the grammar along with the types of 
// the data carried by each token: 
%token <System.Int32> INT 
%token <System.String> STRING 
%token <System.String> ID 
%token PLUS MINUS ASTER SLASH LT LT EQ GTE GT 
%token LPAREN RPAREN LCURLY RCURLY LBRACKET RBRACKET COMMA 
%token ARRAY IF THEN ELSE WHILE FOR TO DO LET IN END OF BREAK NIL FUNCTION VAR TYPE IMPORT PRIMITIVE 
%token EOF 

// This is the type of the data produced by a successful reduction of the 'start' 
// symbol: 
%type <Ast.Program> start 

%% 

// These are the rules of the grammar along with the F# code of the 
// actions executed as rules are reduced. In this case the actions 
// produce data using F# data construction terms. 
start: Prog { Program($1) } 

Prog: 
    | Expr EOF     { $1 } 

Expr: 
    // literals 
    | NIL     { Ast.Nil ($1) } 
     | INT      { Ast.Integer($1) } 
    | STRING     { Ast.Str($1) } 

    // arrays and records 
    | ID LBRACKET Expr RBRACKET OF Expr { Ast.Array ($1, $3, $6) } 
    | ID LCURLY AssignmentList RCURLY { Ast.Record ($1, $3) } 

AssignmentList: 
    | Assignment { [$1] } 
    | Assignment COMMA AssignmentList {$1 :: $3 } 

Assignment: 
    | ID EQ Expr { Ast.Assignment ($1,$3) } 

Ast.fs

namespace Ast 
open System 

type Integer = 
    | Integer of Int32 

and Str = 
    | Str of string 

and Nil = 
    | None 

and Id = 
    | Id of string 

and Array = 
    | Array of Id * Expr * Expr 

and Record = 
    | Record of Id * (Assignment list) 

and Assignment = 
    | Assignment of Id * Expr 

and Expr = 
    | Nil 
    | Integer 
    | Str 
    | Array 
    | Record 

and Program = 
    | Program of Expr 

Fsyacc報告以下錯誤:「FSYACC:錯誤FSY000:具有相同密鑰的項目已被添加。「

我相信這個問題是在生產用於AssignmentList,卻找不到繞辦法...

任何提示,可以理解

回答

5

恨回答我自己的問題,但問題是這裏(解析器輸入文件的第15行)

%令牌正負ASTER SLASH LT LT EQ GTE GT

注意的雙重定義(應該是LTE)

我的投票用於尋找改善Fslex/Fsyacc可執行文件/ msbuild任務輸出的方法

相關問題