gpt4 book ai didi

f# - 期望 LexBuffer 但给定 LexBuffer 类型 'char' 与类型 'byte' 不匹配

转载 作者:行者123 更新时间:2023-12-04 14:52:33 29 4
gpt4 key购买 nike

Type mismatch. Expecting a LexBuffer<char> but given a LexBuffer<byte> The type 'char' does not match the type 'byte'



这是我在使用 fslex 时收到的错误消息。我曾尝试手动检查 lexbuf 的每次出现及其类型。它是 LexBuffer<char>到处。但编译器仍然给我上述错误。你能告诉我为什么会发生这个错误以及如何解决它。
{
open System
open Microsoft.FSharp.Text.Lexing
open Microsoft.FSharp.Text.Parsing

let lexeme (lexbuf : LexBuffer<char>) = new System.String(lexbuf.Lexeme)
let newline (lexbuf:LexBuffer<char>) = lexbuf.EndPos <- lexbuf.EndPos.NextLine
let unexpected_char (lexbuf:LexBuffer<char>) = failwith ("Unexpected character '"+(lexeme lexbuf)+"'")
}

let char = ['a'-'z' 'A'-'Z']
let digit = ['0'-'9']
let float = '-'?digit+ '.' digit+
let ident = char+ (char | digit)*
let whitespace = [' ' '\t']
let newline = ('\n' | '\r' '\n')

rule tokenize = parse
| "maximize" { MAXIMIZE }
| "minimize" { MINIMIZE }
| "where" { WHERE }
| '+' { PLUS }
| '-' { MINUS }
| '*' { MULTIPLY }
| '=' { EQUALS }
| '>' { STRICTGREATERTHAN }
| '<' { STRICTLESSTHAN }
| ">=" { GREATERTHANEQUALS }
| "<=" { LESSTHANEQUALS }
| '[' { LSQUARE }
| ']' { RSQUARE }
| whitespace { tokenize lexbuf }
| newline { newline lexbuf; tokenize lexbuf }
| ident { ID (lexeme lexbuf) }
| float { FLOAT (Double.Parse(lexeme lexbuf)) }
| ';' { SEMICOLON }
| eof { EOF }
| _ { unexpected_char lexbuf }

最佳答案

也许您需要生成一个 unicode 词法分析器。 Unicode 词法分析器使用 LexBuffer <字符 >而不是 LexBuffer <字节 > .

  • FsLex 的“unicode”参数是可选的,但如果启用会生成一个 unicode 词法分析器。

  • http://blogs.msdn.com/dsyme/archive/2009/10/21/some-smaller-features-in-the-latest-release-of-f.aspx

    关于f# - 期望 LexBuffer<char> 但给定 LexBuffer<byte> 类型 'char' 与类型 'byte' 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2713971/

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