Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 758741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:30:57+00:00 2026-05-14T15:30:57+00:00

Type mismatch. Expecting a LexBuffer<char> but given a LexBuffer<byte> The type ‘char’ does not

  • 0

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

This is the error message that I am getting while using fslex. I have tried manually checking every single occurrence of lexbuf and its type. It’s LexBuffer<char> everywhere. But still the compiler is giving me the above error. Can you please tell me why this error occurs and how to go about resolving it.

{
    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 } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:30:58+00:00Added an answer on May 14, 2026 at 3:30 pm

    There was a mistake with my lexer file definition I believe, it compiled when I made the following my lexer definition. Experts can throw more insight into the reasons, while the understanding that I have is the type of the lexbuf that is used in the lexer should somehow be related to the definition that the parser generates

    {
    
    open System
    open LanguageParser
    open Microsoft.FSharp.Text.Lexing
    open Microsoft.FSharp.Text.Parsing
    open System.Text
    
    let newline (lexbuf:LexBuffer<_>) = lexbuf.EndPos <- lexbuf.EndPos.NextLine
    
    }
    
    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 <| Encoding.UTF8.GetString(lexbuf.Lexeme) }
        | float { FLOAT <| Double.Parse(Encoding.UTF8.GetString(lexbuf.Lexeme)) } 
        | ';' { SEMICOLON }
        | eof { EOF }
        | _ { failwith ("Unexpected Character") } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works Lastrow = 8, but not 9 (Type mismatch) If i remove If
Why this compiler does not alert me about a possible type mismatch here? NSHour*
Can someone please explain why I'm getting this error Type mismatch: cannot convert from
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Type.GetFields() does not return fields in a particular order, but I want to sort
I'm getting this error: Data type mismatch in criteria expression when trying to execute
I have only this, but my compiler says:Type mismatch: cannot convert from ArrayList to
Given the following code , under Eclipse , I get a type mismatch error
Sometimes this (relatively strange looking) syntax is required to avoid a type mismatch. But
Am getting Run-time error 13 . Type Mismatch. But i cant figure out why.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.