Skip to main content

module lang::flybytes::demo::protol::Syntax

rascal-0.34.0
flybytes-0.2.3

Usage

import lang::flybytes::demo::protol::Syntax;

Source code

http://github.com/usethesource/flybytes/blob/main/src/lang/flybytes/demo/protol/Syntax.rsc

syntax Program

start syntax Program = Command* commands;

syntax Command

syntax Command 
= assign: Assignable assign "=" Expr val ";"
| \if: "if" "(" Expr cond ")" "{" Command* thenPart "}" "else" "{" Command* elsePart "}"
| \for: "while" "(" Expr cond ")" "{" Command* body "}"
| exp: Expr e ";"
| \return: "return" Expr e ";"
| print: "print" Expr e ";"
;

syntax Assignable

syntax Assignable
= var: Id name
| field: Expr obj "." Id name
| array: Expr array "[" Expr index "]"
;

syntax Expr

syntax Expr
= "this"
| send: Expr receiver "." Id name "(" {Expr ","}* args ")"
| array: "[" {Expr ","}* "]"
| new: "new" Expr? prototype
| \extend: "new" Expr? prototype "{" Definition* definitions "}"
| bracket "(" Expr ")"
| ref: Id id
| \int: Int
| \str: String
| field: Expr receiver "." Id name
> array: Expr array "[" Expr index "]"
> left Expr "\<\<" Expr
> left (Expr "*" Expr | Expr "/" Expr)
> left (Expr "+" Expr | Expr "-" Expr )
> right (Expr "==" Expr | Expr "!=" Expr)
> right (Expr "\<=" Expr | Expr "\<" Expr | Expr "\>" Expr | Expr "\>=" Expr)
;

syntax Definition

syntax Definition
= field: Id name \ "missing" "=" Expr val
| method: Id name \ "missing" "(" {Id ","}* args ")" "{" Command* commands "}"
| missing: "missing" "(" Id name "," Id args ")" "{" Command* commands "}"
;

syntax Id

lexical Id     = ([A-Za-z][a-zA-Z0-9]*) \ "if" \ "new" \ "else" \ "while"  \ "return" \ "this";

syntax Int

lexical Int    = [0-9]+;

syntax String

lexical String = "\"" ![\"]* "\"";

syntax WSC

layout WSC = (WS | COMM)* !>> "//" !>> [\t\n\r\ ];

syntax WS

lexical WS = [\t\n\r\ ]+ !>> [\t\n\r\ ];

syntax COMM

lexical COMM = "//" ![\n]* "\n";