gpt4 book ai didi

f# - Fsyacc:添加了具有相同键的项目

转载 作者:行者123 更新时间:2023-11-30 23:50:50 25 4
gpt4 key购买 nike

我开始玩 Fslex/Fsyacc。尝试使用此输入生成解析器时

解析器.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 的生产中,但找不到解决办法...

任何提示将不胜感激

最佳答案

讨厌回答我自己的问题,但问题就在这里(解析器输入文件的第 15 行)

%token 加减 ASTER 斜线 LT LT 情商 GTE GT

注意双重定义(应该是 LTE)

我投票赞成找到一种方法来改进 Fslex/Fsyacc 可执行文件/msbuild 任务的输出

关于f# - Fsyacc:添加了具有相同键的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5757712/

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