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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:10:26+00:00 2026-06-13T04:10:26+00:00

I’ve spent a day trying to a simple compiler program but still have difficulties

  • 0

I’ve spent a day trying to a simple compiler program but still have difficulties understanding this function.

let rec expression tokens = 
  let (trm, tokens') = term tokens in 

here so (trm, tokens’) is a tuple, is term a function or a variable? How can a tuple = two variables or a function

  expTail trm tokens'

and
  expTail trm tokens = 
  match tokens with
    Tokenizer.PlusTok::tokens' ->
      let (trm', tokens'') = term tokens' in expTail (Plus(trm, trm')) tokens''

  | Tokenizer.MinusTok::tokens' ->
      let (trm', tokens'') = term tokens' in expTail (Minus(trm, trm')) tokens''

  |  _ -> (trm, tokens)

what does this line mean? it doesn’t seem to call anything. And why is it now (trm, tokens) not (trm’, tokens”)

and
  term tokens = let (trm, tokens') = factor tokens in termTail trm tokens'

Not really sure what this line means either.

and
  termTail trm tokens =
  match tokens with
    Tokenizer.TimesTok::tokens' -> 
      let (trm', tokens'') = factor tokens' in termTail (Times(trm, trm')) tokens''

  | Tokenizer.DivTok::tokens' -> 
      let (trm', tokens'') = factor tokens' in termTail (Div(trm, trm')) tokens''

  | Tokenizer.ModTok::tokens' -> 
      let (trm', tokens'') = factor tokens' in termTail (Mod(trm, trm')) tokens''

  | _ -> (trm, tokens)

and
  factor tokens =
  match tokens with
  Tokenizer.LParenTok::tokens' -> 
  let (expr, tokens'') = expression tokens' in
      (match tokens'' with
      Tokenizer.RParenTok::tokens''' -> (expr, tokens''')
  | _ -> raise (Syntax "Bad factor, failed to find )\n")) 

  | (Tokenizer.IntTok i)::tokens' -> (Bits i,  tokens')

  | _ -> raise (Syntax ("Bad factor."))

Thanks guys!

  • 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-13T04:10:27+00:00Added an answer on June 13, 2026 at 4:10 am

    These are pretty basic questions. It might be good to start with an OCaml tutorial (maybe see previous SO question OCaml Resources?).

    Some answers:

    let (trm, tokens') = term tokens
    

    This calls a function named term passing tokens as the argument. The result is a pair. You’re going to refer to the first element of the pair by the name trm and the second by the name tokens'.

    and
       term tokens = let (trm, tokens') = factor tokens in termTail trm tokens'
    

    These are the lines that define the term function called above.

      |  _ -> (trm, tokens)
    

    This is the default case for the pattern match. If neither of the other two patterns matches, the value is given by this alternative. This is basically a value, not a function call. However, in some sense there is a function involved–you’re constructing a pair. The comma (,) is used as nice syntax for constructing a pair. (The parentheses are actually optional, though stylistically I like to see them.)

    The names tokens and tokens' are just different names. There’s no inherent relation between them. In this default case, no value named tokens' is defined. So it’s not possible to refer to such a value here. Conventionally, adding a “prime” to the end of a name is used to indicate that the new value is somehow derived from the old one.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I

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.