Here you can find the grammar for the Gosu programming language. The grammar below uses the following EBNF-style conventions:
For more information on this EBNF notation please refer to this wiki page.
An ANTLR v3.x based grammar can be found here.
start = header modifiers (gClass | gInterface | gEnum | gEnhancement) . header = ["package" namespaceStatement] [usesStatementList] . annotation = "@" idAll {"." idAll} [typeVariableDefs annotationArguments] . gClass = "class" id typeVariableDefs ["extends" classOrInterfaceType] ["implements" classOrInterfaceType {"," classOrInterfaceType}] classBody . gInterface = "interface" id typeVariableDefs [("extends" | "implements") classOrInterfaceType {"," classOrInterfaceType}] interfaceBody . gEnum = "enum" id typeVariableDefs ["implements" classOrInterfaceType {"," classOrInterfaceType}] enumBody . gEnhancement = "enhancement" id typeVariableDefs ":" classOrInterfaceType {"[" "]"} enhancementBody . classBody = "{" classMembers "}" . enhancementBody = "{" enhancementMembers "}" . interfaceBody = "{" interfaceMembers "}" . enumBody = "{" [enumConstants] classMembers "}" . enumConstants = enumConstant {"," enumConstant} [","] [";"] . enumConstant = {annotation} id optionalArguments . interfaceMembers = {modifiers (functionDefn | propertyDefn | fieldDefn | gClass | gInterface | gEnum) [";"]} . classMembers = {declaration} . declaration = modifiers (functionDefn [functionBody] | constructorDefn functionBody | propertyDefn [functionBody] | fieldDefn | delegateDefn | gClass | gInterface | gEnum) [";"] . enhancementMembers = {modifiers (functionDefn functionBody | propertyDefn functionBody) [";"]} . delegateDefn = "delegate" id delegateStatement . delegateStatement = [":" typeLiteral] "represents" typeLiteral {"," typeLiteral} ["=" expression] . optionalType = [":" typeLiteral | blockTypeLiteral] . fieldDefn = "var" id optionalType ["as" ["readonly"] id] ["=" expression] . propertyDefn = "property" ("get" | "set") id parameters [":" typeLiteral] . dotPathWord = id {"." id} . namespaceStatement = dotPathWord {";"} . usesStatementList = "uses" usesStatement {"uses" usesStatement} . usesStatement = dotPathWord ["." "*"] {";"} . typeVariableDefs = ["<" typeVariableDefinition {"," typeVariableDefinition} ">"] . typeVariableDefinition = id ["extends" typeLiteralList] . functionBody = statementBlock . parameters = "(" [parameterDeclarationList] ")" . functionDefn = "function" id typeVariableDefs parameters [":" typeLiteral] . constructorDefn = "construct" parameters [":" typeLiteral] . modifiers = {annotation | "private" | "internal" | "protected" | "public" | "static" | "abstract" | "override" | "final" | "transient"} . statement = (ifStatement | tryCatchFinallyStatement | throwStatement | "continue" | "break" | returnStatement | forEachStatement | whileStatement | doWhileStatement | switchStatement | usingStatement | assertStatement | "final" localVarStatement | localVarStatement | evalExpr | assignmentOrMethodCall | statementBlock) [";"] | ";" . ifStatement = "if" "(" expression ")" statement [";"] ["else" statement] . tryCatchFinallyStatement = "try" statementBlock (catchClause {catchClause} ["finally" statementBlock] | "finally" statementBlock) . catchClause = "catch" "(" ["var"] id [":" typeLiteral] ")" statementBlock . assertStatement = "assert" expression [":" expression] . usingStatement = "using" "(" (localVarStatement {"," localVarStatement} | expression) ")" statementBlock ["finally" statementBlock] . returnStatement = "return" [expression] . whileStatement = "while" "(" expression ")" statement . doWhileStatement = "do" statement "while" "(" expression ")" . switchStatement = "switch" "(" expression ")" "{" {switchBlockStatementGroup} "}" . switchBlockStatementGroup = ("case" expression ":" | "default" ":") {statement} . throwStatement = "throw" expression . localVarStatement = "var" id optionalType ["=" expression] . forEachStatement = ("foreach" | "for") "(" (expression [indexVar] | ["var"] id "in" expression [indexRest]) ")" statement . indexRest = indexVar iteratorVar | iteratorVar indexVar | indexVar | iteratorVar . indexVar = "index" id . iteratorVar = "iterator" id . thisSuperExpr = "this" | "super" . assignmentOrMethodCall = ((newExpr | thisSuperExpr | typeLiteralExpr | parenthExpr | StringLiteral) indirectMemberAccess) [incrementOp | assignmentOp expression] . statementBlock = statementBlockBody . statementBlockBody = "{" {statement} "}" . blockTypeLiteral = blockLiteral . blockLiteral = "(" [blockLiteralArg {"," blockLiteralArg}] ")" [":" typeLiteral] . blockLiteralArg = id ("=" expression | blockTypeLiteral) | [id ":"] typeLiteral ["=" expression] . typeLiteral = type {"&" type} . typeLiteralType = typeLiteral . typeLiteralExpr = typeLiteral . typeLiteralList = typeLiteral . type = classOrInterfaceType {"[" "]"} | "block" blockLiteral . classOrInterfaceType = idclassOrInterfaceType typeArguments {"." id typeArguments} . typeArguments = ["<" typeArgument {"," typeArgument} ">"] . typeArgument = typeLiteralType | "?" [("extends" | "super") typeLiteralType] . expression = conditionalExpr . conditionalExpr = conditionalOrExpr ["?" conditionalExpr ":" conditionalExpr | "?:" conditionalExpr] . conditionalOrExpr = conditionalAndExpr {orOp conditionalAndExpr} . conditionalAndExpr = bitwiseOrExpr {andOp bitwiseOrExpr} . bitwiseOrExpr = bitwiseXorExpr {"|" bitwiseXorExpr} . bitwiseXorExpr = bitwiseAndExpr {"^" bitwiseAndExpr} . bitwiseAndExpr = equalityExpr {"&" equalityExpr} . equalityExpr = relationalExpr {equalityOp relationalExpr} . relationalExpr = intervalExpr {relOp intervalExpr | "typeis" typeLiteralType} . intervalExpr = bitshiftExpr [intervalOp bitshiftExpr] . bitshiftExpr = additiveExpr {bitshiftOp additiveExpr} . additiveExpr = multiplicativeExpr {additiveOp multiplicativeExpr} . multiplicativeExpr = typeAsExpr {multiplicativeOp typeAsExpr} . typeAsExpr = unaryExpr {typeAsOp typeLiteral} . unaryExpr = ("+" | "-") unaryExprNotPlusMinus | unaryExprNotPlusMinus . unaryExprNotPlusMinus = unaryOp unaryExpr | "\" blockExpr | evalExpr | primaryExpr . blockExpr = [parameterDeclarationList] "->" (expression | statementBlock) . parameterDeclarationList = parameterDeclaration {"," parameterDeclaration} . parameterDeclaration = {annotation} ["final"] id [(":" typeLiteral ["=" expression]) | blockTypeLiteral | "=" expression] . annotationArguments = arguments . arguments = "(" [argExpression {"," argExpression}] ")" . optionalArguments = [arguments] . argExpression = namedArgumentExpression | expression . namedArgumentExpression = ":" id "=" expression . evalExpr = "eval" "(" expression ")" . featureLiteral = "#" (id | "construct") typeArguments optionalArguments . standAloneDataStructureInitialization = "{" [initializerExpression] "}" . primaryExpr = (newExpr | thisSuperExpr | literal | typeLiteralExpr | parenthExpr | standAloneDataStructureInitialization) indirectMemberAccess . parenthExpr = "(" expression ")" . newExpr = "new" [classOrInterfaceType] ((arguments ["{" (initializer | anonymousInnerClass) "}"]) | ("[" ("]" {"[" "]"} arrayInitializer | expression "]" {"[" expression "]"} {"[" "]"}))) . anonymousInnerClass = classMembers . arrayInitializer = "{" [expression {"," expression}] "}" . initializer = [initializerExpression | objectInitializer] . initializerExpression = mapInitializerList | arrayValueList . arrayValueList = expression {"," expression} . mapInitializerList = expression "->" expression {"," expression "->" expression} . objectInitializer = initializerAssignment {"," initializerAssignment} . initializerAssignment = ":" id "=" expression . indirectMemberAccess = {("." | "?." | "*.") idAll typeArguments | featureLiteral | ("[" | "?[") expression "]" | arguments} . literal = NumberLiteral | featureLiteral | StringLiteral | CharLiteral | "true" | "false" | "null" . orOp = "||" | "or" . andOp = "&&" | "and" . assignmentOp = "=" | "+=" | "-=" | "*=" | "/=" | "&=" | "|=" | "^=" | "%=" | "<" "<" "=" | ">" ">" ">" "=" | ">" ">" "=" . incrementOp = "++" | "--" . equalityOp = "===" | "!==" | "==" | "!=" | "<>" . intervalOp = ".." | "|.." | "..|" | "|..|" . relOp = "<" "=" | ">" "=" | "<" | ">" . bitshiftOp = "<" "<" | ">" ">" ">" | ">" ">" . additiveOp = "+" | "-" | "?+" | "?-" . multiplicativeOp = "*" | "/" | "%" | "?*" | "?/" | "?%" . typeAsOp = "typeas" | "as" . unaryOp = "~" | "!" | "not" | "typeof" | "statictypeof" . id = Ident . idclassOrInterfaceType = Ident . idAll = Ident . Ident = Letter {Digit | Letter} . NumberLiteral = "NaN" | "Infinity" | HexLiteral | BinLiteral | IntOrFloatPointLiteral . BinLiteral = ("0b" | "0B") "0" | "1" {"0" | "1"} [IntegerTypeSuffix] . HexLiteral = ("0x" | "0X") HexDigit {HexDigit} ["s" | "S" | "l" | "L"] . IntOrFloatPointLiteral = "." Digit {Digit} [FloatTypeSuffix] | Digit {Digit} ("." {Digit} [Exponent] [FloatTypeSuffix] | Exponent [FloatTypeSuffix] | FloatTypeSuffix | IntegerTypeSuffix |) . CharLiteral = "'" (EscapeSequence | any_character) "'" . StringLiteral = "'" {EscapeSequence | any_character} "'" | """ {EscapeSequence | any_character} """ . HexDigit = Digit | "a".."f" | "A".."F" . IntegerTypeSuffix = ("l" | "L" | "s" | "S" | "bi" | "BI" | "b" | "B") . Letter = "A".."Z" | "a".."z" | "_" | "$" . Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . NonZeroDigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . ZeroToSeven = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" . Exponent = ("e" | "E") ["+" | "-"] Digit {Digit} . FloatTypeSuffix = ("f" | "F" | "d" | "D" | "bd" | "BD") . EscapeSequence = "\" ("v" | "a" | "b" | "t" | "n" | "f" | "r" | """ | "'" | "\" | "$" | "<") | UnicodeEscape | OctalEscape . OctalEscape = "\" ("0" | "1" | "2" | "3") ZeroToSeven ZeroToSeven | "\" ZeroToSeven ZeroToSeven | "\" ZeroToSeven . UnicodeEscape = "\" "u" HexDigit HexDigit HexDigit HexDigit . WS = white_space . COMMENT = "/*" {any_character} "*/" . LINE_COMMENT = "//" {any_character} .