module examples::fwjava::Syntax
rascal-0.40.16
typepal-0.14.8
Usage
import examples::fwjava::Syntax;
Source code
http://github.com/usethesource/typepal/src/examples/fwjava/Syntax.rsc
syntax ClassId
lexical ClassId = ([A-Z][A-Za-z0-9]* !>> [a-z0-9]) \ Reserved;
syntax Id
lexical Id = ([a-z][a-z0-9]* !>> [a-z0-9]) \ Reserved;
syntax Reserved
keyword Reserved = "class" | "extends" | "this" | "return";
syntax Layout
layout Layout = WhitespaceAndComment* !>> [\ \t\n\r%];
syntax WhitespaceAndComment
lexical WhitespaceAndComment
= [\ \t\n\r]
| @category="Comment" ws2: "%" ![%]+ "%"
;
syntax FWJProgram
start syntax FWJProgram
= ClassDecl* classdecls
;
syntax ClassDecl
syntax ClassDecl
= "class" ClassId cid "extends" ClassId ecid "{"
FieldDecl* fielddecls
ConstructorDecl constructordecl
MethodDecl* methoddecls
"}"
;
syntax FieldDecl
syntax FieldDecl
= ClassId cid Id id ";"
;
syntax ConstructorDecl
syntax ConstructorDecl
= ClassId cid Formals formals "{"
SuperCall supercall
FieldAssignment* fieldAssignments
"}"
;
syntax SuperCall
syntax SuperCall
= "super" super "(" {Variable ","}* vars ")" ";"
;
syntax Formal
syntax Formal
= ClassId cid Id id
;
syntax Formals
syntax Formals
= "(" {Formal ","}* formals ")"
;
syntax MethodDecl
syntax MethodDecl
= ClassId cid Id mid Formals formals "{" "return" Expression exp ";" "}"
;
syntax Expression
syntax Expression
= Variable var
| Expression exp "." Field field
| Expression exp "." Method method Expressions exps
| "new" Constructor constructor Expressions exps
| "(" Class class ")" Expression exp
| "this"
;
syntax Constructor
syntax Constructor
= ClassId id
;
syntax Class
syntax Class
= ClassId id
;
syntax Variable
syntax Variable
= Id id
;
syntax Field
syntax Field
= Id id
;
syntax Method
syntax Method
= Id id
;
syntax Expressions
syntax Expressions
= "(" {Expression ","}* expressions ")"
;
syntax FieldAssignment
syntax FieldAssignment
= "this" "." Field field "=" Expression exp ";"
;