DOI QR코드

DOI QR Code

Implementation of Nondeterministic Compiler Using Monad

모나드를 이용한 비결정적 컴파일러 구현

  • Byun, Sugwoo (School of Computer Science and Engineering, Kyungsung University)
  • 변석우 (경성대학교 컴퓨터공학부)
  • Received : 2014.01.07
  • Accepted : 2014.01.28
  • Published : 2014.02.28

Abstract

We discuss the implementation of a compiler for an imperative programming language, using monad in Haskell. This compiler involves a recursive-descent parser conducting nondeterministic parsing, in which backtracking occurs to try with other rules when the application of a production rule fails to parse an input string. Haskell has some strong facilities for parsing. Its algebraic types represent abstract syntax trees in a smooth way, and program codes by monad parsing are so concise that they are highly readable and code size is reduced significantly, comparing with other languages. We also deal with the runtime environment of the assembler and code generation whose target is the Stack-Assembly language based on a stack machine.

본 연구에서는 Haskell의 모나드 기법을 이용한 명령형 언어의 컴파일러 구현에 대해 논의한다. 이 컴파일러는 한 생성 룰이 입력 스트링의 파싱을 실패할 때 다른 생성 룰로써 파싱하는 backtracking 기능의 비 결정적 Recursive Descent Parser를 포함한다. Haskell은 파싱에 필요한 우수한 기능들을 가지고 있다. Haskell의 대수적 타입은 추상구문트리를 자연스럽게 표현할 수 있으며, 모나드 파싱을 적용한 프로그램 코드는 매우 간결하여 가독성이 좋고, 타 언어에 의해 구현된 것에 비해 코드의 양이 획기적으로 감소된다. 이 컴파일러의 목적 코드는 스택 머신을 기반으로 한 Stack-Assembly 언어로서 이것을 위한 코드 생성과 어셈블러 실행 환경에 대해서도 논의한다.

Keywords

References

  1. Graham Hutton and Erik Meijer, "Monadic Parser Combinators," Journal of Functional Programming, Vol. 8, Number 4, pp 437-444, Cambridge University Press, July 1998. https://doi.org/10.1017/S0956796898003050
  2. Graham Hutton, "Programming in Haskell," Cambridge University Press, 2007.
  3. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman, "Compilers: Principles, Techniques, and Tools," (2nd edition) Addison Wesley, September 2006.
  4. Sugwoo Byun, "Development of an Assembly Language Interpreter Using Monad," Software and Applications: Journal of Korean Institute of Information Scientists and Engineers, vol. 27, Number 5, pp. 403-410, May 2010.
  5. Kiyoung Ahn and Jeonghoon Park, "Learing Functional Programming in Haskell," Daelim-Press, 2009. (Korean-translated version of [2]).
  6. Simon Thompson, "Haskell: The Craft of Functional Programming," (third edition), Addison Wesley Professional, 2011.
  7. Haskell Homepage. http://haskell.org.
  8. Commercial Users of Functional Prog., http:// cufp.org.
  9. Eugin Moggi, "Computational lambda-calculus and monads," IEEE Symposium on Logic in Computer Science, June 1989.
  10. Philip Wadler, "Comprehending Monads," Proceedings of the 1990 ACM Conference on Lisp and Functional Programming Languages. 1990.
  11. Haskell Understanding Monads, (http://en.wikibooks.org/wiki/Haskell/Understanding_mo nads)
  12. Scala Homepage, http://www.scala-lang.org