[talk] lex start conditions.

R. Clayton factotum at rclayton.org
Wed Oct 28 19:25:41 EDT 2020

I'm working with a 40-year-old lex program that uses statements like


I understand what


does, but what is the intention of the "+ 1"? Does it skip the first rule in
the <PROGRAM> context? The generated code suggests not, but I haven't dug into
it too deeply. Does it select the context listed after the <PROGRAM> context?
That seems slightly more plausible, but a test lex program doesn't support that
intention (it's likely the test program is ineffectively written). I'm using
flex, not a 40-year-old version of lex.

For completeness, here's the test program:

  $ cat t.lex 
  %s A B C

		  BEGIN A;

  <A>[BC]         if (yytext[0] == 'B') BEGIN B + 1; else BEGIN C;
  <A>.            printf("A: '%c'\n", yytext[0]);

  <B>[AC]         if (yytext[0] == 'A') BEGIN A; else BEGIN C;
  <B>.            printf("B: '%c'\n", yytext[0]);

  <C>[AB]         if (yytext[0] == 'A') BEGIN A; else BEGIN B;
  <C>.            printf("C: '%c'\n", yytext[0]);


  main() { yylex(); }

  $ echo abcBabc | ./a.out 
  A: 'a'
  A: 'b'
  A: 'c'
  B: 'a'
  B: 'b'
  B: 'c'


More information about the talk mailing list