Ocamlyacc sign is not displayed during semantic action

I use ocamlyacc for a small parser that also performs some semantic actions for most parsing rules.

I defined a set of tokens at the beginning:

 %token T_plus %token T_minus %token <int> T_int_const %left T_plus T_minus 

An analyzer rule that performs a semantic action is as follows:

 exp: exp T_plus exp { checkType T_plus $1 $3 } 

where checkType is an external helper function. However, I get this strange warning (which refers to a line in my Parser.mly file)

  warning: T_plus was selected from type Parser.token. It is not visible in the current scope, and will not be selected if the type becomes unknown. 

I did not find any information in the ocamlyacc manual. Has anyone encountered a similar error? Why is the marker not displayed inside the semantic scope?

+4
source share
1 answer

It is impossible to guess what is wrong on your side, since you are not revealing enough information. I can guess that you somehow read the error message incorrectly, and the problem is in another file. For example, the following file:

 %{ let f PLUS _ = () %} %token PLUS %left PLUS %start exp %type <unit> exp %% exp : exp PLUS exp {f PLUS $1} 

compiles any problems or warnings with

 ocamlbuild Parser.byte 

I can only suggest, look at the generated Parser.ml and see what happens there.

In general, this message means that you are referencing a constructor that has not been delivered to scope. In Parser.mly tokens are always in scope, so you do not see this error in this file. You can usually do this in your lexer. So make sure you have open Parser in your lexer entry.

+2
source

All Articles