Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar NuML;
- compile_unit: module* EOF;
- module: 'module' ID stat* 'end';
- stat: decl | withcall;
- withcall: 'with' exp call_arg+;
- decl: 'val' bind #var_decl
- | 'val' name=ID funct_args ':' type '==>' block #funct_decl
- ;
- funct_args: arg+;
- arg: ID ':' type;
- block: stat* exp;
- bind: ID ':' type '=' exp;
- Asterisk: '*';
- OP_INFIX: Asterisk | '/' | '+' | '-' | '<>' | ('<' | '>' | '=') '='?;
- exp: atom #atom_exp
- | variable_name #variable_exp
- | tuple #tuple_exp
- | left=exp OP_INFIX right=exp #infix_op
- | exp 'where' bind (',' bind)* 'end' #where
- | lambda #lambda_exp
- | exp call_arg+ #call
- | 'if' pred=exp 'then' then=exp 'else' else=exp #branch
- | '[' explist? ']' #array
- | exp '.' ID #field_access
- ;
- type: variable_name #flat_type
- | type Asterisk type #tuple_type
- | '[' type ']' #array_type
- | <right_assoc> type '->' type #funct_type
- | '(' type ')' #paren_type
- // | type '[' type (',' type)* ']' #generic_type
- ;
- variable_name: (namespace=(ID | NATIVE_VAR_PREFIX) '::')? name=ID;
- lambda: 'funct' funct_args '==>' block;
- call_arg: (ID 'as')? exp;
- tuple: '(' explist? ')';
- explist: exp (',' exp)*;
- atom: number | string | bool | nil;
- number: INT_MOD | FLOAT;
- string: STRING;
- bool: TRUE | FALSE;
- nil: NIL;
- NATIVE_VAR_PREFIX: '$$';
- TRUE: 'true';
- FALSE: 'false';
- NIL: 'nil';
- ID: [a-zA-Z_]+ [a-zA-Z0-9_]*;
- WS: [ \t\n\r]+ -> channel(HIDDEN);
- INT_MOD: SIGN? INT_POS;
- FLOAT: INT_MOD [.] INT_POS EXP? // 1.35, 1.35E-9, 0.3, -4.5
- | INT_MOD EXP // 1e10 -3e4
- | INT_MOD // -3, 45
- ;
- STRING: QUOTE (~["\\] | QUOTE_ESCAPED)* QUOTE;
- fragment INT_POS: [0] | DIGIT_POS [0-9]*; // no leading zeros
- fragment EXP: [Ee] SIGN? INT_POS;
- fragment SIGN: [+~];
- fragment DIGIT_POS: [1-9];
- fragment DIGIT: [0] | DIGIT_POS;
- fragment QUOTE: ["];
- fragment QUOTE_ESCAPED: [\\] QUOTE;
- LINE_COMMENT: '//|' .*? [\n] -> channel(HIDDEN);
- COMMENT: '/|' .*? '|\\' -> channel(HIDDEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement