类型不匹配。期待
LexBuffer<char>
但由于一个LexBuffer<byte>
类型“字符”类型“字节”期待LexBuffer <char>,但给定LexBuffer <byte>类型'char'与'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 }
欢迎这样的定义是在词法分析器中使用的lexbuf的类型。请注意,问题文本中的尖括号需要在引号中进行转义才能正确显示 - 我已经为您编辑了该编辑。 – AakashM 2010-04-26 14:03:00
无法调试我们无法看到的代码。请发布您的代码。 – Juliet 2010-04-26 17:33:00
这是词法分析器的定义。上下文是使用F#编写线性程序的DSl。 – csprabala 2010-04-27 05:31:01