Like others, he suggested that the preferred method would be to have a structure modifier with visibility and static parameters. But I will probably make it a static modifier in the sense that it will not be passed to the field, but instead is simply used to retrieve the values, and then passed to the field. You can even push it onto the stack and reuse it to make it faster.
Something in the following lines:
static struct { boolean vis_opt; boolean static_opt; } mod; field : modifier type TOK_IDENT TOK_SEMICOLON { $$ = new Field(..., mod.vis_opt, mod.static_opt, ...); } ; modifier : visibility_opt static_opt { mod.vis_opt = $1; mod.static_opt = $2; } ; visibility_opt : /* default */ { $$ = true; } | TOK_PUBLIC { $$ = true; } | TOK_PRIVATE { $$ = false; } ; static_opt : /* default */ { $$ = false; } | TOK_STATIC { $$ = true; } ;
In addition, if you are not sure about the future of the language, you may want to make visibility an enumeration. You never know what kind of visibility it is, you can dream when developing a language, and at least if you have it in the enumeration, it is easier to extend it later.
Enjoy.
source share