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 8309915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:16:15+00:00 2026-06-08T19:16:15+00:00

I am writing a lexer in OCaml for a small language, I have a

  • 0

I am writing a lexer in OCaml for a small language, I have a part of its grammar as follows:

tab-character = %x0009
eom-character = %x0019
space-character = %x0020
underscore = %x005F
single-quote = %x0027 ; '

I try to write let single_quote = [%x0027] in lexer.mll, but I get an illegal character error while compilation,

Could anyone tell me how to specify such numbers as %x0027?

The compilation works with the statement let single_quote = ['''], I have also seen another way to specify a character, for instance let black = ['\009'],

Does anyone know if there is any difference between these 3 ways?

  • 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-06-08T19:16:18+00:00Added an answer on June 8, 2026 at 7:16 pm

    I think you’re asking about character literals in OCaml. They are defined in Section 6.1 of the OCaml manual.

    For single quote you can write '\'' or '\x27' or '\039'. All of these are equivalent. All character literals are written in single quotes–there’s no form beginning with a percent (%).

    Regular expressions in ocamllex can contain character literals (as above), which denote single characters, or string literals (in double quotes), which denote a sequence of characters. String literals follow the same pattern as character literals. A string containing just a single quote would be "'" or "\'" or "\x27" or "\039".

    I hope this helps.

    Edit:

    Yes, ['\x09'] and '\x09' and "\x09" are the same when considered as regular expressions. A set with one thing in it denotes the same thing as that one thing by itself. Similarly, a sequence of length 1 is the same as just the one thing.

    The value 0x3000 in Unicode represents an “Ideographic Space” (used in Chinese, Japanese, and Korean I guess). Handling Unicode in OCaml is a whole other topic. There is a Unicode library for OCaml called Camomile. I’ve never used it, but it is well regarded from what I’ve seen. I don’t think ocamllex works with Unicode. Just googling quickly I see a lexer generator named ulex that handles Unicode. There are probably others, this is just the top Google hit.

    (Whoops, I see Jonathan Protzenko already recommended ulex. Sorry for extra noise.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a lexer of .java source files in Java. I have a stream of
I'm writing a lexer in Prolog which will be used as a part of
I'm writing a compiler for a small language, and my Parser class is currently
I am writhing a simple language with antlr, I defined a Lexer grammar in
I am writing a compiler for a small imperative language. The target language is
I am writing a lexer for Haskell using JavaScript and Parsing Expression Grammar, the
I'm writing a lexer using jflex for a made up programming language. It requires
I'm writing a lexer/parser for a small subset of C in ANTLR that will
In the book "Unix Programming Environment" the book relies on writing its own lexer
I am writing a compiler as part of a lab excercise and have chosen

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.