objm2.g 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /* ANTLR v3 Grammar for Objective Modula-2, status: May 24, 2010
  2. *
  3. * Copyright (C) 2010 Benjamin Kowarsch. All rights reserved.
  4. *
  5. * License:
  6. *
  7. * Permission is hereby granted to review and test this software for the sole
  8. * purpose of supporting the effort by the licensor to define and develop the
  9. * Objective Modula-2 language. It is not permissible under any circumstances
  10. * to use the software for the purpose of creating derivative languages or
  11. * dialects. This permission is valid until 31 December 2010, 24:00h GMT.
  12. *
  13. * Future licensing:
  14. *
  15. * The licensor undertakes to eventually release this software under a proper
  16. * open source license AFTER the Objective Modula-2 language definition has
  17. * been finalised and a conforming and working reference compiler completed.
  18. *
  19. * More information about Objective Modula-2:
  20. *
  21. * http://objective.modula2.net
  22. *
  23. */
  24. grammar objm2; // Objective Modula-2
  25. // Note: An empty semantic action {} is used in lists of alternative terminals
  26. // in order to make ANTLRworks display the alternatives as separate branches.
  27. // A trailing comment /* extension */ is used within rules to indicate rules
  28. // or lines which represent Objective Modula-2 specific language extensions.
  29. options {
  30. // *** strict LL(1) ***
  31. backtrack = no;
  32. k = 1;
  33. }
  34. tokens {
  35. // *** R10 Core Language Reserved Words, 42 tokens ***
  36. ALIAS = 'ALIAS';
  37. AND = 'AND';
  38. ARRAY = 'ARRAY';
  39. ASSOCIATIVE = 'ASSOCIATIVE';
  40. BEGIN = 'BEGIN';
  41. BINDINGS = 'BINDINGS';
  42. BY = 'BY';
  43. CASE = 'CASE';
  44. CONST = 'CONST';
  45. DEFINITION = 'DEFINITION';
  46. DIV = 'DIV';
  47. DO = 'DO';
  48. ELSE = 'ELSE';
  49. ELSIF = 'ELSIF';
  50. END = 'END';
  51. EXIT = 'EXIT';
  52. FOR = 'FOR';
  53. FROM = 'FROM';
  54. IF = 'IF';
  55. IMPLEMENTATION = 'IMPLEMENTATION';
  56. IMPORT = 'IMPORT';
  57. IN = 'IN';
  58. LOOP = 'LOOP';
  59. MOD = 'MOD';
  60. MODULE = 'MODULE';
  61. NOT = 'NOT';
  62. OF = 'OF';
  63. OPAQUE = 'OPAQUE';
  64. OR = 'OR';
  65. POINTER = 'POINTER';
  66. PROCEDURE = 'PROCEDURE';
  67. RECORD = 'RECORD';
  68. REPEAT = 'REPEAT';
  69. RETURN = 'RETURN';
  70. SET = 'SET';
  71. THEN = 'THEN';
  72. TO = 'TO';
  73. TYPE = 'TYPE';
  74. UNTIL = 'UNTIL';
  75. VAR = 'VAR';
  76. VARIADIC = 'VARIADIC';
  77. WHILE = 'WHILE';
  78. // *** Objective Modula-2 Reserved Words, 16 tokens ***
  79. BYCOPY = 'BYCOPY';
  80. BYREF = 'BYREF';
  81. CLASS = 'CLASS';
  82. CONTINUE = 'CONTINUE';
  83. CRITICAL = 'CRITICAL';
  84. INOUT = 'INOUT';
  85. METHOD = 'METHOD';
  86. ON = 'ON';
  87. OPTIONAL = 'OPTIONAL';
  88. OUT = 'OUT';
  89. PRIVATE = 'PRIVATE';
  90. PROTECTED = 'PROTECTED';
  91. PROTOCOL = 'PROTOCOL';
  92. PUBLIC = 'PUBLIC';
  93. SUPER = 'SUPER';
  94. TRY = 'TRY';
  95. // *** R10 Core Language Defined Pragma Identifiers, 10 tokens ***
  96. IF = 'IF';
  97. ELSIF = 'ELSIF';
  98. ELSE = 'ELSE';
  99. ENDIF = 'ENDIF';
  100. INFO = 'INFO';
  101. WARN = 'WARN';
  102. ERROR = 'ERROR';
  103. FATAL = 'FATAL';
  104. ALIGN = 'ALIGN';
  105. FOREIGN = 'FOREIGN';
  106. MAKE = 'MAKE';
  107. INLINE = 'INLINE';
  108. NOINLINE = 'NOINLINE';
  109. VOLATILE = 'VOLATILE';
  110. // *** Objective Modula-2 Defined Pragma Identifiers, 4 tokens ***
  111. FRAMEWORK = 'FRAMEWORK';
  112. IBACTION = 'IBAction';
  113. IBOUTLET = 'IBOutlet';
  114. QUALIFIED = 'QUALIFIED';
  115. // *** Special Characters, 3 tokens ***
  116. BACKSLASH = '\\';
  117. SINGLE_QUOTE = '\'';
  118. DOUBLE_QUOTE = '\"';
  119. // *** Ignore Characters, 3 tokens ***
  120. ASCII_TAB = '\t';
  121. ASCII_LF = '\n';
  122. ASCII_CR = '\r';
  123. }
  124. // ---------------------------------------------------------------------------
  125. // N O N - T E R M I N A L S Y M B O L S
  126. // ---------------------------------------------------------------------------
  127. // 78 productions, 25 aliases
  128. // *** Compilation Units ***
  129. // production #1
  130. compilationUnit :
  131. programModule | definitionOfBindings |
  132. definitionOfModule | implementationOfModule |
  133. protocolModule /* extension */
  134. ;
  135. // production #2
  136. definitionOfBindings :
  137. BINDINGS FOR semanticType ';'
  138. bindingsHeader bindings*
  139. END semanticType '.'
  140. ;
  141. // production #3
  142. programModule :
  143. MODULE moduleId ( '[' priority ']' )? ';'
  144. importList* block moduleId '.'
  145. ;
  146. // production #4
  147. definitionOfModule :
  148. DEFINITION MODULE moduleId ( '[' semanticType ']' )? ';'
  149. importList* definition*
  150. END moduleId '.'
  151. ;
  152. // production #5
  153. implementationOfModule :
  154. IMPLEMENTATION programModule
  155. ;
  156. // production #6
  157. protocolModule : /* extension */
  158. PROTOCOL protocolId ( '(' adoptedProtocols ')' )? ';'
  159. importList* ( OPTIONAL? methodHeader ';' )*
  160. END protocolId '.'
  161. ;
  162. // alias
  163. moduleId : ident ;
  164. // alias
  165. priority : constExpression ;
  166. // alias
  167. semanticType : ident ;
  168. // alias
  169. protocolId : ident ;
  170. // alias
  171. adoptedProtocols : identList ;
  172. // *** Bindings, Import Lists, Blocks, Declarations, Definitions ***
  173. // production #7
  174. bindingsHeader :
  175. TYPE '=' ( RECORD | OPAQUE RECORD? ( ':=' ( literalType | '{' '}' ) )? ) ';'
  176. ;
  177. // production #8
  178. bindings :
  179. ( CONST '[' bindableIdent ']' |
  180. PROCEDURE '[' ( bindableOperator | bindableIdent ) ']' ) ';'
  181. ;
  182. // production #9
  183. bindableOperator :
  184. DIV | MOD | IN | FOR | TO | FROM |
  185. ':=' | '::' | '.' | '!' | '+' | '-' | '*' | '/' | '=' | '<' | '>'
  186. {} // make ANTLRworks display separate branches
  187. ;
  188. // alias
  189. bindableIdent : ident ;
  190. // TMIN, TMAX, ABS, NEG, ODD, COUNT, LENGTH, NEW, DISPOSE
  191. // alias
  192. literalType : ident ;
  193. // production #10
  194. importList :
  195. ( FROM moduleId IMPORT ( identList | '*' ) |
  196. IMPORT ident '+'? ( ',' ident '+'? )* ) ';'
  197. ;
  198. // production #11
  199. block :
  200. declaration*
  201. ( BEGIN statementSequence )? END
  202. ;
  203. // production #12
  204. declaration :
  205. CONST ( constantDeclaration ';' )* |
  206. TYPE ( ident '=' type ';' )* |
  207. VAR ( variableDeclaration ';' )* |
  208. procedureDeclaration ';'
  209. ;
  210. // production #13
  211. definition :
  212. CONST ( ( '[' ident ']' )? constantDeclaration ';' )* |
  213. TYPE ( ident '=' ( type | OPAQUE recordType? ) ';' )* |
  214. VAR ( variableDeclaration ';' )* |
  215. procedureHeader ';'
  216. ;
  217. // *** Constant Declarations ***
  218. // production #14
  219. constantDeclaration :
  220. ident '=' constExpression // no type identifiers
  221. ;
  222. // *** Type Declarations ***
  223. // production #15
  224. type :
  225. ( ALIAS OF | '[' constExpression '..' constExpression ']' OF )? namedType |
  226. anonymousType | enumerationType | recordType | setType |
  227. classType /* extension */
  228. ;
  229. // alias
  230. namedType : qualident ;
  231. // production #16
  232. anonymousType :
  233. arrayType | pointerType | procedureType
  234. ;
  235. // production #17
  236. enumerationType :
  237. '(' ( ( '+' namedType ) | ident ) ( ',' ( ( '+' namedType ) | ident ) )* ')'
  238. ;
  239. // production #18
  240. arrayType :
  241. ( ARRAY arrayIndex ( ',' arrayIndex )* | ASSOCIATIVE ARRAY )
  242. OF ( namedType | pointerType | procedureType )
  243. ;
  244. // alias
  245. arrayIndex : ordinalConstExpression ;
  246. // alias
  247. ordinalConstExpression : constExpression ;
  248. // production #19
  249. recordType :
  250. RECORD ( '(' baseType ')' )? fieldListSequence? END
  251. ;
  252. // alias
  253. baseType : ident ;
  254. // production #20
  255. fieldListSequence :
  256. fieldList ( ';' fieldList )*
  257. ;
  258. // production #21
  259. fieldList :
  260. identList ':'
  261. ( namedType | arrayType | pointerType | procedureType )
  262. ;
  263. // production #22
  264. classType : /* extension */
  265. '<*QUALIFIED*>'? CLASS '(' superClass ( ',' adoptedProtocols )? ')'
  266. ( ( PUBLIC | MODULE | PROTECTED | PRIVATE {})?
  267. fieldListSequence )*
  268. END
  269. ;
  270. // alias
  271. superClass : qualident ;
  272. // production #23
  273. setType :
  274. SET OF ( namedEnumType | '(' identList ')' )
  275. ;
  276. // alias
  277. namedEnumType : namedType ;
  278. // production #24
  279. pointerType :
  280. POINTER TO CONST? namedType
  281. ;
  282. // production #25
  283. procedureType :
  284. PROCEDURE
  285. ( '(' formalTypeList ')' )?
  286. ( ':' returnedType )?
  287. ;
  288. // production #26
  289. formalTypeList :
  290. attributedFormalType ( ',' attributedFormalType )*
  291. ;
  292. // production #27
  293. attributedFormalType :
  294. ( CONST | VAR {})? formalType
  295. ;
  296. // production #28
  297. formalType :
  298. ( ARRAY OF )? namedType
  299. ;
  300. // alias
  301. returnedType : namedType ;
  302. // *** Variable Declarations ***
  303. // production #30
  304. variableDeclaration :
  305. ident ( '[' machineAddress ']' | ',' identList )?
  306. ':' ( namedType | anonymousType )
  307. ;
  308. // alias
  309. machineAddress : constExpression ;
  310. // *** Procedure Declarations ***
  311. // production #31
  312. procedureDeclaration :
  313. procedureHeader ';' block ident
  314. ;
  315. // production #32
  316. procedureHeader :
  317. PROCEDURE
  318. ( '[' ( bindableOperator | ident ) ']' )?
  319. ( '(' ident ':' receiverType ')' )?
  320. ident ( '(' formalParamList ')' )? ( ':' returnedType )?
  321. ;
  322. // alias
  323. receiverType : ident ;
  324. // production #33
  325. formalParamList :
  326. formalParams ( ';' formalParams )*
  327. ;
  328. // production #34
  329. formalParams :
  330. simpleFormalParams | variadicFormalParams
  331. ;
  332. // production #35
  333. simpleFormalParams :
  334. ( CONST | VAR {})? identList ':' formalType
  335. ;
  336. // production #36
  337. variadicFormalParams :
  338. VARIADIC ( variadicCounter | '[' variadicTerminator ']' )? OF
  339. ( ( CONST | VAR {})? formalType |
  340. '(' simpleFormalParams ( ';' simpleFormalParams )* ')' )
  341. ;
  342. // alias
  343. variadicCounter : ident ;
  344. // alias
  345. variadicTerminator : constExpression ;
  346. // *** Method Declarations ***
  347. // production #37
  348. methodDeclaration : /* extension */
  349. methodHeader ';' block ident
  350. ;
  351. // production #38
  352. methodHeader : /* extension */
  353. CLASS? METHOD
  354. '(' ident ':' ( receiverClass | '*' ) ')'
  355. ( ident | methodArg ) methodArg*
  356. ( ':' returnedType )?
  357. ;
  358. // alias
  359. receiverClass : qualident ;
  360. // production #39
  361. methodArg : /* extension */
  362. colonIdent '(' ( CONST | VAR {})? ident ':' formalType ')'
  363. ;
  364. // *** Statements ***
  365. // production #40
  366. statement :
  367. ( assignmentOrProcedureCall |
  368. methodInvocation | /* extension */
  369. ifStatement |
  370. caseStatement |
  371. whileStatement |
  372. repeatStatement |
  373. loopStatement |
  374. forStatement |
  375. tryStatement | /* extension */
  376. criticalStatement | /* extension */
  377. RETURN expression? |
  378. EXIT )?
  379. ;
  380. // production #41
  381. statementSequence :
  382. statement ( ';' statement )*
  383. ;
  384. // production #42
  385. methodInvocation : /* extension */
  386. '[' receiver message ']'
  387. ;
  388. // production #43
  389. receiver : /* extension */
  390. ident | methodInvocation
  391. ;
  392. // production #44
  393. message : /* extension */
  394. ident ( colonIdent expression )* |
  395. ( colonIdent expression )+
  396. ;
  397. // production #45
  398. assignmentOrProcedureCall :
  399. designator ( ':=' expression | '++' | '--' | actualParameters )?
  400. ;
  401. // production #46
  402. ifStatement :
  403. IF expression THEN statementSequence
  404. ( ELSIF expression THEN statementSequence )*
  405. ( ELSE statementSequence )?
  406. END
  407. ;
  408. // production #47
  409. caseStatement :
  410. CASE expression OF case ( '|' case )*
  411. ( ELSE statementSequence )?
  412. END
  413. ;
  414. // production #48
  415. case :
  416. caseLabelList ':' statementSequence
  417. ;
  418. // production #49
  419. caseLabelList :
  420. caseLabels ( ',' caseLabels )*
  421. ;
  422. // production #50
  423. caseLabels :
  424. constExpression ( '..' constExpression )?
  425. ;
  426. // production #51
  427. whileStatement :
  428. WHILE expression DO statementSequence END
  429. ;
  430. // production #52
  431. repeatStatement :
  432. REPEAT statementSequence UNTIL expression
  433. ;
  434. // production #53
  435. loopStatement :
  436. LOOP statementSequence END
  437. ;
  438. // production #54
  439. forStatement :
  440. FOR ident
  441. ( IN expression |
  442. ':' namedType ':=' expression TO expression ( BY constExpression )? )
  443. DO statementSequence END
  444. ;
  445. // production #55
  446. tryStatement : /* extension */
  447. TRY statementSequence
  448. ON ident /* NSException */ DO statementSequence
  449. CONTINUE statementSequence
  450. END
  451. ;
  452. // production #56
  453. criticalStatement : /* extension */
  454. CRITICAL '(' classInstance ')'
  455. statementSequence
  456. END
  457. ;
  458. // alias
  459. classInstance : qualident ;
  460. // *** Expressions ***
  461. // production #57
  462. constExpression :
  463. simpleConstExpr ( relation simpleConstExpr )?
  464. ;
  465. // production #58
  466. relation :
  467. '=' | '#' | '<' | '<=' | '>' | '>=' | IN
  468. {} // make ANTLRworks display separate branches
  469. ;
  470. // production #59
  471. simpleConstExpr :
  472. ( '+' | '-' {})? constTerm ( addOperator constTerm )*
  473. ;
  474. // production #60
  475. addOperator :
  476. '+' | '-' | OR
  477. {} // make ANTLRworks display separate branches
  478. ;
  479. // production #61
  480. constTerm :
  481. constFactor ( mulOperator constFactor )*
  482. ;
  483. // production #62
  484. mulOperator :
  485. '*' | '/' | DIV | MOD | AND | '&'
  486. {} // make ANTLRworks display separate branches
  487. ;
  488. // production #63
  489. constFactor :
  490. ( number |
  491. string |
  492. constQualident |
  493. constStructuredValue |
  494. '(' constExpression ')' ) ( '::' namedType )? |
  495. ( NOT | '~' {}) constFactor
  496. ;
  497. // production #64
  498. designator :
  499. qualident designatorTail?
  500. ;
  501. // production #65
  502. designatorTail :
  503. ( ( '[' expressionList ']' | '^' ) ( '.' ident )* )+
  504. ;
  505. // production #66
  506. expressionList :
  507. expression ( ',' expression )*
  508. ;
  509. // production #67
  510. expression :
  511. simpleExpression ( relation simpleExpression )?
  512. ;
  513. // production #68
  514. simpleExpression :
  515. ( '+' | '-' {})? term ( addOperator term )*
  516. ;
  517. // production #69
  518. term :
  519. factor ( mulOperator factor )*
  520. ;
  521. // production #70
  522. factor :
  523. ( number |
  524. string |
  525. structuredValue
  526. designatorOrProcedureCall |
  527. '(' expression ')' ) ( '::' namedType )? |
  528. ( NOT | '~' {}) factor |
  529. methodInvocation /* extension */
  530. ;
  531. // production #71
  532. designatorOrProcedureCall :
  533. qualident designatorTail? actualParameters?
  534. ;
  535. // production #72
  536. actualParameters :
  537. '(' expressionList? ')'
  538. ;
  539. // *** Value Constructors ***
  540. // production #73
  541. constStructuredValue :
  542. '{' ( constValueComponent ( ',' constValueComponent )* )? '}'
  543. ;
  544. // production #74
  545. constValueComponent :
  546. constExpression ( ( BY | '..' {}) constExpression )?
  547. ;
  548. // production #75
  549. structuredValue :
  550. '{' ( valueComponent ( ',' valueComponent )* )? '}'
  551. ;
  552. // production #76
  553. valueComponent :
  554. expression ( ( BY | '..' {}) constExpression )?
  555. ;
  556. // *** Identifiers ***
  557. // production #77
  558. qualident :
  559. ident ( '.' ident )*
  560. ;
  561. // production #78
  562. identList :
  563. ident ( ',' ident )*
  564. ;
  565. // alias
  566. ident : IDENT ;
  567. // alias
  568. constQualident : qualident ; // no type and no variable identifiers
  569. // alias
  570. colonIdent : COLON_IDENT ;
  571. // *** Literals ***
  572. // alias
  573. number : NUMBER ;
  574. // alias
  575. string : STRING ;
  576. // ---------------------------------------------------------------------------
  577. // P R A G M A S Y M B O L S
  578. // ---------------------------------------------------------------------------
  579. // 5 productions, 2 aliases
  580. // *** Pragmas ***
  581. // production #1
  582. pragma :
  583. '<*'
  584. ( conditionalPragma | compileTimeMessagePragma | codeGenerationPragma |
  585. implementationDefinedPragma )
  586. '*>'
  587. ;
  588. // production #2
  589. conditionalPragma :
  590. ( IF | ELSIF {}) constExpression | ELSE | ENDIF
  591. ;
  592. // production #3
  593. compileTimeMessagePragma :
  594. ( INFO | WARN | ERROR | FATAL {}) compileTimeMessage
  595. ;
  596. // production #4
  597. codeGenerationPragma :
  598. ALIGN '=' constExpression | FOREIGN ( '=' string )? | MAKE '=' string |
  599. INLINE | NOINLINE | VOLATILE | FRAMEWORK | IBACTION | IBOUTLET | QUALIFIED
  600. ;
  601. // production #5
  602. implementationDefinedPragma :
  603. pragmaName ( '+' | '-' | '=' ( ident | number ) )?
  604. ;
  605. // alias
  606. compileTimeMessage : string ;
  607. // alias
  608. pragmaName : ident ; // lowercase or camelcase only
  609. // ---------------------------------------------------------------------------
  610. // T E R M I N A L S Y M B O L S
  611. // ---------------------------------------------------------------------------
  612. // 10 productions
  613. // production #1
  614. IDENT :
  615. ( '_' | '$' | LETTER ) ( '_' | '$' | LETTER | DIGIT )*
  616. ;
  617. // production #2
  618. COLON_IDENT : /* extension */
  619. IDENT ':'
  620. ;
  621. // production #3
  622. NUMBER :
  623. // Decimal integer
  624. DIGIT+ |
  625. // Binary integer
  626. BINARY_DIGIT+ 'B' |
  627. // Sedecimal integer
  628. DIGIT SEDECIMAL_DIGIT* ( 'C' | 'H' {}) |
  629. // Real number
  630. DIGIT+ '.' DIGIT+ ( 'E' ( '+' | '-' {})? DIGIT+ )?
  631. ;
  632. // production #4
  633. STRING :
  634. // Proper EBNF for STRING
  635. SINGLE_QUOTE ( CHARACTER | DOUBLE_QUOTE )* SINGLE_QUOTE |
  636. DOUBLE_QUOTE ( CHARACTER | SINGLE_QUOTE )* DOUBLE_QUOTE
  637. //
  638. // Alternative EBNF to make ANTLRworks display the diagram properly
  639. // SINGLE_QUOTE ( CHARACTER | DOUBLE_QUOTE | )+ SINGLE_QUOTE |
  640. // DOUBLE_QUOTE ( CHARACTER | SINGLE_QUOTE | )+ DOUBLE_QUOTE
  641. ;
  642. // production #5
  643. fragment
  644. LETTER :
  645. 'A' .. 'Z' | 'a' .. 'z'
  646. {} // make ANTLRworks display separate branches
  647. ;
  648. // production #6
  649. fragment
  650. DIGIT :
  651. BINARY_DIGIT | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
  652. {} // make ANTLRworks display separate branches
  653. ;
  654. // production #7
  655. fragment
  656. BINARY_DIGIT :
  657. '0' | '1'
  658. {} // make ANTLRworks display separate branches
  659. ;
  660. // production #8
  661. fragment
  662. SEDECIMAL_DIGIT :
  663. DIGIT | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
  664. {} // make ANTLRworks display separate branches
  665. ;
  666. // production #9
  667. fragment
  668. CHARACTER :
  669. DIGIT | LETTER |
  670. // any printable characters other than single and double quote
  671. ' ' | '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | '+' |
  672. ',' | '-' | '.' | ':' | ';' | '<' | '=' | '>' | '?' | '@' |
  673. '[' | ']' | '^' | '_' | '`' | '{' | '|' | '}' | '~' |
  674. ESCAPE_SEQUENCE
  675. ;
  676. // production #10
  677. fragment
  678. ESCAPE_SEQUENCE :
  679. BACKSLASH
  680. ( '0' | 'n' | 'r' | 't' | BACKSLASH | SINGLE_QUOTE | DOUBLE_QUOTE {})
  681. ;
  682. // ---------------------------------------------------------------------------
  683. // I G N O R E S Y M B O L S
  684. // ---------------------------------------------------------------------------
  685. // 6 productions
  686. // *** Whitespace ***
  687. // production #1
  688. WHITESPACE :
  689. ' ' | ASCII_TAB
  690. {} // make ANTLRworks display separate branches
  691. { $channel = HIDDEN; } // ignore
  692. ;
  693. // *** Comments ***
  694. // production #2
  695. COMMENT :
  696. NESTABLE_COMMENT | NON_NESTABLE_COMMENT | SINGLE_LINE_COMMENT
  697. { $channel = HIDDEN; } // ignore
  698. ;
  699. // production #3
  700. fragment
  701. NESTABLE_COMMENT :
  702. '(*'
  703. ( options { greedy=false; }: . )* // anything other than '(*' or '*)'
  704. NESTABLE_COMMENT*
  705. '*)'
  706. ;
  707. // production #4
  708. fragment
  709. NON_NESTABLE_COMMENT :
  710. '/*'
  711. ( options { greedy=false; }: . )* // anything other than '*/'
  712. '*/'
  713. ;
  714. // production #5
  715. fragment
  716. SINGLE_LINE_COMMENT :
  717. '//'
  718. ( options { greedy=false; }: . )* // anything other than EOL
  719. END_OF_LINE
  720. ;
  721. // production #6
  722. fragment
  723. END_OF_LINE :
  724. ASCII_LF ASCII_CR? | ASCII_CR ASCII_LF?
  725. ;
  726. // END OF FILE