stuck-waitfor-destruct
|
Last change
on this file was 2cb10170, checked in by Alvin Zhang <alvin.zhang@…>, 3 weeks ago |
|
stitched modules proposal
|
-
Property mode
set to
100644
|
|
File size:
1.9 KB
|
| Rev | Line | |
|---|
| [2cb10170] | 1 | // C-like language with expressions removed, used to showcase module capabilities
|
|---|
| 2 |
|
|---|
| 3 | grammar CMOD;
|
|---|
| 4 |
|
|---|
| 5 | compilationUnit
|
|---|
| 6 | : translationUnit EOF
|
|---|
| 7 | ;
|
|---|
| 8 |
|
|---|
| 9 | translationUnit
|
|---|
| 10 | : moduleDeclaration importDeclaration* externalDeclaration*
|
|---|
| 11 | ;
|
|---|
| 12 |
|
|---|
| 13 | moduleDeclaration
|
|---|
| 14 | : 'module' ';'
|
|---|
| 15 | ;
|
|---|
| 16 |
|
|---|
| 17 | importDeclaration
|
|---|
| 18 | : 'import' (StringLiteral | (Identifier ('/' Identifier)*)) ';'
|
|---|
| 19 | ;
|
|---|
| 20 |
|
|---|
| 21 | externalDeclaration
|
|---|
| 22 | : 'export'? limitedFunctionDefinition
|
|---|
| 23 | | 'export'? limitedGlobal
|
|---|
| 24 | | 'export'? limitedStruct
|
|---|
| 25 | | ';' // stray ;
|
|---|
| 26 | ;
|
|---|
| 27 |
|
|---|
| 28 | limitedFunctionDefinition
|
|---|
| 29 | : limitedTypeSpecifier limitedDeclarator '(' limitedParameterList? ')' limitedCompoundStatement
|
|---|
| 30 | ;
|
|---|
| 31 |
|
|---|
| 32 | limitedTypeSpecifier
|
|---|
| 33 | : 'void'
|
|---|
| 34 | | 'char'
|
|---|
| 35 | | 'short'
|
|---|
| 36 | | 'int'
|
|---|
| 37 | | 'long'
|
|---|
| 38 | | 'float'
|
|---|
| 39 | | 'double'
|
|---|
| 40 | | 'struct' Identifier
|
|---|
| 41 | ;
|
|---|
| 42 |
|
|---|
| 43 | limitedDeclarator
|
|---|
| 44 | : '*'? Identifier
|
|---|
| 45 | ;
|
|---|
| 46 |
|
|---|
| 47 | limitedParameterList
|
|---|
| 48 | : limitedTypeSpecifier limitedDeclarator (',' limitedTypeSpecifier limitedDeclarator)*
|
|---|
| 49 | ;
|
|---|
| 50 |
|
|---|
| 51 | limitedCompoundStatement
|
|---|
| 52 | : '{' limitedStatement* '}'
|
|---|
| 53 | ;
|
|---|
| 54 |
|
|---|
| 55 | limitedStatement
|
|---|
| 56 | : Identifier ';' // these are values or functions
|
|---|
| 57 | | 'type' Identifier ';' // these are structs, need full definition
|
|---|
| 58 | | 'type' '*' Identifier ';' // these are structs, only need forward declaration
|
|---|
| 59 | ;
|
|---|
| 60 |
|
|---|
| 61 | limitedGlobal
|
|---|
| 62 | : limitedTypeSpecifier limitedDeclarator ('=' limitedInitializer)? ';'
|
|---|
| 63 | ;
|
|---|
| 64 |
|
|---|
| 65 | limitedInitializer
|
|---|
| 66 | : Identifier ('+' Identifier)* // these are values or functions
|
|---|
| 67 | ;
|
|---|
| 68 |
|
|---|
| 69 | limitedStruct
|
|---|
| 70 | : 'struct' Identifier limitedCompoundStatement ';'
|
|---|
| 71 | ;
|
|---|
| 72 |
|
|---|
| 73 | Identifier
|
|---|
| 74 | : Nondigit (Nondigit | Digit)*
|
|---|
| 75 | ;
|
|---|
| 76 |
|
|---|
| 77 | fragment Nondigit
|
|---|
| 78 | : [a-zA-Z_$]
|
|---|
| 79 | ;
|
|---|
| 80 |
|
|---|
| 81 | fragment Digit
|
|---|
| 82 | : [0-9]
|
|---|
| 83 | ;
|
|---|
| 84 |
|
|---|
| 85 | StringLiteral
|
|---|
| 86 | : '"' SChar* '"'
|
|---|
| 87 | ;
|
|---|
| 88 |
|
|---|
| 89 | fragment SChar
|
|---|
| 90 | : ~["\r\n]
|
|---|
| 91 | ;
|
|---|
| 92 |
|
|---|
| 93 | Whitespace
|
|---|
| 94 | : [ \t]+ -> channel(HIDDEN)
|
|---|
| 95 | ;
|
|---|
| 96 |
|
|---|
| 97 | Newline
|
|---|
| 98 | : ('\r' '\n'? | '\n') -> channel(HIDDEN)
|
|---|
| 99 | ;
|
|---|
| 100 |
|
|---|
| 101 | BlockComment
|
|---|
| 102 | : '/*' .*? '*/' -> channel(HIDDEN)
|
|---|
| 103 | ;
|
|---|
| 104 |
|
|---|
| 105 | LineComment
|
|---|
| 106 | : '//' ~[\r\n]* -> channel(HIDDEN)
|
|---|
| 107 | ;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.