Language Interpreter in PortablE

I’m sure you have noticed by my posts that I’ve been on an Amiga E language binge. More specifically I am using PortablE by Chris Handley, which I have already posted about. I’m writing PortablE code using the AROS operating system.

Chris asked me what I would like to write in PortablE. I told him how I have always wanted to learn how to create my own programming language, but I needed more experience. He basically said I should just start trying to do it and learn that way. Chris has actually taken me under his wing and has been helping me with it. I am blessed that he has taken the time to help me with this. I cannot thank him enough.

So, Chris took his knowledge of parsers and wrote a very simple toy interpreter in PortablE. We have been calling it the toy interpreter for now. He sent it to me and explained that it could only parse a PRINT command in a file named code.txt. You could only print numbers with it. This gave me a great starting point. I studied the code carefully. I had to look up many statements, because I didn’t know the PortablE language yet. But it turned out to be a very good learning experience.

Chris commented the code well too. This helped me while tracing through the code trying to figure out what it was doing.

My next challenge was to make the interpreter understand how to print a string and not just a number. I studied the interpreter code many times and finally realized what I needed to change to make it print a string. I had an old code file of the toy interpreter that Chris had sent me to compare to see if I was correct in my thinking and I was. Chris has made some adjustments to improve the code as we have worked our way through this. He plans to include the toy interpreter as an example when he officially releases PortablE.

Of course this is just a start and I have many more features to add to this. I plan to keep making additions to the interpreter and expand my learning experience even further. I am really enjoying the PortablE/Amiga E style of programming.

If your reading this thinking, “what about Lisp?”. I haven’t quit using Lisp. I plan to split my time between PortablE and Common Lisp. I think my experience so far with this interpreter will help me when I try to write parsers in Common Lisp. I’m feeling very comfortable about concentrating on these two languages. Besides Lisp, I have been trying out many different languages in the past six months and I feel like I have finally settled on these two languages.

What’s that? You want to see what PortablE code looks like? No problem at all. Here is the code for the toy interpreter so far. I’ll provide it as a link since it is too long to post. This code has parseLET() included, but I have not worked with it yet. I was concentrating on the PRINT command first.

Interpreter.e

Amiga E IRC Channel

I have been pleasantly surprised with the activity of the new Amiga E programming channel on Freenode at #AmigaE. In the past three days, I’ve had Leif Salomonsson, developer of ECX in the channel. Chris Handley, developer of PortablE in the channel. Tomasz Wiszkowski, developer of CreativE in the channel.
Then tonight, the creator of Amiga E, Wouter van Oortmerssen logged into the channel! I was elated! I have been a fan of Wouter’s for a long time. You can find his web site in my blogroll in the right navigation. He is definitely my favorite programmer. So it was a pleasure to see him in the channel and chat with him for a bit.

Amiga E Programming for AROS

Chris Handley has made a beta version of his Amiga E implementation called PortablE available for AROS now. You can only obtain a copy of PortablE through the Amiga E mailing list available at http://www.freelists.org/list/positron. If you register and ask Chris for it, he will send you a link. Chris said PortablE is working well and may not be in beta stage much longer. So he will provide a link on the PortablE web site once the beta is finished.

I have been testing PortablE on AROS lately. In short, here is how PortablE works. You write your Amiga E code, use PortablE to translate it into a .cpp file and then use any C++ compiler to compile the file into an executable. I have been using g++ inside AROS. If you want to go to Amiga Classic, you can use PortablE to translate to Amiga E and then move it to Classic where you can use an Amiga E compiler like CreativE. More detailed information is available on the PortablE web site at the link I provided above.

There are a few things you need to setup in AROS for things to work. For one, you need a Stack of 100000. You can set this up by typing “stack 100000″ (without the quotes) in the AROS shell. You need to do an assign for PEmodules. Do this with this command: Assign PEmodules: VolumeName:PEmodules
You can put Assign commands like this in your user-startup file in AROS so you don’t have to do it everytime. User-startup is in System:S

You also need some Assigns placed in there for g++. The exact Assigns you need can be found in the INSTALL file located in System:Development

So here are the commands I entered on the command line once I had things setup to test a simple program.

PortablE test.e (This gave me a file named test.cpp)

g++ test.cpp -o test (This gave me a file named test to run as an executable)

So then I just typed in the name of my executable at the shell and it ran and printed “Hello, World!”.

Don’t forget to come and hang out with us on the #AmigaE IRC channel on Freenode if you are interested in Amiga E programming. I have recently created an Amiga E IRC channel on Freenode at #AmigaE.

Enjoy!

Next Indiana Programming Group Meeting

The Indiana Programming Group (This is what we decided to call ourselves.) is having our next meeting Wednesday, April 23rd at 5:30pm. We are meeting in Terre Haute, Indiana on the campus of Indiana State University at the Unix Lab in Root Hall. It is open to the public.
Our speaker for this meeting is tentatively Paul Cardwell. He is a local web developer specializing in his own PHP programming architecture.

Steve Baker has just setup Mailman to handle our new mailing list. To subscribe to the list, just go to: IPG Mailing List
I’ll be sending future news and meeting dates to this list, so if you are interested, please subscribe.

This is a new programming language group in Indiana. The group is for anyone interested in programming no matter what the language is. We do enjoy Common Lisp, so Lispers are definitely welcome anytime! But we have members with many different backgrounds in many different programming languages. I will try to have a speaker at each meeting. But anyone is welcome to discuss or present anything about programming.

Open File and Read

I mentioned I needed a project to work on and Zach Beane mentioned an SVG parser. I thought it sounded really cool, but I have never programmed a parser before in any language. So, I started writing code yesterday that hopefully will turn into an SVG parser. I started with simply opening an SVG and reading it line by line.

An SVG is actually created by using XML. I heard you can use javascript to do this, but I don’t know much about that yet. I have been reading the w3.org site for SVG information. They had an example of an upside down triangle, so I grabbed that to test my code. Here is the XML code that makes up the SVG. If you copied this to a text file and then saved it as a .svg, you could open the file with your web browser and see the red upside down triangle it creates.

<?xml version=”1.0″ standalone=”no”?>
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1//EN”
“http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd”>
<svg width=”4cm” height=”4cm” viewBox=”0 0 400 400″
xmlns=”http://www.w3.org/2000/svg” version=”1.1″>
<title>Example triangle01- simple example of a ‘path’</title>
<desc>A path that draws a triangle</desc>
<rect x=”1″ y=”1″ width=”398″ height=”398″
fill=”none” stroke=”blue” />
<path d=”M 100 100 L 300 100 L 200 300 z”
fill=”red” stroke=”blue” stroke-width=”3″ />
</svg>

I have been using CUSP lately to do all of my Common Lisp coding. Especially after talking with Jasko at the programming meetup we had last week. I like using it, plus I can use it on Windows and that is all I have at work, so it makes it more convenient.

What took me the longest with this code was the Windows pathname. I wasn’t sure how SBCL looks at that. SBCL is what CUSP uses as it’s implementation, by the way. Which is great, because I want to use SBCL. I had to play with it quite a bit but finally figured out the pathname. I placed my tri.svg file in my C:\lispstuff directory. So after playing in the REPL and trying different options, I figured out SBCL reads it as “C:\\lispstuff\\tri.svg”.

Once I had that, I knew the best thing to use to open a file and read it was the Common Lisp macro WITH-OPEN-FILE. Peter Seibel talks about this in his Practical Common Lisp book in chapter 14. Then I used a do loop to step through each line of the file and “format” to print them out. Here is the code:
Keep in mind this code is indented, but WordPress really sucks when it comes to handling code. I need to switch this to a different blog.
I uploaded the actual text file so you could see the indention, get it here.

(defun pjmain ()
(with-open-file (stream “C:\\lispstuff\\tri.svg”)
(do ((line (read-line stream nil)
(read-line stream nil)))
((null line))
(format t “~A~%” line))))

I will have to revisit this code for the parser, because I need a way for it to ask the person what SVG file they would like to parse. The next thing I need to do is try to parse this. I have a lot of reading to do. I know Zach mentioned he only needed the path data of the SVG, so I will concentrate on obtaining that first.

Any tips or suggestions on any of this is definitely welcome. I am a beginner after all.

Meeting, Main Topic - Common Lisp

I had a great time at the first Indiana State University Programming Meetup! This meeting went very well and it actually went much better than I expected.

When I first arrived on campus, the first task was to find a parking spot. I just parked in the student lot where I used to park years ago while attending ISU. (I won’t say how many years. ;-)) While I was walking to Root Hall, I noticed Tim Ritchey and Tim Jasko walking right in front of me. If it were not for their pictures on the bitfauna web site, I would have never known. Tim Ritchey was on the phone, so I chatted with Jasko on the way in.

It had been about 17 years since I had been in the Unix Lab at Root Hall, so I could not remember where it was once we walked inside the building. I had to swallow my pride and finally ask someone. When we walked in, my long time friend, Steve Baker informed us that the pizza was on it’s way. I want to thank Steve for helping me set this meeting up and paying for the pizza! It was very nice of him to help with everything.

There were nine people that showed up for the meeting. A guy named Brad came all the way from Purdue to attend. He heard about the meeting by reading it on Planet Lisp. There was a student there from Rose-Hulman Institute of Technology that was just starting a class project that involved using Common Lisp. I had e-mailed his professor about the meeting and he passed it along. That was pretty cool.

So after I kicked off the meeting, Tim Ritchey and Tim Jasko took over. They began by taking us through a presentation of their desktop management system Paragent. To create Paragent they used the Common Lisp web framework Uncommon Web or UCW. They used a mySQL database for the backend. They also used the graphics library, CL-Vectors for a lot of their interface, which was awesome! Tim Ritchey then ssh’ed into their server to show us Common Lisp running and how they can easily add to the application, compile and make it live quickly. They were using SBCL for their Common Lisp implementation.

After the discussion on Paragent, Tim Jasko showed us his Common Lisp plugin for Eclipse known as CUSP. He took us through autocompletion, macro expansion and quick access to the Hyperspec, just to name a few. I highly recommend CUSP for Common Lisp development. I have started using it and I really like it. CUSP is a great way to get started using Common Lisp, especially if you are a beginner. It is much quicker than setting up Emacs/SLIME. CUSP also uses SBCL as the Common Lisp implementation, which is great!

There were many questions for Tim and Tim afterwards. Everyone seemed to enjoy the demo. I want to thank Tim and Tim for coming, they did a really good job of presenting. Who knows, we may even have gained a couple new Lispers after a presentation like that. It really helped to observe how veteran Lispers wrote their code. It helped me confirm I was doing things right as well as showed me some things I didn’t know.

Afterwards I had a chance to chat with both Tim’s. We talked about Paragent and CUSP. Plus we talked about how nice it would be to have about a half day seminar/meetup of Lisp users in Indianapolis. I hope we can put something like this together. We would like this to be a large gathering if possible.

Steve and I will be discussing what is on the schedule for the next meeting. We hope to do this Indiana State University Meetup every month. I need to discuss this more with Steve and figure out what we want to do. It turned out to be a great start with a lot of Lisp goodness!

Next Page »