A basic compiler based off of thejameskyle's super-tiny-compiler

example.mc 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ; This is a test program
  2. (include str)
  3. (assign twelve 12) ; This assigns the variable twelve, to the number literal 12
  4. (assign myvar (add twelve (subtract 6 2))) ; This assigns the variable myvar, to the result of adding the variable twelve to the result of subtracting 2 from 6
  5. (log myvar) ; This logs the value of myvar
  6. (log 6) ; This logs the number literal 6
  7. (assign twelve myvar) ; This reassigns the variable twelve to the value of the variable myvar
  8. (log twelve) ; This logs the new value of the variable twelve
  9. ; An example function definition
  10. (def myF ; Anywhere is a valid position for a comment!
  11. (log 0)
  12. (log twelve)
  13. (log 6)
  14. (log 6)
  15. (assign scopelol (add twelve 5))
  16. (log scopelol)
  17. )
  18. (def argTest (log $1) (log $2)) ; Functions take an unlimited number of arguments that can be referred to by $n
  19. (myF) ; Calling an argument-less function
  20. (log 0)
  21. (log 0)
  22. (log 0)
  23. (log 0)
  24. (log 0)
  25. (argTest 43 scopelol) ; Custom functions with arguments are called like any other
  26. (log "We got a string!")
  27. (argTest "You can call functions with strings!" "Yay!")
  28. (log "It supports multiline stri
  29. ngs without stupid escape
  30. characters")
  31. (repeat 5 (log 10))
  32. (log scopelol)
  33. (repeat scopelol (log 10))
  34. (if (eq 2 scopelol) (log "2 == scopelol") | (log "2 != scopelol"))
  35. (log (str::concat "Hello " "World!"))