Language Grammar
Top Level
- Program ::= Member*
- Member ::= Subroutine | Function | DimStatement | ConstStatement | TypeDeclaration
- Subroutine ::= "sub" identifier "(" ParameterList ")" "\n" Body "end" "sub" "\n"*
- Function ::= "function" identifier "(" ParameterList ")" "as" Type "\n" Body "end" "function" "\n"*
- TypeDeclaration ::= "type" identifier "\n" (Parameter "\n")* "end" "type" "\n"*
- Statement ::= DeclarationStatement | BlockStatement | CommandStatement
Statements
- Statement ::= CommandStatement | ForStatement | ForEachStatement | WhileStatement | DoStatement | IfStatement | SelectCaseStatement | TryStatement | DimStatement | DimCollectionStatement | ConstStatement
- CommandStatement ::= AssignStatement | YieldStatement | ReturnStatement | CallStatement | ContinueStatement | ExitStatement | ThrowStatement | RethrowStatement | PrintStatement | InputStatement
- AssignStatement ::= DottedExpression "=" Expression "\n"
- ForStatement ::= "for" identifier "=" Expression "to" Expression ForStep? "\n" Body "next" "\n"
- ForStep ::= "step" Expression
- ForEachStatement ::= "for" "each" identifier "in" Expression "\n" Body "next" "\n"
- WhileStatement ::= "while" Expression "\n" Body "wend" "\n"
- IfStatement ::= "if" Expression "then" ("\n" Body ElseIf* Else? "end" "if" | CommandStatement) "\n"
- ElseIf ::= "else" "if" Expression "then" "\n" Body
- Else ::= "else" "\n" Body
- DoStatement ::= "do" "\n" Body "loop" "while" Expression "\n"
- SelectCaseStatement ::= "select" "case" Expression "\n" Case* "end" "select" "\n"
- Case ::= "case" (CaseValueList | "else") "\n" Body
- CaseValueList ::= CaseValue ("," CaseValue)*
- CaseValue ::= Expression ("to" Expression)?
- DeclarationStatement ::= DimStatement | ConstStatement
- TryStatement ::= "try" "\n" Body "catch" "\n" Body "end" "try"
- DimStatement ::= "dim" "shared"? identifier ("as" Type | "=" Expression) "\n"
- DimCollectionStatement ::= "dim" ("list" | "map" | "set") identifier "\n" Body "end" "dim" "\n"
- ConstStatement ::= "const" identifier "=" LiteralValue "\n"
- YieldStatement ::= "yield" Expression ("to" Expression)? "\n"
- ReturnStatement ::= "return" Expression? "\n"
- CallStatement ::= identifier ArgumentList "\n"
- ContinueStatement ::= "continue" ("do" | "for" | "while") "\n"
- ExitStatement ::= "exit" ("do" | "for" | "while") "\n"
- ThrowStatement ::= "throw" (Expression ",")? Expression "\n"
- RethrowStatement ::= "rethrow" "\n"
- PrintStatement ::= "print" Expression (";" Expression)* ";"? "\n"
- InputStatement ::= "input" identifier "\n"
- OnStatement ::= "on" identifier identifier "call" identifier "\n"
Expressions
- Expression ::= OrExpression
- OrExpression ::= AndExpression OrExpressionSuffix*
- OrExpressionSuffix ::= "or" AndExpression
- AndExpression ::= EqualityExpression AndExpressionSuffix*
- AndExpressionSuffix ::= "and" EqualityExpression
- EqualityExpression ::= InequalityExpression EqualityExpressionSuffix*
- EqualityExpressionSuffix ::= ("=" | "<>") InequalityExpression
- InequalityExpression ::= AddExpression InequalityExpressionSuffix*
- InequalityExpressionSuffix ::= ("<" | "<=" | ">" | ">=") AddExpression
- AddExpression ::= MultiplyExpression AddExpressionSuffix*
- AddExpressionSuffix ::= ("+" | "-") MultiplyExpression
- MultiplyExpression ::= ExponentExpression MultiplyExpressionSuffix*
- MultiplyExpressionSuffix ::= ("*" | "/" | "mod") ExponentExpression
- ExponentExpression ::= UnaryExpression ExponentExpressionSuffix*
- ExponentExpressionSuffix ::= ("^") UnaryExpression
- UnaryExpression ::= "not"? ConvertExpression
- ConvertExpression ::= DottedExpression ("as" Type)?
- DottedExpression ::= ExpressionTerm DottedExpressionSuffix*
- DottedExpressionSuffix ::= "." identifier | "(" ArgumentList ")"
- ExpressionTerm ::= LiteralValue | identifier | ParenthesesTerm | LiteralArrayTerm | LiteralRecordTerm | LiteralNoTerm
- ParenthesesTerm ::= "(" Expression ")"
- LiteralArrayTerm ::= "[" ArgumentList "]"
- LiteralRecordTerm ::= "{" LiteralRecordFieldList "}"
- LiteralNoTerm ::= "no" Type
- LiteralRecordFieldList ::= (LiteralRecordField ("," LiteralRecordField)*)?
- LiteralRecordField ::= identifier ":" Expression
- LiteralValue ::= boolean | number | string
Type Signatures
- Type ::= PrimitiveType | RecordType | ListType | MapType | SetType | OptionalType | NamedType
- PrimitiveType ::= "boolean" | "number" | "string" | "date" | "datetime" | "datetimeoffset" | "timespan" | "timezone"
- RecordType ::= "record" "(" ParameterList ")"
- ListType ::= "list" "of" TypeWithParentheses
- MapType ::= "map" "from" TypeWithParentheses "to" TypeWithParentheses
- SetType ::= "set" "of" TypeWithParentheses
- OptionalType ::= "optional" TypeWithParentheses
- TypeWithParentheses ::= "(" Type ")" | Type
- NamedType ::= identifier
Common
- ParameterList ::= (Parameter ("," Parameter)*)?
- Parameter ::= identifier "as" Type
- ArgumentList ::= (Expression ("," Expression)*)?
- Body ::= Statement*
Terminals
- identifier ::= /[A-Za-z_][A-Za-z0-9_]*/
- boolean ::= "true" | "false"
- number ::= /-?[0-9]+\.?[0-9]*/
- string ::= /"(""|[^"])*"/