Advertisement
Guest User

Untitled

a guest
Apr 30th, 2012
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. // #include "pl0yacc.tab.h"
  5. #include "pl0yacc.tab.hpp"
  6.  
  7. void yyerror(char*);
  8.  
  9. //#define YY_USER_INIT yylloc.first_line = 1;
  10.  
  11. /*handle locations */
  12. int yylcolumn = 1;
  13.  
  14. /*The macro YY_USER_INIT is used to define the action to be
  15. performed before the first scan*/
  16.  
  17. #define YY_USER_INIT yylloc.first_line = yylloc.first_column = 1;
  18.  
  19. /*The macro YY_USER_ACTION is executed always before the execution
  20. of the action whenever token is recognized by lex*/
  21.  
  22. // #define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno;
  23. // yylloc.first_column = yylcolumn;
  24. // yylloc.last_column = yylcolumn+yyleng-1;
  25. // yylcolumn += yyleng;
  26. %}
  27.  
  28.  
  29. number [0-9]+
  30. identifier [a-zA-Z][a-zA-Z|0-9]*
  31. ws [ \t]+
  32. newline [\r\n]+
  33.  
  34.  
  35. %%
  36.  
  37. ":=" {
  38. //printf("ASSIGNMENT");
  39. //columnCount += 2;
  40. //yylval.num = columnCount;
  41. return ASSIGNMENT;
  42. }
  43. "/" {
  44. //printf("DIVIDE");
  45. //++columnCount;
  46. //yylval.num = columnCount;
  47. return DIVIDE;
  48. }
  49. "*" {
  50. //printf("MULTIPLY");
  51. //++columnCount;
  52. //yylval.num = columnCount;
  53. return MULTIPLY;
  54. }
  55. "-" {
  56. //printf("SUB");
  57. //++columnCount;
  58. //yylval.num = columnCount;
  59. return SUB;
  60. }
  61. "+" {
  62. ///printf("ADD");
  63. //++columnCount;
  64. //yylval.num = columnCount;
  65. return ADD;
  66. }
  67. ")" {
  68. //printf("RB");
  69. //++columnCount;
  70. //yylval.num = columnCount;
  71. return RB;
  72. }
  73. "(" {
  74. //printf("LB");
  75. //++columnCount;
  76. //yylval.num = columnCount;
  77. return LB;
  78. }
  79.  
  80. "<>" {
  81. //printf("NE");
  82. //columnCount += 2;
  83. //yylval.num = columnCount;
  84. return NE;
  85. }
  86. ">=" {
  87. //printf("GE");
  88. //columnCount += 2;
  89. //yylval.num = columnCount;
  90. return GE;
  91. }
  92. "<=" {
  93. //printf("LE");
  94. //columnCount += 2;
  95. //yylval.num = columnCount;
  96. return LE;
  97. }
  98. "=" {
  99. //printf("EQ");
  100. //++columnCount;
  101. ///yylval.num = columnCount;
  102. return EQ;
  103. }
  104. "<" {
  105. //printf("LT");
  106. //++columnCount;
  107. //yylval.num = columnCount;
  108. return LT;
  109. }
  110. ">" {
  111. //printf("GT");
  112. ///++columnCount;
  113. //yylval.num = columnCount;
  114. return GT;
  115. }
  116.  
  117. "," {
  118. //printf("COMMA");
  119. //++columnCount;
  120. //yylval.num = columnCount;
  121. return COMMA;
  122. }
  123. "." {
  124. //printf("DOT");
  125. //++columnCount;
  126. //yylval.num = columnCount;
  127. return DOT;
  128. }
  129. ";" {
  130. //printf("SEMICOLON");
  131. //++columnCount;
  132. //yylval.num = columnCount;
  133. return SEMICOLON;
  134. }
  135.  
  136. begin|BEGIN {
  137. //printf("BEGIN");
  138. //columnCount += 5;
  139. //yylval.num = columnCount;
  140. return BEGN;
  141. }
  142. call|CALL {
  143. //printf("CALL");
  144. //columnCount += 4;
  145. //yylval.num = columnCount;
  146. return CALL;
  147. }
  148. const|CONST {
  149. //printf("CONST");
  150. //columnCount += 5;
  151. //yylval.num = columnCount;
  152. return CONST;
  153. }
  154. do|DO {
  155. //printf("DO");
  156. //columnCount += 2;
  157. //yylval.num = columnCount;
  158. return DO;
  159. }
  160. end|END {
  161. //printf("END");
  162. //columnCount += 3;
  163. //yylval.num = columnCount;
  164. return END;
  165. }
  166. if|IF {
  167. //printf("IF");
  168. //columnCount += 2;
  169. //yylval.num = columnCount;
  170. return IF;
  171. }
  172. odd|ODD {
  173. //printf("ODD");
  174. //columnCount += 3;
  175. //yylval.num = columnCount;
  176. return ODD;
  177. }
  178. procedure|PROCEDURE {
  179. //printf("PROCEDURE");
  180. //columnCount += 9;
  181. //yylval.num = columnCount;
  182. return PROCEDURE;
  183. }
  184. then|THEN {
  185. //printf("THEN");
  186. //columnCount += 4;
  187. //yylval.num = columnCount;
  188. return THEN;
  189. }
  190. var|VAR {
  191. //printf("VAR");
  192. //columnCount += 3;
  193. //yylval.num = columnCount;
  194. return VAR;
  195. }
  196. while|WHILE {
  197. //printf("WHILE");
  198. //columnCount += 5;
  199. //yylval.num = columnCount;
  200. return WHILE;
  201. }
  202.  
  203. {number} {
  204. //int length = strlen(yytext);
  205. //columnCount += length;
  206. //yylval.num = atoi(yytext);
  207. return NUMBER;
  208. //printf("NUMBER");
  209. }
  210.  
  211. {identifier} {
  212. yylval.str = strdup(yytext);
  213. return ID;
  214. //printf("IDENIFIER");
  215. }
  216.  
  217. {ws}$ {
  218. //printf("WHITE_SPACES_AT_END")
  219. }
  220.  
  221. {ws} {
  222. //printf("WHITE_SPACES");
  223. }
  224.  
  225. {newline} {
  226. //yylloc.first_line++;
  227. //printf("NL");
  228. }
  229.  
  230. %%
  231.  
  232. int yywrap(void) {
  233. return 1;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement