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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:47:41+00:00 2026-06-05T01:47:41+00:00

Is it possible to feed an OCamlYacc-generated parser an explicit token list for analysis?

  • 0

Is it possible to feed an OCamlYacc-generated parser an explicit token list for analysis?

I’d like to use OCamlLex to explicitly generate a token list which I then analyze using a Yacc-generated parser later. However, the standard use case generates a parser that calls a lexer implicitly for the next token. Here tokens are computed during the yacc analysis rather than before. Conceptually a parser should only work on tokens but a Yacc-generated parser provides an interface that relies on a lexer which in my case I don’t need.

  • 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-05T01:47:42+00:00Added an answer on June 5, 2026 at 1:47 am

    If you already have a list of tokens, you can just go the ugly way and ignore the lexing buffer altogether. After all, the parse-from-lexbuf function that your parser expects is a non-pure function :

    let my_tokens = ref [ (* WHATEVER *) ]
    let token lexbuf = 
      match !my_tokens with 
        | []     -> EOF 
        | h :: t -> my_tokens := t ; h 
    
    let ast = Parser.parse token (Lexbuf.from_string "")
    

    On the other hand, it looks from your comments that you actually have a function of type Lexing.lexbuf -> token list that you’re trying to fit into the Lexing.lexbuf -> token signature of your parser. If that is the case, you can easily use a queue to write a converter between the two types:

    let deflate token = 
      let q = Queue.create () in
      fun lexbuf -> 
        if not (Queue.is_empty q) then Queue.pop q else   
          match token lexbuf with 
            | [   ] -> EOF 
            | [tok] -> tok
            | hd::t -> List.iter (fun tok -> Queue.add tok q) t ; hd 
    
    let ast = Parser.parse (deflate my_lexer) lexbuf
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Is it possible to feed an array of image names into code which converts
Is it possible to use Drupal to feed a few dynamic portions of a
Is it possible to use AutoMapper with a single property? I would like to
Is it possible to read JSON feed available in another site which is HTTPS?
It's now possible to tag friends and location in feed post https://developers.facebook.com/blog/post/2012/03/07/building-better-stories-with-location-and-friends/ according to
Is it possible to create a web site and, with JavaScript, read the feed
on http://www.youngcreativity.se you can se that it is a news feed. Is it possible
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will

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.