Advertisement
Guest User

Untitled

a guest
Nov 8th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BNF 3.70 KB | None | 0 0
  1. comment "//" ;
  2. comment "/*" "*/" ;
  3. comment "#" ;
  4.  
  5. -----------------------------------------
  6. -- Programs
  7. -----------------------------------------
  8.  
  9. PDefs.   Program ::= [Def] ;
  10.  
  11. separator nonempty Id ",";
  12. -----------------------------------------
  13. -- Definitions
  14. -----------------------------------------
  15.  
  16. DQConst.    Def ::= "using" QConst ";" ;
  17. DFun.       Def ::= Type Id "(" [Arg] ")" Body ;
  18. DStat.      Def ::= Stm2 ;
  19.  
  20. terminator Def "" ;
  21.  
  22. -----------------------------------------
  23. -- Argument
  24. -----------------------------------------
  25.  
  26. ADecl. Arg ::= Type Id ;
  27. AType. Arg ::= Type ;
  28.  
  29. separator  Arg "," ;
  30.  
  31. -----------------------------------------
  32. -- Body
  33. -----------------------------------------
  34.  
  35. BStm.   Body ::= "{" [Stm] "}" ;
  36. BEmpty. Body ::= ";" ;
  37.  
  38. -----------------------------------------
  39. -- Declaration
  40. -----------------------------------------
  41.  
  42. DDecl.       Decl ::= Type [Var] ;
  43. DAss.        Decl ::= Type Id "=" Exp ;
  44. DConst.      Decl ::= "const" Type Id "=" Exp ;
  45.  
  46. VVar.      Var ::= Id ;
  47. separator Decl "," ;
  48. separator nonempty Var "," ;
  49.  
  50. -----------------------------------------
  51. -- Statements
  52. -----------------------------------------
  53.  
  54. STypeDef.  Stm2  ::= "typedef" Type Id ";" ;
  55. SDecl.     Stm2  ::= Decl ";" ;
  56. SExp.      Stm   ::= Exp ";" ;
  57. SEmpty.    Stm   ::= ";" ;
  58. SInit.     Stm   ::= Type Id "=" Exp ";" ;
  59. SReturn.   Stm   ::= "return" Exp ";" ;
  60. SWhile.    Stm   ::= "while" "(" Exp ")" Stm ;
  61. SBlock.    Stm   ::= "{" [Stm] "}" ;
  62. SIf.       Stm   ::= "if" "(" Exp ")" Stm ;
  63. SIfElse.   Stm   ::= "if" "(" Exp ")" Stm "else" Stm ;
  64. SQual.     Stm   ::= "using" QConst ";" ;
  65.  
  66. coercions  Stm 2 ;
  67. terminator Stm "" ;
  68.  
  69. -----------------------------------------
  70. -- Expressions
  71. -----------------------------------------
  72.  
  73. EInt.     Exp16  ::= Integer ;
  74. EDouble.  Exp16  ::= Double ;
  75. EChar.    Exp16  ::= Char ;
  76. EString.  Exp16  ::= [String] ;
  77. ETrue.    Exp16  ::= "true";
  78. EFalse.   Exp16  ::= "false";
  79. EConst.   Exp15  ::= QConst ;
  80. EIndex.   Exp15  ::= Id "[" Exp "]" ;
  81. ECall.    Exp15  ::= Id "(" [Exp] ")" ;
  82. EMem.     Exp14  ::= Exp14 "." Exp15 ;
  83. EFAccs.   Exp14  ::= Exp14 "->" Exp15 ;
  84. EPostInc. Exp14  ::= Exp15 "++" ;
  85. EPostDec. Exp14  ::= Exp15 "--" ;
  86. EDeref.   Exp14  ::= "*" Exp15 ;
  87. EPreInc.  Exp13  ::= "++" Exp14 ;
  88. EPreDex.  Exp13  ::= "--" Exp14 ;
  89. ENot.     Exp13  ::= "!" Exp14 ;
  90. ENeg.     Exp13  ::= "-" Exp14 ;
  91. EMul.     Exp12  ::= Exp12 "*" Exp13 ;
  92. EDiv.     Exp12  ::= Exp12 "/" Exp13 ;
  93. EMod.     Exp12  ::= Exp12 "%" Exp13 ;
  94. EAdd.     Exp11  ::= Exp11 "+" Exp12 ;
  95. ESub.     Exp11  ::= Exp11 "-" Exp12 ;
  96. EShiftL.  Exp10  ::= Exp10 "<<" Exp11 ;
  97. EShiftR.  Exp10  ::= Exp10 ">>" Exp11 ;
  98. EGt.      Exp9   ::= Exp9 ">" Exp10 ;
  99. ELt.      Exp9   ::= Exp9 "<" Exp10 ;
  100. ELeq.     Exp9   ::= Exp9 "<=" Exp10 ;
  101. EGeq.     Exp9   ::= Exp9 ">=" Exp10 ;
  102. ENeq.     Exp8   ::= Exp8 "!=" Exp9 ;
  103. EEq.      Exp8   ::= Exp8 "==" Exp9 ;
  104. EAnd.     Exp4   ::= Exp4 "&&" Exp5 ;
  105. EOr.      Exp3   ::= Exp3 "||" Exp4 ;
  106. EAss.     Exp2   ::= Exp3 "=" Exp2;
  107. EAssDec.  Exp2   ::= Exp3 "-=" Exp2 ;
  108. EAssInc.  Exp2   ::= Exp3 "+=" Exp2 ;
  109. EIfElse.  Exp2   ::= Exp3 "?" Exp2 ":" Exp2 ;
  110. EThrow.   Exp1   ::= "throw" Exp2 ;
  111.  
  112. coercions Exp 16;
  113.  
  114. separator Exp "," ;
  115. separator nonempty String "" ;
  116.  
  117. -----------------------------------------
  118. -- Types
  119. -----------------------------------------
  120.  
  121. Tbool.   Type ::= "bool" ;
  122. Tdouble. Type ::= "double" ;
  123. Tint.    Type ::= "int" ;
  124. Tvoid.   Type ::= "void" ;
  125. Tconst.  Type ::= QConst ;
  126. Tref.    Type ::= Type "&" ;
  127.  
  128. separator nonempty Type "," ;
  129.  
  130. QCon.  QConst ::= [Const] ;
  131. CId.   Const  ::= Id ;
  132. CTemp. Const  ::= Id "<" [Type] ">" ;
  133. separator nonempty Const "::" ;
  134.  
  135. position token Id (letter (letter | digit | '_')*) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement