mirror of
https://github.com/mudabbir-ahmad/UNI-PROG3-CW2-DYOPL.git
synced 2026-10-07 20:00:20 +00:00
63 lines
1.5 KiB
ANTLR
63 lines
1.5 KiB
ANTLR
grammar fspow;
|
|
// workshop 4 version
|
|
|
|
prog: stat+ ;
|
|
|
|
// labelling alternatives creates extra visitor methods
|
|
// the labels migh clash with rule names, so I make them unique
|
|
stat:
|
|
assignment # statAssignment
|
|
| fcList # statFcList
|
|
| fcApplySelector # statFcApplySelector
|
|
| message # statMessage
|
|
;
|
|
|
|
assignment :
|
|
ID '=' expression ;
|
|
|
|
// when alternatives are introduced, try using labels to distinguish
|
|
expression :
|
|
ID # exprID
|
|
|
|
|
selCreation # exprSelCreation
|
|
|
|
|
fcCreation # exprFcCreation
|
|
;
|
|
// -------
|
|
// filecollection statements
|
|
// -------
|
|
fcCreation: fcCreationName '(' rootSpecifier ')' ;
|
|
|
|
fcCreationName: 'FileCollection' ;
|
|
rootSpecifier: STRING ;
|
|
// -------
|
|
// selector statements
|
|
// -------
|
|
selCreation : selCreationName '(' filterSpecifier ')' ;
|
|
|
|
selCreationName: 'Selector' ;
|
|
filterSpecifier: selfilter '(' STRING ')' ;
|
|
selfilter: 'name' ;
|
|
// -------
|
|
// apply statement
|
|
// -------
|
|
fcApplySelector: ID '.' applyName '(' expression ')' ;
|
|
|
|
applyName: 'apply' ;
|
|
// -------
|
|
// print statement
|
|
// -------
|
|
fcList: ID '.' printName ;
|
|
|
|
printName: 'print()' ;
|
|
// -------
|
|
// message statement
|
|
// -------
|
|
message: 'message' STRING ;
|
|
|
|
ID: [a-zA-Z][a-zA-Z0-9]* ;
|
|
STRING: '"'.*?'"'
|
|
{self.text = self.text[1:-1]} ;
|
|
WS : [ \t\r\n]+ -> skip ;
|
|
COMMENT : '//' ~[\r\n]* -> channel(HIDDEN) ;
|