Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar MBDVL;
- /* LEXER RULES */
- SINGLE_COMMENT : '//' ~('\r' | '\n')* -> skip ;
- MULTILINE_COMMENT : '/*' .*? '*/' -> skip ;
- WS : [ \t\n\r]+ -> skip ;
- fragment LETTER : ('a' .. 'z') | ('A' .. 'Z') ;
- BOOL : 'true' | 'false' ;
- IDENTIFIER : LETTER+ ;
- fragment NUMBER : ('0' .. '9') | '-'('0' .. '9') ;
- ANYCHAR : '.' | '!' | '?' | '/' | ',' | '(' | ')' ;
- COORDS : NUM ';' NUM ';' NUM ;
- NUM : NUMBER+ | NUMBER+ '.' NUMBER+ ;
- STR : '"' (LETTER | NUMBER | WS | ANYCHAR)* '"' | '\'' (LETTER | NUMBER | WS | ANYCHAR)* '\'' ;
- ITEM_ID : NUMBER+ ':' NUMBER+ ;
- MULDIVMODOP : '*' | '/' | '%' ;
- ADDSUBOP : '+' | '-' ;
- NEGOP : '!' ;
- EQOP : '==' | '!=' | '<' | '<=' | '>' | '>=' ;
- LOGOP : '&&' | '||' ;
- /* PROGRAM GRAMMAR */
- prog : 'begin' 'bot' body 'end' 'bot' ;
- body : glob_var* initiate main function* ;
- initiate : 'initiate' stmt* 'end' 'initiate' ;
- main : 'loop' stmt* 'end' 'loop' ;
- type : 'num' | 'bool' | 'string' | 'block' | 'item' | 'coords' ;
- eventtype : 'block' | 'entity' | 'hunger' |'inventory' | 'health' | 'durability' ;
- function
- : 'function' IDENTIFIER '(' args ')' stmt* 'end' 'function' #function_func
- | 'activity' IDENTIFIER '(' args ')' stmt* 'end' 'activity' #activity_func
- | 'event' eventtype '(' event_args ')' stmt* 'end' 'event' #event_func
- ;
- event_arg
- : ITEM_ID #block_event_arg
- | NUM #num_event_arg
- ;
- arg
- : type IDENTIFIER #type_arg
- | type '[' ']' IDENTIFIER #type_arr_arg
- | dcl #dcl_arg
- | /* epsilon */ #empty_arg
- ;
- i_arg
- : cond #iarg
- | /* epsilon */ #iarg_empty
- ;
- event_args : event_arg ',' event_args | event_arg ;
- args : arg ',' args | arg ;
- i_args : i_arg ',' i_args | i_arg ;
- cond
- : '(' cond ')' #paren_cond
- | left=cond MULDIVMODOP right=cond #multdiv_cond
- | left=cond ADDSUBOP right=cond #addsub_cond
- | NEGOP cond #neg_cond
- | left=cond EQOP right=cond #eq_cond
- | left=cond LOGOP right=cond #log_cond
- | '{' cond ';' cond ';' cond '}' #coords_cond
- | tpe=(NUM | STR | BOOL | ITEM_ID | IDENTIFIER) #var_cond
- | accessing #acc_cond
- | func_call #func_call_cond
- ;
- stnd_stmt
- : dcl #dcl_stmt
- | 'for' IDENTIFIER '=' init=cond way=('to' | 'downto') target=cond 'do' stmt* 'end' 'for' #for_stmt
- | rpt=('while' | 'until') cond 'repeat' stmt* 'end' 'repeat' #repeat_stmt
- | func_call #func_call_stmt
- | IDENTIFIER '=' cond #assign_stmt
- | 'return' cond #return_stmt
- | 'break' #break_stmt
- ;
- func_call : IDENTIFIER '(' i_args ')' ;
- stmt : stnd_stmt | if_stmt ;
- else_stmt : stnd_stmt | ifelse_stmt ;
- eelse_stmt : else_stmt ;
- if_stmt
- : 'if' cond 'then' stmt* 'end' 'if'
- | 'if' cond 'then' stmt* 'else' else_stmt* 'end' 'if'
- ;
- ifelse_stmt
- : 'if' cond 'then' else_stmt*
- | 'if' cond 'then' else_stmt* 'else' eelse_stmt*
- ;
- glob_var : 'global' dcl ;
- arr_items : cond ',' arr_items | cond ;
- dcl
- : type IDENTIFIER '=' cond #var_dcl
- | type '[' ']' IDENTIFIER '=' '{' arr_items '}' #arr_dcl
- | type '[' ']' id=IDENTIFIER '=' val=IDENTIFIER #arr_id_dcl
- ;
- accessing
- : IDENTIFIER '[' val=('X' | 'Y' | 'Z') ']' #coords_accessing
- | IDENTIFIER '[' val=NUM+ ']' #arr_accessing
- | id=IDENTIFIER '[' val=IDENTIFIER ']' #arr_id_accessing
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement