lex - Program to remove comments -


I would like to write a program in LX which will remove comments from the input. Comments can be written in these ways:

  • / * comment * /
  • // comment
  • / * then find out some sort of Code> -> Then I'll check / * and ignore the text inside. If input starts with // , then I will ignore it at the end of the line

    but I do not know how to implement it.

Lex patterns alone can not handle nested comments, so you nest with Lex states Recollection must be handled in nature (or writing a recursive original parser).

With Lex, use state stack management routine ( yy_push_state () , yy_pop_state () and yy_top_state () )

Simple example:

 % x BLOCKCOMMENT "/ *" {yy_push_state (BLOCKCOMMENT); } & Lt; BLOCKCOMMENT & gt; "* /" {If (yy_top_state () == Blogcomment) yy_pop_state (); Else fprintf (stderr, "error: stop comment` * /` not found in comment while \ n "); } & Lt; BLOCKCOMMENT & gt; { /* consume */ }  . {Returns yytext [0]; }  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -