how to handle nested comment in flex

后端 未结 3 1375
轻奢々
轻奢々 2021-01-24 17:32

I am working on writing a flex scanner for a language supporting nested comment like this:

/*
/**/
*/

I use to work on ocaml/ocamllex that supp

3条回答
  •  逝去的感伤
    2021-01-24 18:02

    I resolve this problem by using yy_push_state , yy_pop_state and start condition like this :

    %x comment 
    %%
    "/*" {
      yy_push_state(comment);
    }
    {
      "*/" {
        yy_pop_state();
      }
    
      "/*" {
        yy_push_state(comment);
      }
    }
    %%
    

    In this way, I can handle any level of nested comment.

提交回复
热议问题