Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. %top{
  2. #include "alphabet.h"
  3. #include "context.h"
  4. #include <stdio.h>
  5.  
  6. #define lastchar yytext[yyleng - 1]
  7.  
  8. #define YY_BUF_SIZE 66000
  9.  
  10. struct alphabet* alphabet;
  11. struct context* current;
  12. struct stack* contexts;
  13.  
  14. void operand_action(struct expression*);
  15. void operator_action(int);
  16.  
  17. void change_context();
  18. void restore_context();
  19.  
  20. int is_comment = 0;
  21.  
  22. struct expression* get_result();
  23. }
  24.  
  25. %s SEPA CHARA SEP EXP EXPO COMMENT ALPH SOURCE COMMENT_CODE CODE
  26.  
  27.  
  28.  
  29. upper [A-Z]
  30. lower [a-z]
  31. letter {upper}|{lower}
  32.  
  33. special "#"|"$"|"*"|"@"
  34.  
  35. digit [0-9]
  36. symbol {letter}|{special}|{digit}
  37.  
  38. sep "\n"|"\r"|"\t"|" "
  39. comentariu ";".+{sep}
  40.  
  41. name ({letter}|{digit}|"_")+
  42.  
  43. element {symbol}
  44.  
  45. elementary "L"|"R"|{element}|"L(""!"?{element}")"|"R(""!"?"
  46.  
  47.  
  48.  
  49. mt_call "["{name}"]"|"["{elementary}"]"
  50.  
  51. set "{"{symbol}(","{symbol})*"}"
  52. transition {set}" -> "{mt}+";"
  53. mt_trans "("{transition}*")"
  54.  
  55. mt ({name}"@")?({mt_call}|{mt_trans})|"&"{name}
  56.  
  57. mt_decl {name}" ::= "{mt}+";;"{sep}
  58.  
  59.  
  60.  
  61. code {mt_decl}
  62.  
  63. nocom {symbol}+{sep}+
  64.  
  65.  
  66.  
  67. alphab_ad {symbol}{sep}+
  68. alphab "alphabet :: "{alphab_ad}+";"
  69.  
  70. %option noinput
  71. %option nounput
  72. %option noyymore
  73.  
  74. %%
  75. alphabet BEGIN(ALPH);
  76. "^[alphabet]" BEGIN(COMMENT_CODE);
  77.  
  78. <ALPH>" :: " {/*At first we read the first bracket of the alphabet*/
  79. BEGIN(CHARA);
  80. }
  81.  
  82. <CHARA>{symbol} {/*Then we read one symbol at a time*/
  83. printf("Simbol din alfabet: %c\n", lastchar);
  84. BEGIN(SEPA);
  85. }
  86. <SEPA>{ /*We read the separator that follows a symbol and change the state.*/
  87. " " BEGIN(CHARA);
  88. " ;"{sep} BEGIN(COMMENT_CODE);
  89. ";"{sep} BEGIN(COMMENT_CODE);
  90. {sep} BEGIN(COMMENT_CODE);
  91. }
  92. <COMMENT_CODE>{
  93. {comentariu} printf("Comentariu %s\n", yytext); BEGIN(COMMENT);
  94. {mt_decl} printf("Cod in COMMENT_CODE: %s\n", yytext); BEGIN(CODE);
  95. }
  96.  
  97. <COMMENT>{
  98. . ECHO;
  99. "\n" printf("\n"); BEGIN(COMMENT_CODE);
  100. }
  101.  
  102. <CODE>{
  103. }
  104.  
  105.  
  106. %%
  107.  
  108. int main(void)
  109. {
  110. FILE* f = fopen("RE", "rt");
  111. yyrestart(f);
  112. yylex();
  113. fclose(f);
  114.  
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement