Advertisement
tomdodd4598

Untitled

Sep 7th, 2021
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. Package drlc;
  2.  
  3. Helpers
  4. all = [0 .. 0xFFFF];
  5. digit = ['0' .. '9'];
  6. letter = [['a' .. 'z'] + ['A' .. 'Z']];
  7. name_char = digit | letter | '_';
  8.  
  9. sign = '-' | '+';
  10. apostrophe = ''';
  11.  
  12. tab = 9;
  13. lf = 10;
  14. cr = 13;
  15. eol = cr | lf | cr lf;
  16. separator = ' ' | tab | eol;
  17.  
  18. double_slash = '//';
  19. slash_star = '/*';
  20. star_slash = '*/';
  21.  
  22. not_eol = [all - [cr + lf]];
  23. not_star = [all - '*'];
  24. not_star_slash = [not_star - '/'];
  25.  
  26. line_comment = double_slash not_eol* eol;
  27. block_comment = slash_star not_star* '*'+ (not_star_slash not_star* '*'+)* '/';
  28.  
  29. Tokens
  30. directive_prefix = '\';
  31.  
  32. set_argc = 'set_argc';
  33.  
  34. modifier = 'stack' | 'static';
  35.  
  36. const = 'const';
  37.  
  38. conditional_start_section_keyword = 'if' | 'unless';
  39. conditional_middle_section_keyword = 'elsif' | 'elsunless';
  40. else = 'else';
  41.  
  42. loop = 'loop';
  43. conditional_iterative_section_keyword = 'while' | 'until';
  44. repeat = 'repeat';
  45.  
  46. goto = 'goto';
  47.  
  48. exit = 'exit';
  49. return = 'return';
  50. continue = 'continue';
  51. break = 'break';
  52.  
  53. equals = '=';
  54.  
  55. l_par = '(';
  56. r_par = ')';
  57. l_bracket = '[';
  58. r_bracket = ']';
  59. l_brace = '{';
  60. r_brace = '}';
  61. comma = ',';
  62. colon = ':';
  63. semicolon = ';';
  64.  
  65. dereference = '#';
  66. address_of = '@';
  67.  
  68. logical_and = '&&';
  69. logical_or = '||';
  70. logical_xor = '^^';
  71.  
  72. equal_to = '==';
  73. not_equal_to = '!=';
  74.  
  75. less_than = '<';
  76. less_or_equal = '<=';
  77. more_than = '>';
  78. more_or_equal = '>=';
  79.  
  80. plus = '+';
  81. and = '&';
  82. or = '|';
  83. xor = '^';
  84. minus = '-';
  85.  
  86. arithmetic_left_shift = '<<';
  87. arithmetic_right_shift = '>>';
  88. logical_right_shift = '>>>';
  89. circular_left_shift = '<</';
  90. circular_right_shift = '>>/';
  91.  
  92. multiply = '*';
  93. divide = '/';
  94. remainder = '%';
  95.  
  96. complement = '~';
  97. to_bool = '?';
  98. not = '!';
  99.  
  100. name = letter name_char*;
  101.  
  102. integer = sign? digit+;
  103. character = apostrophe not_eol apostrophe;
  104.  
  105. blank = separator+;
  106. comment = line_comment | block_comment;
  107.  
  108. Ignored Tokens
  109. blank,
  110. comment;
  111.  
  112. Productions
  113. unit =
  114. setup program;
  115.  
  116. setup =
  117. setup_section*;
  118.  
  119. program =
  120. program_section*;
  121.  
  122.  
  123.  
  124. /* UNIT SPECIFICATION */
  125.  
  126. setup_section =
  127. {directive_call} directive_call;
  128.  
  129. directive_call =
  130. directive_prefix directive semicolon;
  131.  
  132. directive =
  133. {set_argc} set_argc l_par expression r_par;
  134.  
  135. program_section =
  136. {function_declaration} function_declaration |
  137. {function_definition} function_definition |
  138. {basic_section} basic_section;
  139.  
  140. basic_section =
  141. {empty_statement} empty_statement |
  142. {constant_definition} constant_definition |
  143. {variable_declaration} variable_declaration |
  144. {assignment_statement} assignment_statement |
  145. {expression_statement} expression_statement |
  146. {conditional_section} conditional_section |
  147. {iterative_section} iterative_section |
  148. {goto_statement} goto_statement |
  149. {section_label} section_label;
  150.  
  151.  
  152.  
  153. /* SECTION SPECIFICATIONS */
  154.  
  155. function_declaration =
  156. type function_name par_parameter_list semicolon;
  157.  
  158. function_definition =
  159. modifier* type function_name par_parameter_list l_brace basic_section* stop_statement? r_brace;
  160.  
  161. empty_statement =
  162. semicolon;
  163.  
  164. constant_definition =
  165. const type constant_name equals expression semicolon;
  166.  
  167. variable_declaration =
  168. {excluding_initialization} type variable_lvalue semicolon |
  169. {including_initialization} type variable_lvalue equals expression semicolon;
  170.  
  171. assignment_statement =
  172. variable_lvalue equals expression semicolon;
  173.  
  174. expression_statement =
  175. {function} function semicolon;
  176.  
  177. conditional_section =
  178. conditional_start_section conditional_middle_section* else_section?;
  179.  
  180. conditional_start_section =
  181. conditional_start_section_keyword expression l_brace basic_section* stop_statement? r_brace;
  182.  
  183. conditional_middle_section =
  184. conditional_middle_section_keyword expression l_brace basic_section* stop_statement? r_brace;
  185.  
  186. else_section =
  187. else l_brace basic_section* stop_statement? r_brace;
  188.  
  189. iterative_section =
  190. {loop} loop l_brace basic_section* stop_statement? r_brace |
  191. {conditional} conditional_iterative_section_keyword expression l_brace basic_section* stop_statement? r_brace |
  192. {repeat_conditional} repeat l_brace basic_section* stop_statement? r_brace conditional_iterative_section_keyword expression semicolon;
  193.  
  194. goto_statement =
  195. goto label_name semicolon;
  196.  
  197. section_label =
  198. label_name colon;
  199.  
  200. stop_statement =
  201. {exit} exit semicolon dead_section* |
  202. {return} return semicolon dead_section* |
  203. {continue} continue semicolon dead_section* |
  204. {break} break semicolon dead_section* |
  205. {exit_expression} exit expression semicolon dead_section* |
  206. {return_expression} return expression semicolon dead_section*;
  207.  
  208. dead_section =
  209. {dead0} basic_section |
  210. {dead1} exit semicolon |
  211. {dead2} return semicolon |
  212. {dead3} continue semicolon |
  213. {dead4} break semicolon |
  214. {dead5} exit expression semicolon |
  215. {dead6} return expression semicolon;
  216.  
  217.  
  218.  
  219. /* COMPONENT SPECIFICATIONS */
  220.  
  221. type =
  222. {basic} address_of* type_name |
  223. {function} address_of* l_par type r_par par_parameter_list;
  224.  
  225. par_parameter_list =
  226. l_par parameter_list? r_par;
  227.  
  228. parameter_list =
  229. type variable_lvalue? parameter_list_tail*;
  230.  
  231. parameter_list_tail =
  232. comma type variable_lvalue?;
  233.  
  234. variable_lvalue =
  235. dereference* variable_name;
  236.  
  237. expression =
  238. expression0;
  239.  
  240. expression0 =
  241. {prioritized} expression1 |
  242. {binary} expression0 logical_binary_op expression1;
  243.  
  244. expression1 =
  245. {prioritized} expression2 |
  246. {binary} expression1 equality_binary_op expression2;
  247.  
  248. expression2 =
  249. {prioritized} expression3 |
  250. {binary} expression2 comparative_binary_op expression3;
  251.  
  252. expression3 =
  253. {prioritized} expression4 |
  254. {binary} expression3 additive_binary_op expression4;
  255.  
  256. expression4 =
  257. {prioritized} expression5 |
  258. {binary} expression4 shift_binary_op expression5;
  259.  
  260. expression5 =
  261. {prioritized} expression6 |
  262. {binary} expression5 multiplicative_binary_op expression6;
  263.  
  264. expression6 =
  265. {prioritized} expression7 |
  266. {unary} unary_op expression6 |
  267. {dereference} dereference expression6 |
  268. {address_of} address_of variable_name;
  269.  
  270. expression7 =
  271. {prioritized} expression8 |
  272. {function} function;
  273.  
  274. expression8 =
  275. {value} value |
  276. {variable} variable_name |
  277. {parentheses} l_par expression0 r_par;
  278.  
  279. value =
  280. {integer} integer |
  281. {character} character;
  282.  
  283. function =
  284. expression7 l_par argument_list? r_par;
  285.  
  286. argument_list =
  287. expression argument_list_tail*;
  288.  
  289. argument_list_tail =
  290. comma expression;
  291.  
  292. type_name =
  293. name;
  294.  
  295. function_name =
  296. name;
  297.  
  298. constant_name =
  299. name;
  300.  
  301. variable_name =
  302. name;
  303.  
  304. label_name =
  305. name;
  306.  
  307.  
  308.  
  309. /* OPERATION SPECIFICATIONS */
  310.  
  311. logical_binary_op =
  312. {logical_and} logical_and |
  313. {logical_or} logical_or |
  314. {logical_xor} logical_xor;
  315.  
  316. equality_binary_op =
  317. {equal_to} equal_to |
  318. {not_equal_to} not_equal_to;
  319.  
  320. comparative_binary_op =
  321. {less_than} less_than |
  322. {less_or_equal} less_or_equal |
  323. {more_than} more_than |
  324. {more_or_equal} more_or_equal;
  325.  
  326. additive_binary_op =
  327. {plus} plus |
  328. {and} and |
  329. {or} or |
  330. {xor} xor |
  331. {minus} minus;
  332.  
  333. shift_binary_op =
  334. {arithmetic_left_shift} arithmetic_left_shift |
  335. {arithmetic_right_shift} arithmetic_right_shift |
  336. {logical_right_shift} logical_right_shift |
  337. {circular_left_shift} circular_left_shift |
  338. {circular_right_shift} circular_right_shift;
  339.  
  340. multiplicative_binary_op =
  341. {multiply} multiply |
  342. {divide} divide |
  343. {remainder} remainder;
  344.  
  345. unary_op =
  346. {plus} plus |
  347. {minus} minus |
  348. {complement} complement |
  349. {to_bool} to_bool |
  350. {not} not;
  351.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement