2020-05-28 05:55:48 +02:00
|
|
|
/**
|
|
|
|
* Define a grammar called Hello
|
|
|
|
*/
|
|
|
|
grammar Jass;
|
|
|
|
|
|
|
|
@header {
|
|
|
|
package com.etheller.interpreter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
program :
|
|
|
|
newlines
|
|
|
|
|
|
|
|
|
newlines_opt
|
|
|
|
typeDefinitionBlock
|
|
|
|
(block)*
|
|
|
|
(functionBlock)*
|
|
|
|
;
|
|
|
|
|
|
|
|
typeDefinition :
|
|
|
|
TYPE ID EXTENDS ID newlines
|
|
|
|
;
|
|
|
|
|
|
|
|
type :
|
|
|
|
ID # BasicType
|
|
|
|
|
|
|
|
|
ID ARRAY # ArrayType
|
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
NOTHING # NothingType
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
global :
|
2020-06-27 05:54:42 +02:00
|
|
|
CONSTANT? type ID newlines # BasicGlobal
|
2020-05-28 05:55:48 +02:00
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
CONSTANT? type ID assignTail newlines # DefinitionGlobal
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
assignTail:
|
|
|
|
EQUALS expression;
|
|
|
|
|
|
|
|
expression:
|
|
|
|
ID # ReferenceExpression
|
|
|
|
|
|
|
|
|
STRING_LITERAL #StringLiteralExpression
|
|
|
|
|
|
|
|
|
INTEGER #IntegerLiteralExpression
|
|
|
|
|
|
|
|
|
FUNCTION ID #FunctionReferenceExpression
|
|
|
|
|
|
|
|
|
NULL # NullExpression
|
|
|
|
|
|
|
|
|
TRUE # TrueExpression
|
|
|
|
|
|
|
|
|
FALSE # FalseExpression
|
|
|
|
|
|
|
|
|
ID '[' expression ']' # ArrayReferenceExpression
|
|
|
|
|
|
|
|
|
functionExpression # FunctionCallExpression
|
|
|
|
|
|
|
|
|
'(' expression ')' # ParentheticalExpression
|
2020-06-27 05:54:42 +02:00
|
|
|
|
|
|
|
|
NOT expression # NotExpression
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
functionExpression:
|
|
|
|
ID '(' argsList ')'
|
2020-06-27 05:54:42 +02:00
|
|
|
|
|
|
|
|
ID '(' ')'
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
argsList:
|
|
|
|
expression # SingleArgument
|
|
|
|
|
|
|
|
|
expression ',' argsList # ListArgument
|
|
|
|
;
|
|
|
|
|
|
|
|
//#booleanExpression:
|
|
|
|
// simpleArithmeticExpression # PassBooleanThroughExpression
|
|
|
|
// |
|
|
|
|
|
|
|
|
statement:
|
|
|
|
CALL functionExpression newlines #CallStatement
|
|
|
|
|
|
|
|
|
SET ID EQUALS expression newlines #SetStatement
|
|
|
|
|
|
|
|
|
SET ID '[' expression ']' EQUALS expression newlines # ArrayedAssignmentStatement
|
|
|
|
|
|
|
|
|
RETURN expression newlines # ReturnStatement
|
2020-06-27 05:54:42 +02:00
|
|
|
|
|
|
|
|
IF ifStatementPartial # IfStatement
|
|
|
|
;
|
|
|
|
|
|
|
|
ifStatementPartial:
|
|
|
|
expression THEN newlines statements ENDIF newlines # SimpleIfStatement
|
|
|
|
|
|
|
|
|
expression THEN newlines statements ELSE newlines statements ENDIF newlines # IfElseStatement
|
|
|
|
|
|
|
|
|
expression THEN newlines statements ELSEIF ifStatementPartial # IfElseIfStatement
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
param:
|
|
|
|
type ID;
|
|
|
|
|
|
|
|
paramList:
|
|
|
|
param # SingleParameter
|
|
|
|
|
|
|
|
|
param ',' paramList # ListParameter
|
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
NOTHING # NothingParameter
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
globalsBlock :
|
|
|
|
GLOBALS newlines (global)* ENDGLOBALS newlines ;
|
|
|
|
|
|
|
|
typeDefinitionBlock :
|
|
|
|
(typeDefinition)*
|
|
|
|
;
|
|
|
|
|
|
|
|
nativeBlock:
|
2020-06-27 05:54:42 +02:00
|
|
|
CONSTANT? NATIVE ID TAKES paramList RETURNS type newlines
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
block:
|
|
|
|
globalsBlock
|
|
|
|
|
|
|
|
|
nativeBlock
|
|
|
|
;
|
|
|
|
|
|
|
|
functionBlock:
|
2020-06-27 05:54:42 +02:00
|
|
|
FUNCTION ID TAKES paramList RETURNS type newlines statements ENDFUNCTION newlines
|
|
|
|
;
|
|
|
|
|
|
|
|
statements:
|
|
|
|
(statement)*
|
2020-05-28 05:55:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
newlines:
|
2020-06-27 05:54:42 +02:00
|
|
|
pnewlines
|
2020-05-28 05:55:48 +02:00
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
|
|
|
newlines_opt:
|
2020-06-27 05:54:42 +02:00
|
|
|
pnewlines
|
2020-05-28 05:55:48 +02:00
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
;
|
2020-06-27 05:54:42 +02:00
|
|
|
|
|
|
|
pnewlines:
|
|
|
|
NEWLINE
|
|
|
|
|
|
|
|
|
NEWLINE newlines
|
|
|
|
;
|
2020-05-28 05:55:48 +02:00
|
|
|
|
|
|
|
EQUALS : '=';
|
|
|
|
|
|
|
|
|
|
|
|
GLOBALS : 'globals' ; // globals
|
|
|
|
ENDGLOBALS : 'endglobals' ; // end globals block
|
|
|
|
|
|
|
|
NATIVE : 'native' ;
|
|
|
|
|
|
|
|
FUNCTION : 'function' ; // function
|
|
|
|
TAKES : 'takes' ; // takes
|
|
|
|
RETURNS : 'returns' ;
|
|
|
|
ENDFUNCTION : 'endfunction' ; // endfunction
|
2020-06-27 05:54:42 +02:00
|
|
|
NOTHING : 'nothing' ;
|
2020-05-28 05:55:48 +02:00
|
|
|
|
|
|
|
CALL : 'call' ;
|
|
|
|
SET : 'set' ;
|
|
|
|
RETURN : 'return' ;
|
|
|
|
|
|
|
|
ARRAY : 'array' ;
|
|
|
|
|
|
|
|
TYPE : 'type';
|
|
|
|
|
|
|
|
EXTENDS : 'extends';
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
IF : 'if';
|
|
|
|
THEN : 'then';
|
|
|
|
ELSE : 'else';
|
|
|
|
ENDIF : 'endif';
|
|
|
|
ELSEIF : 'elseif';
|
|
|
|
CONSTANT : 'constant';
|
|
|
|
|
2020-05-28 05:55:48 +02:00
|
|
|
STRING_LITERAL : ('"'.*?'"');
|
|
|
|
|
|
|
|
INTEGER : [0]|([1-9][0-9]*) ;
|
|
|
|
|
|
|
|
NULL : 'null' ;
|
|
|
|
TRUE : 'true' ;
|
|
|
|
FALSE : 'false' ;
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
NOT : 'not';
|
|
|
|
|
2020-05-28 05:55:48 +02:00
|
|
|
ID : ([a-zA-Z_][a-zA-Z_0-9]*) ; // match identifiers
|
|
|
|
|
|
|
|
WS : [ \t]+ -> skip ; // skip spaces, tabs
|
|
|
|
|
2020-06-27 05:54:42 +02:00
|
|
|
NEWLINE : '//'.*?'\r\n' | '//'.*?'\n' | '//'.*?'\r' | '\r' '\n' | '\n' | '\r';
|