fork download
  1. #lang racket
  2.  
  3. (require (only-in srfi/13 string-tokenize))
  4.  
  5. (define (translator some-file)
  6. (with-input-from-file some-file
  7. (lambda ()
  8. (let loop ((line (read-line)) (acc '()))
  9. (if (eof-object? line)
  10. (with-output-to-file
  11. (string-replace some-file "." "-rkt.")
  12. (lambda ()
  13. (let loop ((ls (reverse acc)))
  14. (unless (null? ls)
  15. (display (car ls))
  16. (newline)
  17. (loop (cdr ls))))))
  18. (loop (read-line)
  19. (cons
  20. (if (char=? (string-ref line 0) #\#)
  21. (if (char=? (string-ref line 1) #\#)
  22. (format "(~a)" (string-trim
  23. (string-replace line "##" "label")))
  24. (let ((ls (string-tokenize
  25. (string-trim (substring line 1)))))
  26. (case (string->symbol (car ls))
  27. ((back) (format "(~a ~s)" (car ls) (cadr ls)))
  28. ((putChar)
  29. (format "(~a ~s ~a)" (car ls)
  30. (cadr ls) (caddr ls)))
  31. ((branch)
  32. (format "(~a ~a ~s ~a ~s)"
  33. (first ls) (second ls)
  34. (third ls) (fourth ls) (fifth ls)))
  35. ((jump)
  36. (format "(~a ~a)" (car ls) (cadr ls)))
  37. (else
  38. (format "(~a)" (car ls))))))
  39. (format "(msg ~s)"
  40. (string-trim
  41. (string-replace line "\\n" "~%"))))
  42. acc)))))))
Success #stdin #stdout 0.47s 81336KB
stdin
Standard input is empty
stdout
Standard output is empty