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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The pointer you pass to free must be the same… May 17, 2026 at 12:20 am
  • Editorial Team
    Editorial Team added an answer Note that linux's and mac os's fsync and fdatasync are… May 17, 2026 at 12:20 am
  • Editorial Team
    Editorial Team added an answer There is none. That's because arrays will decay to a… May 17, 2026 at 12:20 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I get the following error in diff with a red squiggle under Subset. Type
Anyone know what the problem with this code is? let rec Foo(a,b) = match
Why this piece of code is working on my fsi, but can't build the
When I'm writing this code, I've got a Compile error in Scala var s:
When I try to omit dots from method invocations, like in this example program:
I would like to use a discriminated union to represent a files and directories.
I have a Set in Scala (I can choose any implementation as I am
I'm trying to sort each Position (which is a list) in a Position list.
I have made a bunch of 2D arrays in Excel, and I have written
I was chatting with Sadek Drobi on twitter when be brought up that F#

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.