Here I've found that it is allowed to declare something like:%type < (context -> context) > toplevel但是我找不到如何使用此构造的方法,并且在项目编译过程中退出了"fsyacc.exe",并出现了代码1."错误But I could not find how to use this construction and during project compilation have "fsyacc.exe" exited with code 1." error 问题是:使用FsYacc解析期间是否可能以及如何使用上下文参数?The Question is: is it possible and how to use context parameters during parsing with FsYacc? 示例:%start startAst%type < (bool -> MyAst) > startAst%% startAst:| MyAst EOF { (fun (x : bool) -> if x then MyAst.Type1 $1 else MyAst.Type2) }...我期望使用这样的东西:and I've expected usage something like this:let lexbuf = Lexing.LexBuffer<char>.FromString textlexbuf |> Lexer.tokenize |> Parser.startAst (ctx: bool)预先感谢 更新,发生以下异常,并且在执行fsyacc.exe的过程中生成了调用堆栈:Update following exception and call stack is generated during fsyacc.exe execution:Unhandled Exception: System.Exception: more than one input given at FSharp.PowerPack.FsYacc.Driver.clo@67-5.Invoke(String x) at <StartupCode$fsyacc>.$Arg.findMatchingArg$cont@104-1(FSharpRef`1 cursor, FSharpFunc`2 other, String usageText, FSharpList`1 argSpecs, String arg, Unit unitVar) at <StartupCode$fsyacc>.$Arg.findMatchingArg@64(FSharpRef`1 cursor, String[] argv, FSharpFunc`2 other, String usageText, Int32 nargs, FSharpList`1 argSpecs, String arg, FSharpList`1 args) at Internal.Utilities.ArgParser.ParsePartial(FSharpRef`1 cursor, String[] argv, IEnumerable`1 arguments, FSharpOption`1 otherArgs, FSharpOption`1 usageText) at Internal.Utilities.ArgParser.Parse(IEnumerable`1 arguments, FSharpOption`1 otherArgs, FSharpOption`1 usageText) at <StartupCode$fsyacc>.$FSharp.PowerPack.FsYacc.Driver.main@()推荐答案很抱歉,耽搁了很长时间,但终于解决了这个问题.Sorry for the long delay, but finally got around to this.谁写了FsYacc(F#团队?)错过了这些功能,可以通过他们在链接页面上的注释看到.我尝试了几种变体,但这是我唯一可以做的变体(请注意:这需要.fsy文件中的#nowarn "62",它将传播到.fs文件,或者传播到--nowarn:62整个项目):Whoever wrote FsYacc (the F# team?) missed the functions, as can be seen by their own comment on the page you linked. I tried several variations, but this is the only one I was able to make work (note: this requires either a #nowarn "62" in the .fsy file, which will propagate to the .fs file, or --nowarn:62 for the whole project):%{open Asttype ('a,'b) Fun = 'a -> 'b%}%start startAst%token <string> MyAst%token EOF%type < (bool, MyAst) Fun > startAst%%startAst:| MyAst EOF { (fun (x : bool) -> if x then MyAst.Type1 $1 else MyAst.Type2) }我不知道为什么(而且没有时间检查FsYacc的消息来源,至少现在没有).I got no idea why (and don't have the time to go over FsYacc's source, at least not right now). 这篇关于在使用F#FsYacc解析期间如何添加和使用自定义上下文参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 18:34