Create a table with tokens visible for .mly.mll

I would like to define keyword_tablewhich displays some rows for some tokens, and I would like to make this table visible to both parser.mly, and for lexer.mll.

It seems that the table should be defined in parser.mly,

%{ 
  open Utility (* where hash_table is defined to make a table from a list *)
  let keyword_table = hash_table [
      "Call", CALL; "Case", CASE; "Close", CLOSE; "Const", CONST; 
      "Declare", DECLARE; "DefBool", DEFBOOL; "DefByte", DEFBYTE ]
%}

However, I could not use it in lexer.mll, for example

{
open Parser
let x = keyword_table (* doesn't work *)
let x = Parser.keyword_table (* doesn't work *)
let x = Parsing.keyword_table (* doesn't work *)
}

Can someone tell me where the problem is? Is it impossible to make data visible to both parser.mly, and lexer.mll?

0
source share
2 answers

gsg answer, ocamlyacc mli ml . http://caml.inria.fr/mantis/view.php?id=1703, , :

  • mli ( Makefile, rm , ).
  • menhir, , .
0

, . .ml :

.mly:

%{ 
    open Data
%}

.mll:

{
    open Data
}

parse.mly . ocamlyacc , parse.mli, .

0

All Articles