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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:36:24+00:00 2026-05-23T11:36:24+00:00

I am writing a compiler of mini-pascal in Ocaml. I would like my compiler

  • 0

I am writing a compiler of mini-pascal in Ocaml. I would like my compiler to accept the following code for instance:

program test;
var
   a,b : boolean;
   n : integer;
begin
   ...
end.

I have difficulties in dealing with the declaration of variables (the part following var). At the moment, the type of variables is defined like this in sib_syntax.ml:

type s_var =
    { s_var_name: string;
      s_var_type: s_type; }

Here is sib_parser.mly. My question is, where and how I could tell the compiler to build globals, the declaration of variables, which is actually a list of s_var. I guess I need to refine the part of menhir in the end of sib_parser.mly(terminated_bindings, binding, separated_nonempty_list, etc.), but I do not know how…

Could anyone help? Thank you very much!

  • 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-23T11:36:24+00:00Added an answer on May 23, 2026 at 11:36 am

    From the looks of it, in your binding rules, you have access to ids which is a list of variable names, so you could write, for instance:

    binding:
      | ids = separated_nonempty_list(COMMA, IDENT) COLON INTEGER
          { List.map (fun id -> { s_var_name = id ; s_var_type = St_int}) ids }
      | ids = separated_nonempty_list(COMMA, IDENT) COLON BOOLEAN
          { List.map (fun id -> { s_var_name = id ; s_var_type = St_bool}) ids }
    

    This would make the binding rule return a s_var list.

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

Sidebar

Related Questions

Possible Duplicate: How to code a compiler in C? How would I start writing
Im writing a compiler for university project, and I would like to transform my
I'm writing a compiler which uses C as an intermediate code which is (Currently)
I am experimenting with writing a toy compiler in ocaml. Currently, I am trying
I'm writing a compiler that generates Jasmin code and want to invoke a method
I am writing a compiler for a c-like language. Currently, the compiler supports arrays
I'm writing a compiler for a simple C-like language for a course I'm taking.
I'm writing a compiler for a subset of Pascal. The compiler produces machine instructions
I am writing a compiler written in OCaml. Sometimes when there is an error
I'm writing a compiler in ocaml, using ocamllex/yacc. Things are going well, but I've

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.