mirror of
https://github.com/mudabbir-ahmad/UNI-PROG3-CW2-DYOPL.git
synced 2026-10-08 04:00:20 +00:00
Q2 prep
This commit is contained in:
1 parent
b3fd98703a
commit
d20c595e0f
10 files changed
+204
No files matched your search
@@ -0,0 +1,62 @@
|
||||
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) ;
|
||||
Reference in new issue
Block a user