Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "header.h"
  6. #include "y.tab.h"
  7. using namespace std;
  8.  
  9. int yyerror(char*);
  10. simple s,t;
  11. int line_count=1;
  12. %}
  13.  
  14.  
  15.  
  16. INCLUDE #include<[a-z]+\.h>
  17. WS [ \t]+
  18. DIGIT [0-9]
  19. NUMBER [-]?{DIGIT}+(\.{DIGIT}+)?
  20. letter [A-Za-z]
  21. id (_|{letter})(_|{letter}|{DIGIT})*
  22.  
  23.  
  24.  
  25. %%
  26.  
  27.  
  28.  
  29. "(" { return LPAREN; }
  30. ")" { return RPAREN; }
  31.  
  32. "{" { return LCURL; }
  33. "}" { return RCURL; }
  34.  
  35. ";" { return SEMICOLON; }
  36. "=" { return ASSIGNOP;}
  37. "\"" { return D_QUOTE; }
  38. "%d" { return SPECIFIER; }
  39. "printf" { return PRINTF; }
  40. "," { return COMMA; }
  41.  
  42. "main" {return MAIN;}
  43. "int" {return INT;}
  44. "using namespace std;" {}
  45. "return 0;" {}
  46.  
  47. "\n" {line_count++;}
  48. {id} {
  49. s.ch=yytext;
  50. s.d = strlen(s.ch);
  51. yylval=(YYSTYPE)&s;
  52. return VARIABLE;}
  53.  
  54. {WS} { /* No action and no return */}
  55.  
  56. {NUMBER} {
  57.  
  58. t.ch=yytext;
  59. t.d = strlen(t.ch);
  60. yylval=(YYSTYPE)&t;
  61. return NUMBER;
  62. }
  63.  
  64.  
  65. {INCLUDE} {
  66. return INCLUDE;
  67. }
  68.  
  69.  
  70.  
  71. %%
  72.  
  73. int yywrap()
  74. {
  75. return -1;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement