Create jlc.

3 views
Skip to first unread message

Alexander

unread,
Apr 13, 2011, 11:59:35 AM4/13/11
to Compiler construction 2011
In Appendix A, it is said that the command jlc myFile.jl should
generate myFile.class.
I assume this is made using shell script first calling on the compiler
(it generates myFile.j) and then calls the Jasmin jar (generate
myFile.j to myFile.class)
Since me and my lab partner haven't worked a lot with shell script, we
really don't know how to achieve this.
Are we supposed to use shell script for it, or is it an easier way?
Our compiler is written in Haskell.

Björn von Sydow

unread,
Apr 13, 2011, 1:15:15 PM4/13/11
to compiler-cons...@googlegroups.com
Hi,

there are several ways to do this. One is with a shell script; what is needed is a very simple script. Even if you do not have experience, a bit of googling should be enough to find help for this task; it will actually be worthwhile to learn how to write simple scripts.

But one can also manage without. From Haskell, the simplest is to use function system from module System; see

http://www.haskell.org/ghc/docs/6.12.2/html/libraries/haskell98-1.0.1.1/System.html

> system :: String -> IO ExitCode Source
> Computation system cmd returns the exit code produced when the operating system runs the shell command cmd.

So

system "java -jar lib/jasmin.jar myFile.j"

runs jasmin on myfile.j. Of course, you will need to build a string which takes the file name from the command line argumet and you will need to use the -d command line option to get the class file written in the correct directory. Probably you will need functions from System.FilePath to split file names into the directory name and the file name, and to remove the suffix etc.

Best regards

Björn

Reply all
Reply to author
Forward
0 new messages