Share Pastebin
Guest
Public paste!

napi.h

By: a guest | Mar 22nd, 2010 | Syntax: None | Size: 3.32 KB | Hits: 105 | Expires: Never
Copy text to clipboard
  1. COMPILER Galaxy
  2.  
  3. CHARACTERS
  4.         letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".
  5.         digit = "0123456789".
  6.         integer_digit = "123456789".
  7.         octal_digit = "01234567".
  8.         hex_digit = "0123456789ABCDEFabcdef".
  9.         underscore = "_".
  10.         cr  = '\r'.
  11.         lf  = '\n'.
  12.         tab = '\t'.
  13.         eol = cr + lf.
  14.         string_char = ANY - '"' - '\\' - eol.
  15.  
  16. TOKENS
  17.         ident  = letter [{letter | digit | underscore} (letter | digit)].
  18.        
  19.         semicolon = ";".
  20.        
  21.         integer = integer_digit {digit}.
  22.        
  23.         hex = ("0x" | "0X") hex_digit {hex_digit}.
  24.        
  25.         octal = "0" {octal_digit}.
  26.        
  27.         real = {digit} "." digit {digit}.
  28.        
  29.         string = "\"" {string_char | "\\\'" | "\\\"" | "\\\\" | "\\0" | "\\a" | "\\b" | "\\f" | "\\n" | "\\r" | "\\t" | "\\v"} "\"".
  30.  
  31. COMMENTS FROM "//" TO cr lf
  32.  
  33. IGNORE cr + lf + tab
  34.  
  35.  
  36. PRODUCTIONS
  37.  
  38. /*
  39.  * Token capturing
  40.  */
  41.  
  42. String<wchar_t* &name> = string (. name = coco_string_create(t->val); .).
  43.  
  44.  
  45. /*
  46.  * Global Terminals
  47.  */
  48.  
  49. Galaxy = {Include | ModuleTerm semicolon | ["static"] StaticTerm | semicolon}.
  50.  
  51. ModuleTerm = Struct | Typedef | "native" TypeIdentPair FunctionHead.
  52.  
  53. StaticTerm = Constant | TypeIdentPair (["=" Expression] semicolon | Function).
  54.  
  55. Include (. wchar_t* name; .) = "include" String<name> (. include(name); .).
  56.  
  57. Struct = "struct" ident "{" TypeIdentPair semicolon {TypeIdentPair semicolon} "}".
  58.  
  59. Typedef = "typedef" TypeIdentPair.
  60.  
  61. Function = FunctionHead (FunctionBody | semicolon).
  62.  
  63. FunctionHead = "(" [TypeIdentPair {"," TypeIdentPair}] ")".
  64.  
  65. FunctionBody = "{" {Constant} {Statement} "}".
  66.  
  67. Constant = "const" TypeIdentPair ["=" Expression] semicolon.
  68.  
  69. TypeIdentPair = Type ident.
  70.  
  71.  
  72. /*
  73.  * Types
  74.  */
  75.  
  76. Type = ident {ArraySubScript | "*"}.
  77.  
  78.  
  79. /*
  80.  * Statements
  81.  */
  82.  
  83. Statement = [VarAssignExpr | "continue" | "break" | Return | Do] semicolon
  84.         | While
  85.         | If
  86.         | Block.
  87.  
  88. Return = "return" [Expression].
  89.  
  90. VarAssignExpr = Expression [ident] [AssignmentOp Expression].
  91.  
  92. AssignmentOp = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=".
  93.  
  94. Block = "{" {Statement} "}".
  95.  
  96. While = "while" GroupedExpression Block.
  97.  
  98. Do = "do" Block "while" GroupedExpression.
  99.  
  100. If = "if" GroupedExpression Block ["else" (If | Block)].
  101.  
  102.  
  103. /*
  104.  * Expressions
  105.  */
  106.  
  107. Expression = LogicalOr.
  108.  
  109. LogicalOr = LogicalAnd {"||" LogicalAnd}.
  110.  
  111. LogicalAnd = BitwiseOr {"&&" BitwiseOr}.
  112.  
  113. BitwiseOr = BitwiseXor {"|" BitwiseXor}.
  114.  
  115. BitwiseXor = BitwiseAnd {"^" BitwiseAnd}.
  116.  
  117. BitwiseAnd = Equality {"&" Equality}.
  118.  
  119. Equality = Relational {EqualityOp Relational}.
  120.  
  121. EqualityOp = "==" | "!=".
  122.  
  123. Relational = Shift {RelationalOp Shift}.
  124.  
  125. RelationalOp = ">" | ">=" | "<" | "<=".
  126.  
  127. Shift = Arithmetic {ShiftOp Arithmetic}.
  128.  
  129. ShiftOp = "<<" | ">>".
  130.  
  131. Arithmetic = Term {TermOp Term}.
  132.  
  133. TermOp = "+" | "-".
  134.  
  135. Term = Unary {FactorOp Unary}.
  136.  
  137. FactorOp = "*" | "/" | "%".
  138.        
  139. Unary = {UnaryOp} FactorChain.
  140.  
  141. UnaryOp = "+" | "-" | "!" | "~" | "&" | "*".
  142.  
  143. FactorChain = Factor {ArraySubScript | StructMember}
  144.         | ArraySubScript {ArraySubScript}. /* This is only valid for types */
  145.  
  146. Factor = ident [FunctionArguments]
  147.         | integer
  148.         | hex
  149.         | octal
  150.         | string
  151.         | real
  152.         | "true"
  153.         | "false"
  154.         | "null"
  155.         | GroupedExpression.
  156.  
  157. GroupedExpression = "(" Expression ")".
  158.  
  159. FunctionArguments = "(" [Expression {"," Expression}] ")".
  160.  
  161. ArraySubScript = "[" Expression "]".
  162.  
  163. StructMember = ("." | "->") ident.
  164.  
  165. END Galaxy.