Added function call and function definition

This commit is contained in:
Marvin Kaiser
2019-11-18 16:39:12 +01:00
parent 9385618252
commit 13caee0667
8 changed files with 242 additions and 76 deletions

View File

@@ -1,11 +1,19 @@
grammar Klang;
parse
: block <EOF>
: program <EOF>
;
block
: statement+
program
: functionDef* expression
;
functionDef
: FUNC funcName=IDENT OPAR parameters CPAR braced_block
;
parameters
: (IDENT (COMMA IDENT)*)?
;
braced_block
@@ -31,6 +39,15 @@ expression
| atom MOD atom #moduloExpression
| SUB atom #unaryNegateExpression
| atom #atomExpression
| functionCall #functionCallExpression
;
functionCall
: IDENT OPAR arguments CPAR SCOL
;
arguments
: (expression (COMMA expression)*)?
;
atom
@@ -40,12 +57,14 @@ atom
PRINT: 'print';
IF: 'if';
ELSE: 'else';
FUNC: 'function';
SCOL: ';';
OBRK: '{';
CBRK: '}';
OPAR: '(';
CPAR: ')';
COMMA: ',';
MULT: '*';
ADD: '+';
@@ -56,6 +75,10 @@ INTEGER_LITERAL
: [0-9]+
;
IDENT
: [a-zA-Z][a-zA-Z0-9]*
;
WS
: [ \t\r\n] -> skip
;