- COMPILER Galaxy
- CHARACTERS
- letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".
- digit = "0123456789".
- integer_digit = "123456789".
- octal_digit = "01234567".
- hex_digit = "0123456789ABCDEFabcdef".
- underscore = "_".
- cr = '\r'.
- lf = '\n'.
- tab = '\t'.
- eol = cr + lf.
- string_char = ANY - '"' - '\\' - eol.
- TOKENS
- ident = letter [{letter | digit | underscore} (letter | digit)].
- semicolon = ";".
- integer = integer_digit {digit}.
- hex = ("0x" | "0X") hex_digit {hex_digit}.
- octal = "0" {octal_digit}.
- real = {digit} "." digit {digit}.
- string = "\"" {string_char | "\\\'" | "\\\"" | "\\\\" | "\\0" | "\\a" | "\\b" | "\\f" | "\\n" | "\\r" | "\\t" | "\\v"} "\"".
- COMMENTS FROM "//" TO cr lf
- IGNORE cr + lf + tab
- PRODUCTIONS
- /*
- * Token capturing
- */
- String<wchar_t* &name> = string (. name = coco_string_create(t->val); .).
- /*
- * Global Terminals
- */
- Galaxy = {Include | ModuleTerm semicolon | ["static"] StaticTerm | semicolon}.
- ModuleTerm = Struct | Typedef | "native" TypeIdentPair FunctionHead.
- StaticTerm = Constant | TypeIdentPair (["=" Expression] semicolon | Function).
- Include (. wchar_t* name; .) = "include" String<name> (. include(name); .).
- Struct = "struct" ident "{" TypeIdentPair semicolon {TypeIdentPair semicolon} "}".
- Typedef = "typedef" TypeIdentPair.
- Function = FunctionHead (FunctionBody | semicolon).
- FunctionHead = "(" [TypeIdentPair {"," TypeIdentPair}] ")".
- FunctionBody = "{" {Constant} {Statement} "}".
- Constant = "const" TypeIdentPair ["=" Expression] semicolon.
- TypeIdentPair = Type ident.
- /*
- * Types
- */
- Type = ident {ArraySubScript | "*"}.
- /*
- * Statements
- */
- Statement = [VarAssignExpr | "continue" | "break" | Return | Do] semicolon
- | While
- | If
- | Block.
- Return = "return" [Expression].
- VarAssignExpr = Expression [ident] [AssignmentOp Expression].
- AssignmentOp = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=".
- Block = "{" {Statement} "}".
- While = "while" GroupedExpression Block.
- Do = "do" Block "while" GroupedExpression.
- If = "if" GroupedExpression Block ["else" (If | Block)].
- /*
- * Expressions
- */
- Expression = LogicalOr.
- LogicalOr = LogicalAnd {"||" LogicalAnd}.
- LogicalAnd = BitwiseOr {"&&" BitwiseOr}.
- BitwiseOr = BitwiseXor {"|" BitwiseXor}.
- BitwiseXor = BitwiseAnd {"^" BitwiseAnd}.
- BitwiseAnd = Equality {"&" Equality}.
- Equality = Relational {EqualityOp Relational}.
- EqualityOp = "==" | "!=".
- Relational = Shift {RelationalOp Shift}.
- RelationalOp = ">" | ">=" | "<" | "<=".
- Shift = Arithmetic {ShiftOp Arithmetic}.
- ShiftOp = "<<" | ">>".
- Arithmetic = Term {TermOp Term}.
- TermOp = "+" | "-".
- Term = Unary {FactorOp Unary}.
- FactorOp = "*" | "/" | "%".
- Unary = {UnaryOp} FactorChain.
- UnaryOp = "+" | "-" | "!" | "~" | "&" | "*".
- FactorChain = Factor {ArraySubScript | StructMember}
- | ArraySubScript {ArraySubScript}. /* This is only valid for types */
- Factor = ident [FunctionArguments]
- | integer
- | hex
- | octal
- | string
- | real
- | "true"
- | "false"
- | "null"
- | GroupedExpression.
- GroupedExpression = "(" Expression ")".
- FunctionArguments = "(" [Expression {"," Expression}] ")".
- ArraySubScript = "[" Expression "]".
- StructMember = ("." | "->") ident.
- END Galaxy.
