localleg.leg 330 B

12345678910111213141516171819202122232425
  1. %{
  2. #define YY_CTX_LOCAL 1
  3. #define YY_CTX_MEMBERS \
  4. int count;
  5. %}
  6. Char = ('\n' | '\r\n' | '\r') { yy->count++ }
  7. | .
  8. %%
  9. #include <stdio.h>
  10. #include <string.h>
  11. int main()
  12. {
  13. yycontext yy;
  14. memset(&yy, 0, sizeof(yy));
  15. while (yyparse(&yy))
  16. ;
  17. printf("%d newlines\n", yy.count);
  18. yyrelease(&yy);
  19. return 0;
  20. }