This repository was archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Grammar
Seyedamirhossein Hesamian edited this page Dec 27, 2021
·
4 revisions
The syntax is a very small subset of Scala.
<Comment> = '//' + ([^/][^/])* '//'
| '/*' + ([^*][^/])* '*/'
;
<Name> = [^:" {}=()\n;,*!.<>]+
;
<Actuals> = '(' (<Expr> ,)+ <Expr> ')' | '(' <Expr> ')' | '(' ')'
;
<Arm> = case null '=>' <Expr> | case <Name> ':' <Name> '=>' <Expr>
;
<Arms> = '{' (<Arm> ,)+ <Arm> '}' | '{' <Arm> '}' | '{' '}'
;
<Expr> = if '(' <Expr> ')' else <Expr>
| while '(' <Expr> ')' <Expr>
| match <Expr> 'with' <Arms>
| <Name> <Actuals>
| var <Name> '=' <Expr>
| <Name> '=' <Expr>
| '{' (<Expr> ';')+ <Expr> '}' | '{' <Expr> '}' | '{' '}'
| [\d]+
| <Name>
| null
| true | false
| '(' <Expr> ')'
| native
| <Expr> '.' <Expr>
| <Expr> '+' <Expr> | <Expr> '-' <Expr> | <Expr> '*' <Expr> | <Expr> '/' <Expr>
| <Expr> '<' <Expr> | <Expr> '<=' <Expr>
| '-' <Expr>
| '!' <Expr>
| <Expr> '==' <Expr> | <Expr> '!=' <Expr>
;
<Formal> = <Name> ':' <Name>
;
<Formals> = '(' (<Formal> ';')+ <Formal> ')' | '(' (<Formal> ')' | '(' ')'
;
<FunctionDecl> = def <Name> <Formals> : <Name> = <Expr>
;
<Feature> = <Expr> | <FunctionDecl>
;
<Features> = '{' (<Feature> ;)+ <Feature> '}' | '{' <Feature> '}' | '{' '}'
;
<ClassDecl> = class <Name> <Formals> Features
| class <Name> <Formals> extends <Name> <Actuals> Features
| class <Name> <Formals> extends native Features
;
There are differences between Toy and Scala.
- Match expression in Toy: this change was needed to prevent left recursion in the parser.
// Toy
match <Expr> with <Arms>
// Scala
<Expr> match <Arms>
- Match Arms: this change simplifies the parser.
// Toy
Arms ',' Arm | Arm
// Scala
Arms Arm | Arm
- Semicolon separating class features (i.e. methods and expressions)
// Toy
class Foo() {
{ null } ;
{ null }
}
// Scala
class Foo() {
{ null }
{ null }
}