Advertisement
PifyZ

Sous-ensemble du langage Bootmonkey

Oct 30th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. chunk = { func_decl }
  2.  
  3. name = { "a"..."z" | "A"..."Z" | "0"..."9" | "_" }
  4.  
  5. string ::= """ (* tout et n'importe quoi *) """
  6. number ::= "0"..."9"
  7.  
  8. block ::= name "=" expr |
  9. "if" expr "{" block "}" { "else if" expr "{" block "}" } [ "else" "{" block "}" ] |
  10. "loop" [ number ] "{" block "}" |
  11. "while" expr "{" block "}" |
  12. "for" name "=" number ( "to" | "till" ) number [ "by" number ] "{" block "}" |
  13. "for" name "in" iterable "{" block "}" |
  14. "return" expr |
  15. "break" |
  16. "continue"
  17.  
  18. expr ::= value |
  19. func_call |
  20. expr op_binary expr |
  21. op_binary expr
  22.  
  23. value ::= "nil" |
  24. "false" |
  25. "true" |
  26. number |
  27. string |
  28. iterable
  29.  
  30. iterable ::= "[" { expr "," } "]" |
  31. "{" { string "=>" expr "," } "}"
  32.  
  33. func_decl ::= func_name "(" par_list ")" "{" block "}"
  34. func_name ::= name { "." name }
  35. par_list ::= par_arg { "," par_arg }
  36. par_arg ::= [ "&" ] name
  37. func_call ::= func_name "(" { expr } ")"
  38.  
  39. op_binary ::= "+" | "-" | "*" | "/" | "^" | "%" |
  40. "<" | "<=" | ">" | ">=" | "==" | "<>" |
  41. "and" | "or"
  42.  
  43. op_unary ::= "-" | "not"
  44.  
  45. -----
  46.  
  47. Exemple d'utilisation :
  48.  
  49. main() {
  50. if 1 + 1 == 3 {
  51. Console.log("1 + 1 = 3")
  52. } else if 1 + 1 == 2 {
  53. Console.log("1 + 1 = 2")
  54. } else {
  55. Console.log("1 + 1 = ?")
  56. }
  57.  
  58. loop 6 { }
  59.  
  60. while true { break }
  61.  
  62. for i = 0 to 50 by 2 { }
  63.  
  64. for i in [ 0, 50, 60 ] { }
  65.  
  66. return 0
  67. }
  68.  
  69. -----
  70.  
  71. Pas entièrement la même syntaxe mais peut servir de référence :
  72. http://pastie.org/pastes/6574368
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement