Commit 51bc8891 authored by Alexander Weigl's avatar Alexander Weigl
Browse files

changes to the grammar

in preparation for an visitor
parent 588a76d2
/** Optional javadoc style comment */
grammar ScriptLanguage; grammar ScriptLanguage;
start start
: (SCRIPT ID '(' argList? ')' INDENT stmtList DEDENT)* : (SCRIPT name=ID '(' paramters=argList? ')' INDENT body=stmtList DEDENT)*
; ;
argList argList
...@@ -21,7 +19,7 @@ type ...@@ -21,7 +19,7 @@ type
; ;
stmtList stmtList
: statement+ : statement*
; ;
statement statement
...@@ -35,38 +33,44 @@ statement ...@@ -35,38 +33,44 @@ statement
; ;
assignment assignment
: ID (':' type)? ':=' expression SEMICOLON : variable=ID (COLON type)? ASSIGN expression SEMICOLON
; ;
expression expression
: matchPattern :
| '-' expression MINUS expression #exprMinus
| 'not' expression | NEGATE expression #exprNegate
| expression MUL expression | expression MUL expression #exprMultiplication
| <assoc=right> expression DIV expression | <assoc=right> expression DIV expression #exprDivision
| expression (PLUS|MINUS) expression | expression op=(PLUS|MINUS) expression #exprLineOperators
| expression LE expression | expression op=(LE|GE|LEQ|GEQ) expression #exprComparison
| expression GE expression | expression op=(NEQ|EQ) expression #exprEquality
| expression LEQ expression | expression AND expression #exprAnd
| expression GEQ expression | expression OR expression #exprOr
| expression EQ expression | expression IMP expression #exprIMP
| expression NEQ expression //| expression EQUIV expression already covered by EQ/NEQ
| expression AND expression | '(' expression ')' #exprParen
| expression OR expression | literals #exprLiterals
| expression IMP expression | matchPattern #exprMatch
| expression EQUIV expression ;
| scriptVar
| ID literals :
| DIGITS ID #literalID
| '(' expression ')' | DIGITS #literalDigits
| TERM | TERM_LITERAL #literalTerm
| STRINGLIT | STRING_LITERAL #literalString
| TRUE | TRUE #literalTrue
| FALSE | FALSE #literalFalse
; ;
/**
* Example: <pre>
match `f(x) ==>` using [x:term]
</pre>*/
matchPattern matchPattern
: 'match' TERM 'using' '[' ID COLON type (',' ID COLON type)* ']' : MATCH ( TERM_LITERAL | ID)
(USING LBRACKET argList RBRACKET)?
; ;
scriptVar scriptVar
...@@ -78,12 +82,12 @@ repeatStmt ...@@ -78,12 +82,12 @@ repeatStmt
; ;
casesStmt casesStmt
: 'cases' INDENT casesList+ DEDENT : CASES INDENT casesList+ DEDENT
; ;
casesList casesList
: 'case' expression COLON INDENT stmtList DEDENT casesList* : CASE expression COLON INDENT stmtList DEDENT casesList*
| 'default' COLON INDENT stmtList DEDENT | DEFAULT COLON INDENT stmtList DEDENT
; ;
forEachStmt forEachStmt
...@@ -105,6 +109,14 @@ callStmt ...@@ -105,6 +109,14 @@ callStmt
//LEXER Rules //LEXER Rules
WS : [ \t\n\r]+ -> skip ; WS : [ \t\n\r]+ -> skip ;
CASES: 'cases';
CASE: 'case';
DEFAULT: 'default';
ASSIGN : ':=';
LBRACKET: '[';
RBRACKET:']';
USING : 'using';
MATCH : 'match';
SCRIPT : 'script' ; SCRIPT : 'script' ;
TRUE : 'true' ; TRUE : 'true' ;
FALSE : 'false' ; FALSE : 'false' ;
...@@ -122,8 +134,15 @@ INDENT : '{' ; ...@@ -122,8 +134,15 @@ INDENT : '{' ;
DEDENT : '}' ; DEDENT : '}' ;
SEMICOLON : ';' ; SEMICOLON : ';' ;
COLON : ':' ; COLON : ':' ;
STRINGLIT : '"' ~["]* '"' ;
TERM : '`' ~[`]* '`' ; STRING_LITERAL
: '\'' ('\'\'' | ~ ('\''))* '\''
;
TERM_LITERAL
: '`' ~('`')* '`'
;
PLUS : '+' ; PLUS : '+' ;
MINUS : '-' ; MINUS : '-' ;
MUL : '*' ; MUL : '*' ;
...@@ -138,8 +157,7 @@ AND : '&' ; ...@@ -138,8 +157,7 @@ AND : '&' ;
OR: '|' ; OR: '|' ;
IMP : '->' ; IMP : '->' ;
EQUIV : '<=>' ; EQUIV : '<=>' ;
NEGATE: 'not';
//options {...} //options {...}
//import ... ; //import ... ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment