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!
From the looks of it, in your binding rules, you have access to
idswhich is a list of variable names, so you could write, for instance:This would make the
bindingrule return as_var list.