fork download
  1. %{
  2. #include <stdio.h>
  3. // int commented_lines = 0;
  4. // FILE *fptr;
  5. int flag1 = 0;
  6. int flag2 = 0;
  7. int flag3 = 0;
  8. int stop = 0;
  9. %}
  10.  
  11. %%
  12. global {
  13. if(stop == 0){
  14. if(flag1 == 0){
  15. flag1++;
  16. printf("GLOBAL CONFIG\n---------------\n");
  17. }else{
  18. printf("global not present at the top");
  19. stop = 1;
  20. }
  21. }
  22. }
  23. \{ {
  24. if(stop == 0){
  25. if(flag1 != 1 && flag3 == 0){
  26. printf("Error not after global");
  27. exit(0);
  28. }else{
  29. flag1++;
  30. }
  31. }
  32. }
  33. [ \t]
  34. \n {
  35. if(stop == 0){
  36. if(flag1 != 2){
  37. printf("\n");
  38. }
  39. }
  40. }
  41. [a-zA-Z]+[a-zA-Z0-9_]*[ \t]*\=[ \t]*([0-9]+(\.[0-9])*|(\/[a-zA-Z]*)*) {
  42. if(stop == 0){
  43. if(flag1 == 2){
  44. flag1++;
  45. }
  46.  
  47. if(flag1 != 3 && flag3==0){
  48. printf("Error not after brackets");
  49. exit(0);
  50. }else{
  51. printf("%s", yytext);
  52. }
  53. }
  54. }
  55. \}\; {
  56. if(stop == 0){
  57. if(flag1 != 3 && flag3 == 0){
  58. printf("Error not after optional identifiers");
  59. printf("flag: %d", flag1);
  60. exit(0);
  61. }else{
  62. flag1++;
  63. }
  64. }
  65. }
  66. host {
  67. if(stop == 0){
  68. if(flag1 < 4){
  69. printf("GLOBAL not present at top");
  70. exit(0);
  71. }else{
  72. printf("HOST");
  73. flag1++;
  74. flag2 = 1;
  75. flag3 =1;
  76. }
  77. }
  78. }
  79. \"[0-9a-zA-Z\-\.]*\" {
  80. if(stop == 0){
  81. if(flag2 != 1){
  82. printf("Error not after host");
  83. exit(0);
  84. }else{
  85. flag2 = 0;
  86. printf(" %s CONFIG\n--------------", yytext);
  87. }
  88. }
  89.  
  90. }
  91. %%
  92.  
  93. int main(int argc, char *argv[]){
  94. yyin = fopen(argv[1], "r");
  95. // fptr = fopen("code.c", "a");
  96. yylex();
  97. fclose(yyin);
  98. // fclose(fptr);
  99. // printf("Number of commented lines = %d", commented_lines);
  100. }
  101.  
  102. int yywrap(){
  103. return 1;
  104. }
Success #stdin #stdout #stderr 0.02s 6956KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/rXqapi/prog:104:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit