Advertisement
Guest User

Untitled

a guest
Jun 16th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.52 KB | None | 0 0
  1. module Foo {
  2. language Pipetest {
  3. interleave Whitespace = ' ' | '\t' | '\n' | '\r';
  4.  
  5. token Identifier = ('a'..'z'|'A'..'Z'|'_')+;
  6.  
  7. syntax ExprPrimary(HigherPrec)
  8. = ident:Identifier => Identifier { ident }
  9. | '(' e:HigherPrec ')' => e
  10. ;
  11.  
  12. syntax ExpressionList(Expr)
  13. = e:Expr => [e]
  14. | lhs:ExpressionList(Expr) ',' rhs:Expr
  15. => [valuesof(lhs),rhs]
  16. ;
  17.  
  18. syntax ExprPostfix(HigherPrec, Expr)
  19. = e:HigherPrec => e
  20. | lhs:(ExprPostfix(HigherPrec, Expr)) "++"
  21. => PostfixInc { valuesof(lhs) }
  22. | lhs:(ExprPostfix(HigherPrec, Expr)) "--"
  23. => PostfixDec { valuesof(lhs) }
  24. | lhs:(ExprPostfix(HigherPrec, Expr)) '(' rhs:ExpressionList(Expr)? ')'
  25. => FunctionCall { valuesof(lhs), rhs }
  26. | lhs:(ExprPostfix(HigherPrec, Expr)) '[' rhs:ExpressionList(Expr)? ']'
  27. => Subscript { valuesof(lhs), rhs }
  28. | lhs:(ExprPostfix(HigherPrec, Expr)) '.' rhs:Identifier
  29. => MemberAccess { valuesof(lhs), rhs }
  30. | lhs:(ExprPostfix(HigherPrec, Expr)) "->" rhs:Identifier
  31. => PointerMemberAccess { valuesof(lhs), rhs }
  32. ;
  33.  
  34. syntax ExprUnary(HigherPrec)
  35. = e:HigherPrec => e
  36. | '-' rhs:(ExprUnary(HigherPrec))
  37. => Neg { valuesof(rhs) }
  38. | '+' rhs:(ExprUnary(HigherPrec))
  39. => Pos { valuesof(rhs) }
  40. | '!' rhs:(ExprUnary(HigherPrec))
  41. => Not { valuesof(rhs) }
  42. | '~' rhs:(ExprUnary(HigherPrec))
  43. => Complement { valuesof(rhs) }
  44. | "++" rhs:(ExprUnary(HigherPrec))
  45. => PrefixInc { valuesof(rhs) }
  46. | "--" rhs:(ExprUnary(HigherPrec))
  47. => PrefixDec { valuesof(rhs) }
  48. | '*' rhs:(ExprUnary(HigherPrec))
  49. => Dereference { valuesof(rhs) }
  50. | '&' rhs:(ExprUnary(HigherPrec))
  51. => AddressOf { valuesof(rhs) }
  52. ;
  53.  
  54. syntax ExprPointerToMember(HigherPrec)
  55. = e:HigherPrec => e
  56. | lhs:(ExprPointerToMember(HigherPrec)) ".*" rhs:HigherPrec
  57. => PointerToMember { valuesof(lhs), rhs }
  58. | lhs:(ExprPointerToMember(HigherPrec)) "->*" rhs:HigherPrec
  59. => PointerToPointerMember { valuesof(lhs), rhs }
  60. ;
  61.  
  62. syntax ExprMultiplicative(HigherPrec)
  63. = e:HigherPrec => e
  64. | lhs:(ExprMultiplicative(HigherPrec)) '*' rhs:HigherPrec
  65. => Mul { valuesof(lhs), rhs }
  66. | lhs:(ExprMultiplicative(HigherPrec)) '/' rhs:HigherPrec
  67. => Div { valuesof(lhs), rhs }
  68. | lhs:(ExprMultiplicative(HigherPrec)) '%' rhs:HigherPrec
  69. => Mod { valuesof(lhs), rhs }
  70. ;
  71.  
  72. syntax ExprAdditive(HigherPrec)
  73. = e:HigherPrec => e
  74. | lhs:(ExprAdditive(HigherPrec)) '+' rhs:HigherPrec
  75. => Add { valuesof(lhs), rhs }
  76. | lhs:(ExprAdditive(HigherPrec)) '-' rhs:HigherPrec
  77. => Sub { valuesof(lhs), rhs }
  78. ;
  79.  
  80. syntax ExprShift(HigherPrec)
  81. = e:HigherPrec => e
  82. | lhs:(ExprShift(HigherPrec)) "<<" rhs:HigherPrec
  83. => Shl { valuesof(lhs), rhs }
  84. | lhs:(ExprShift(HigherPrec)) ">>" rhs:HigherPrec
  85. => Shr { valuesof(lhs), rhs }
  86. ;
  87.  
  88. syntax ExprCompare(HigherPrec)
  89. = e:HigherPrec => e
  90. | lhs:HigherPrec "<=>" rhs:HigherPrec
  91. => Compare { lhs, rhs }
  92. ;
  93.  
  94. syntax ExprRelational(HigherPrec)
  95. = e:HigherPrec => e
  96. | lhs:HigherPrec '<' rhs:HigherPrec => Lt { lhs, rhs }
  97. | lhs:HigherPrec '>' rhs:HigherPrec => Gt { lhs, rhs }
  98. | lhs:HigherPrec "<=" rhs:HigherPrec => Le { lhs, rhs }
  99. | lhs:HigherPrec ">=" rhs:HigherPrec => Ge { lhs, rhs }
  100. ;
  101.  
  102. syntax ExprEquality(HigherPrec)
  103. = e:HigherPrec => e
  104. | lhs:HigherPrec "==" rhs:HigherPrec => Eq { lhs, rhs }
  105. | lhs:HigherPrec "!=" rhs:HigherPrec => Ne { lhs, rhs }
  106. ;
  107.  
  108. syntax ExprBitwiseAnd(HigherPrec)
  109. = e:HigherPrec => e
  110. | lhs:(ExprBitwiseAnd(HigherPrec)) '&' rhs:HigherPrec
  111. => BitwiseAnd { valuesof(lhs), rhs }
  112. ;
  113.  
  114. syntax ExprBitwiseXor(HigherPrec)
  115. = e:HigherPrec => e
  116. | lhs:(ExprBitwiseXor(HigherPrec)) '^' rhs:HigherPrec
  117. => BitwiseXor { valuesof(lhs), rhs }
  118. ;
  119.  
  120. syntax ExprBitwiseOr(HigherPrec)
  121. = e:HigherPrec => e
  122. | lhs:(ExprBitwiseOr(HigherPrec)) '|' rhs:HigherPrec
  123. => BitwiseOr { valuesof(lhs), rhs }
  124. ;
  125.  
  126. syntax ExprLogicalAnd(HigherPrec)
  127. = e:HigherPrec => e
  128. | lhs:(ExprLogicalAnd(HigherPrec)) "&&" rhs:HigherPrec
  129. => LogicalAnd { valuesof(lhs), rhs }
  130. ;
  131.  
  132. syntax ExprLogicalOr(HigherPrec)
  133. = e:HigherPrec => e
  134. | lhs:(ExprLogicalOr(HigherPrec)) "||" rhs:HigherPrec
  135. => LogicalOr { valuesof(lhs), rhs }
  136. ;
  137.  
  138. syntax ExprAssign(HigherPrec)
  139. = e:HigherPrec => e
  140. | lhs:HigherPrec "=" rhs:(ExprAssign(HigherPrec))
  141. => Assign { lhs, valuesof(rhs) }
  142. | lhs:HigherPrec "+=" rhs:(ExprAssign(HigherPrec))
  143. => AddAssign { lhs, valuesof(rhs) }
  144. | lhs:HigherPrec "-=" rhs:(ExprAssign(HigherPrec))
  145. => SubAssign { lhs, valuesof(rhs) }
  146. | lhs:HigherPrec "*=" rhs:(ExprAssign(HigherPrec))
  147. => MulAssign { lhs, valuesof(rhs) }
  148. | lhs:HigherPrec "/=" rhs:(ExprAssign(HigherPrec))
  149. => DivAssign { lhs, valuesof(rhs) }
  150. | lhs:HigherPrec "%=" rhs:(ExprAssign(HigherPrec))
  151. => ModAssign { lhs, valuesof(rhs) }
  152. | lhs:HigherPrec "<<=" rhs:(ExprAssign(HigherPrec))
  153. => ShlAssign { lhs, valuesof(rhs) }
  154. | lhs:HigherPrec ">>=" rhs:(ExprAssign(HigherPrec))
  155. => ShrAssign { lhs, valuesof(rhs) }
  156. | lhs:HigherPrec "&=" rhs:(ExprAssign(HigherPrec))
  157. => AndAssign { lhs, valuesof(rhs) }
  158. | lhs:HigherPrec "^=" rhs:(ExprAssign(HigherPrec))
  159. => XorAssign { lhs, valuesof(rhs) }
  160. | lhs:HigherPrec "|=" rhs:(ExprAssign(HigherPrec))
  161. => OrAssign { lhs, valuesof(rhs) }
  162. ;
  163.  
  164.  
  165.  
  166. syntax ExpressionCPP
  167. = e:
  168. ExprAssign(
  169. ExprLogicalOr(
  170. ExprLogicalAnd(
  171. ExprBitwiseOr(
  172. ExprBitwiseXor(
  173. ExprBitwiseAnd(
  174. ExprEquality(
  175. ExprRelational(
  176. ExprCompare(
  177. ExprShift(
  178. ExprAdditive(
  179. ExprMultiplicative(
  180. ExprPointerToMember(
  181. ExprUnary(
  182. ExprPostfix(
  183. ExprPrimary(
  184. ExpressionCPP
  185. ),
  186. ExpressionCPP
  187. )
  188. )
  189. )
  190. )
  191. )
  192. )
  193. )
  194. )
  195. )
  196. )
  197. )
  198. )
  199. )
  200. )
  201. ) => e
  202. ;
  203.  
  204. syntax ExprPostfixWithPipe(HigherPrec, Expr)
  205. = e:HigherPrec => e
  206. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "|>" rhs:HigherPrec '(' e:ExpressionList(Expr)? ')'
  207. => Pipe { valuesof(lhs), FunctionCall { rhs, e } }
  208. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "++"
  209. => PostfixInc { valuesof(lhs) }
  210. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "--"
  211. => PostfixDec { valuesof(lhs) }
  212. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '(' ExpressionList(Expr)? ')'
  213. => FunctionCall { valuesof(lhs) }
  214. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '[' ExpressionList(Expr)? ']'
  215. => Subscript { valuesof(lhs) }
  216. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) '.' rhs:Identifier
  217. => MemberAccess { valuesof(lhs), rhs }
  218. | lhs:(ExprPostfixWithPipe(HigherPrec, Expr)) "->" rhs:Identifier
  219. => PointerMemberAccess { valuesof(lhs), rhs }
  220.  
  221. ;
  222.  
  223. syntax ExpressionR0
  224. = e:
  225. ExprAssign(
  226. ExprLogicalOr(
  227. ExprLogicalAnd(
  228. ExprBitwiseOr(
  229. ExprBitwiseXor(
  230. ExprBitwiseAnd(
  231. ExprEquality(
  232. ExprRelational(
  233. ExprCompare(
  234. ExprShift(
  235. ExprAdditive(
  236. ExprMultiplicative(
  237. ExprPointerToMember(
  238. ExprUnary(
  239. ExprPostfixWithPipe(
  240. ExprPrimary(
  241. ExpressionR0
  242. ),
  243. ExpressionR0
  244. )
  245. )
  246. )
  247. )
  248. )
  249. )
  250. )
  251. )
  252. )
  253. )
  254. )
  255. )
  256. )
  257. )
  258. ) => e
  259. ;
  260.  
  261. syntax ExprPipe(HigherPrec)
  262. = e:HigherPrec => e
  263. | lhs:(ExprPipe(HigherPrec)) "|>" rhs:HigherPrec
  264. => Pipe { valuesof(lhs), rhs }
  265. ;
  266.  
  267. syntax ExpressionR1
  268. = e: ExprAssign(
  269. ExprLogicalOr(
  270. ExprLogicalAnd(
  271. ExprBitwiseOr(
  272. ExprBitwiseXor(
  273. ExprBitwiseAnd(
  274. ExprEquality(
  275. ExprRelational(
  276. ExprCompare(
  277. ExprShift(
  278. ExprAdditive(
  279. ExprMultiplicative(
  280. ExprPipe(
  281. ExprPointerToMember(
  282. ExprUnary(
  283. ExprPostfix(
  284. ExprPrimary(
  285. ExpressionR1
  286. ),
  287. ExpressionR1
  288. )
  289. )
  290. )
  291. )
  292. )
  293. )
  294. )
  295. )
  296. )
  297. )
  298. )
  299. )
  300. )
  301. )
  302. )
  303. ) => e
  304. ;
  305.  
  306.  
  307. syntax ExprPipe(HigherPrecLeft, HigherPrecRight)
  308. = e:HigherPrecLeft => e
  309. | lhs:(ExprPipe(HigherPrecLeft, HigherPrecRight)) "|>" rhs:HigherPrecRight
  310. => Pipe { valuesof(lhs), rhs }
  311. ;
  312.  
  313. syntax ExprLimitedToPM(Expr)
  314. = e:ExprPointerToMember(
  315. ExprUnary(
  316. ExprPostfix(
  317. ExprPrimary(
  318. ExprLimitedToPM(Expr)
  319. ),
  320. Expr
  321. )
  322. )
  323. ) => e
  324. ;
  325.  
  326. syntax ExpressionRx
  327. = e: ExprAssign(
  328. ExprPipe(
  329. ExprLogicalOr(
  330. ExprLogicalAnd(
  331. ExprBitwiseOr(
  332. ExprBitwiseXor(
  333. ExprBitwiseAnd(
  334. ExprEquality(
  335. ExprRelational(
  336. ExprCompare(
  337. ExprShift(
  338. ExprAdditive(
  339. ExprMultiplicative(
  340. ExprPointerToMember(
  341. ExprUnary(
  342. ExprPostfix(
  343. ExprPrimary(
  344. ExpressionRx
  345. ),
  346. ExpressionRx
  347. )
  348. )
  349. )
  350. )
  351. )
  352. )
  353. )
  354. )
  355. )
  356. )
  357. )
  358. )
  359. )
  360. ),
  361. ExprLimitedToPM(ExpressionRx)
  362. )
  363. ) => e
  364. ;
  365.  
  366. syntax CompilationUnit
  367. = "#pragma CPP" e:(e:ExpressionCPP "\r\n" => e)*
  368. => CPPExpressions [ valuesof(e) ]
  369. | "#pragma R0" e:(e:ExpressionR0 "\r\n" => e)*
  370. => R0Expressions [ valuesof(e) ]
  371. | "#pragma R1" e:(e:ExpressionR1 "\r\n" => e)*
  372. => R1Expressions [ valuesof(e) ]
  373. | "#pragma Rx" e:(e:ExpressionRx "\r\n" => e)*
  374. => RxExpressions [ valuesof(e) ]
  375. ;
  376.  
  377.  
  378. syntax Main
  379. = c:("----\r\n" c:CompilationUnit => c)*
  380. => CompilationUnits [ valuesof(c) ]
  381. ;
  382. }
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement