Implement context dependent language with ocamlyacc

I am sorry the title is misleading, it should be Implement context dependent language with menhir. I didn’t distinguish ocamlyacc and menhir before…

I read the menhir document and a related post that makes lexer a bit smarter. Now i got some clues but still need some helps.

I am planning to return different tokens, say variable token and type token, according the same rule. snippet of .mll file looks like

let ident = ['A'-'Z' 'a'-'z' '_']['A'-'Z' 'a'-'z' '0'-'9' '_']*
rule initial type_set = parse
  | ident as name {if ident in type_set then TIdent name else VIdent name}

This type_set stores all type variables declared till now. So once a identifier is recognized, lexer can check if this identifier is a type variable or not. If it is a type variable, then return type ident token for parser, otherwise variable ident token.

However, the key point now is how can I pass this type_set to lexer. I know ocamllex allows to pass argument at entrypoint. However, these arguments seems to be internal. Can I pass these argument from parser(menhir)?