help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Nested comments


From: Hans Aberg
Subject: Nested comments
Date: Wed, 2 Jul 2003 00:39:03 +0200

I implemented nested [* ... *] comments by the code below, but it turns out
to be slow with many nestings, and I do not know why. Is there a way to
make it faster?

%{

int comment_level = 0;

%}

%x comment

%%

"[*"  { BEGIN(comment); comment_level = 1; }
<comment>{
  [^*[]+        {} /* Eat all but * [               */
  "*"+[^*[\]]*  {} /* Eat all * plus all but * [ ]  */
  "["+[^*[\]]*  {} /* Eat all [ plus all but * [ ]  */
  "["+"*"  { ++comment_level; }
  "*"+"]"  {
    --comment_level;
    if (comment_level == 0) {
      BEGIN(INITIAL);
    }
  }
  <<EOF>> {
    std::cerr << "Error: Nested comments not properly closed at end of
file.\n";
    BEGIN(INITIAL); return YYERRCODE;
  }
}
"*]"  { std::cerr << "Error: Too many comment closings *].\n";
        BEGIN(INITIAL); return YYERRCODE; }

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]