Advertisement
tomdodd4598

Untitled

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