Advertisement
Guest User

CS'.g4

a guest
Jul 28th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. grammar CS;
  2. import Unicode;
  3.  
  4. start: namespaceOrTypeName EOF;
  5.  
  6. /**********
  7. *
  8. * Basic Concepts
  9. *
  10. **********/
  11.  
  12. namespaceName
  13. : namespaceOrTypeName
  14. ;
  15.  
  16. typeName
  17. : namespaceOrTypeName
  18. ;
  19.  
  20. namespaceOrTypeName
  21. : Identifier typeArgumentList?
  22. | namespaceOrTypeName '.' Identifier typeArgumentList?
  23. | qualifiedAliasMember
  24. ;
  25.  
  26. /**********
  27. *
  28. * Types
  29. *
  30. **********/
  31.  
  32. type
  33. : (typeName
  34. | simpleType
  35. | enumType
  36. | classType
  37. | interfaceType
  38. | delegateType
  39. | typeParameter
  40. | 'void' '*'
  41. ) ('?' | rankSpecifiers | '*')*
  42. ;
  43.  
  44. valueType
  45. : structType
  46. | enumType
  47. ;
  48.  
  49. structType
  50. : typeName
  51. | simpleType
  52. | nullableType
  53. ;
  54.  
  55. simpleType
  56. : numericType
  57. | 'bool'
  58. ;
  59.  
  60. numericType
  61. : integralType
  62. | floatingPointType
  63. | 'decimal'
  64. ;
  65.  
  66. integralType
  67. : 'sbyte'
  68. | 'byte'
  69. | 'short'
  70. | 'ushort'
  71. | 'int'
  72. | 'uint'
  73. | 'long'
  74. | 'ulong'
  75. | 'char'
  76. ;
  77.  
  78. floatingPointType
  79. : 'float'
  80. | 'double'
  81. ;
  82.  
  83. nullableType
  84. : nonNullableValueType '?'
  85. ;
  86.  
  87. nonNullableValueType
  88. : type
  89. ;
  90.  
  91. enumType
  92. : typeName
  93. ;
  94.  
  95. referenceType
  96. : classType
  97. | interfaceType
  98. | arrayType
  99. | delegateType
  100. ;
  101.  
  102. classType
  103. : typeName
  104. | 'object'
  105. | 'dynamic'
  106. | 'string'
  107. ;
  108.  
  109. interfaceType
  110. : typeName
  111. ;
  112.  
  113. rankSpecifiers
  114. : rankSpecifier
  115. | rankSpecifiers rankSpecifier
  116. ;
  117.  
  118. rankSpecifier
  119. : '[' dimSeparators? ']'
  120. ;
  121.  
  122. dimSeparators
  123. : ','
  124. | dimSeparators ','
  125. ;
  126.  
  127. delegateType
  128. : typeName
  129. ;
  130.  
  131. typeArgumentList
  132. : '<' typeArguments '>'
  133. ;
  134.  
  135. typeArguments
  136. : typeArgument
  137. | typeArguments ',' typeArgument
  138. ;
  139.  
  140. typeArgument
  141. : type
  142. ;
  143.  
  144. typeParameter
  145. : Identifier
  146. ;
  147.  
  148. pointerType
  149. : unmanagedType '*'
  150. | 'void' '*'
  151. ;
  152.  
  153. unmanagedType
  154. : type
  155. ;
  156.  
  157. qualifiedAliasMember
  158. : Identifier '::' Identifier typeArgumentList?
  159. ;
  160.  
  161. arrayType
  162. : nonArrayType rankSpecifiers
  163. ;
  164.  
  165. nonArrayType
  166. : type
  167. ;
  168.  
  169. /**********
  170. *
  171. * Identifiers
  172. *
  173. **********/
  174.  
  175. Identifier
  176. : AvailableIdentifier
  177. | '@' IdentifierOrKeyword
  178. ;
  179.  
  180. AvailableIdentifier
  181. : IdentifierOrKeyword
  182. ;
  183.  
  184. IdentifierOrKeyword
  185. : IdentifierStartCharacter IdentifierPartCharacter*
  186. ;
  187.  
  188. IdentifierStartCharacter
  189. : LetterCharacter
  190. | '_'
  191. ;
  192.  
  193. fragment
  194. IdentifierPartCharacter
  195. : LetterCharacter
  196. | DecimalDigitCharacter
  197. | ConnectingCharacter
  198. | CombiningCharacter
  199. | FormattingCharacter
  200. ;
  201.  
  202. fragment
  203. LetterCharacter
  204. : UNICODE_CLASS_LU
  205. | UNICODE_CLASS_LL
  206. | UNICODE_CLASS_LT
  207. | UNICODE_CLASS_LM
  208. | UNICODE_CLASS_LO
  209. | UNICODE_CLASS_NL
  210. ;
  211.  
  212. fragment
  213. CombiningCharacter
  214. : UNICODE_CLASS_MN
  215. | UNICODE_CLASS_MC
  216. ;
  217.  
  218. fragment
  219. DecimalDigitCharacter
  220. : UNICODE_CLASS_ND
  221. ;
  222.  
  223. fragment
  224. ConnectingCharacter
  225. : UNICODE_CLASS_PC
  226. ;
  227.  
  228. fragment
  229. FormattingCharacter
  230. : UNICODE_CLASS_CF
  231. ;
  232.  
  233. /**********
  234. *
  235. * Whitespace and comments
  236. *
  237. **********/
  238.  
  239. WS : [ \t\r\n\u000C]+ -> skip
  240. ;
  241.  
  242. COMMENT
  243. : '/*' .*? '*/' -> skip
  244. ;
  245.  
  246. LINE_COMMENT
  247. : '//' ~[\r\n]* -> skip
  248. ;
  249.  
  250. DIRECTIVE
  251. : '#' ~[\r\n]* -> skip
  252. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement