Haskell Quiz/Bytecode Compiler/Solution Pepe Iborra
Revision as of 18:21, 10 November 2006
This solution declares the type of Expressions as an instance of Num, thus don't really need to define a parser as long as the compiler is launched interpreted via 'ghc -e' . This trick is inspired from the Ruby solution.
It passes all the tests but due to the parsing trick some expressions need parentization. Namely expressions with negations such as "1*-1", which needs to be expressed as "1*(-1)".
In order to launch the compiler from the command line you should use the script:
ghc bytecode.hs -fno-implicit-prelude -fno-warn-missing-methods -e 'process ($1)'