Learning Ruby

So, It’s been a while since my last post. I recently graduated from college and accepted a job working for Cyrus Innovation. The first project I will be joining is a Ruby on Rails project, so I’ve spent some time lately learning a bit more about Ruby. To help with this, I’ve started making attempts at solving some Ruby Quiz problems, amongst other things. I decided to make a new page where I can start posting some of my solutions, and maybe other Ruby stuff, as I continue to learn. I’m very excited about everything thats going on in my life right now, so hopefully I can start posting more frequently as I get settled. In the meantime, check out my solutions and tell me all the things I did wrong!

More Javascript Fun

So, I’ve seen a variety of web pages with components which can be freely dragged around the page. Things like when Facebook used to let you freely drag and rearrange some of your profile boxes. Last night I somewhat randomly decided to find an easy way to do this component dragging using Javascript. Sure enough, I immediately came across a very simple Jquery plugin called EasyDrag. After finding it, I suddenly decided I wanted to make something using it. All I wanted to do tonight was create something simple enough that I could finish at least a very basic example in one quick sitting. So I decided to create a trivially simple puzzle. The puzzle itself is pretty self explanatory. There are 4 colored triangles which start on the left side of the screen. The goal is to drag them onto their matching grey triangle  in the middle of the screen. Once a triangle is correctly placed, it cannot be moved any more until the page is refreshed. Yes, this is about on par with puzzles for your average 1 year-old. Oh well, I’ll create something more interesting once I get a bit more time.

The puzzle itself can be found here. My javascript code can be found here.

The Muffinman!

Muffinman is a project I’ve been working on for a while now. Me and one partner, Dale Sample, have been building this tool as our senior design project.

What is it? It is an automated testing tool for Java Swing applications. There are lots of things I want to say/write about this project, but I think I’m going to hold off on all of those ideas for now since I feel they would do more good as a series of seperate posts instead of one disorganized post.

I took a little time a couple days ago to start setting up a simple website for the project though. Please note: The site in its current state of writing this does not have all the content, features, and design I’d like. However, I wanted to at least get something simple online quickly to create some sort of public presence about the project. As time continues in the weeks ahead, I will be adding and changing the site around as well as writing about the project and its development.

For now, check out Muffinman and keep an eye out for more information in the weeks ahead!

This Just In: I Like Jquery

I know I’m not the first person to point it out, but Jquery is pretty damn cool. I had read about it a little while back, but I never really bothered to look into it in much detail. Recently, I took another look at it and started playing around with the basics and found it to be a lot of fun. I’ve always liked Javascript in the times that I’ve used it, and Jquery makes so many of those little cool features in web pages trivially simple. I’ll probably start trying to integrate more and more little snippets of Javascript in any of the websites I post here (I’m planning on posting about another one of my projects soon) just to get a little more experience using it since I’m still a newbie.

A Simple Interpreter in C++

A little while ago I made my first post here and put up a link to a simple interactive shell I had made. Now, If you went out of your way to play with the shell it might not take very long for you to find some issues with it. If you are bold enough to actually open up the source code for it, you might find the overall implementation to be fairly poor. Maybe it isn’t a good idea for me to post code that is not as good as it can be since it could reflect poorly on me as a programmer. However, to me, the goal of building things like this is to learn.  I am perfectly fine with the idea that the code I write is not perfect and I don’t think that should say anything bad about me as a programmer up front. In general, I would hope the ambition to continuously learn and improve with everything I create outweighs the fact that these creations may not end up being brilliant or flawless pieces of software.

So what was the problem with the interactive shell?
Well, for starters, there was no solid organization for how I tried to parse or interpret the commands entered by the user.
What do you mean by that?
At the time of starting the project, I had absolutely no experience or knowledge of compiler theory or the general organization of a compiler/interpreter. In other words: I didn’t know that a compiler is usually broken up into a lexer and parser. As a result, no formal tokenization really ever takes place, which doesn’t make the process of parsing and evaluating expressions any easier.

I don’t want to spend too much time talking about what I didn’t do correctly, I just want to mention some points which inspired me to take another stab at a similar problem in a more intelligent way. As I mentioned, the interactive shell was primarily motivated by my desire to build something in Javascript and it was just something to keep me coding at the time.  It was not about trying to learn intelligent methods of parsing. Recently however, I decided to try to build a basic interpreter in C++ and I wanted to go about it in a more organized fashion.

All I wanted was the ability to, once again, evaluate arithmetic expressions and to allow the creation and use of variables in these expressions. Instead of being an interactive shell, it would simply read in a full script from a text file and evaluate the expressions line by line and print any results out to the console. I admit, this is not terribly useful, but I wanted to try and do things more intelligently.

What do I mean by ‘more intelligently’? I mean that I wanted to have a formal lexer which performed tokenization first, and then these tokens would be used by the parser to evaluate the expressions based off of a well defined grammer. So what all is needed?

First, I defined the valid set of tokens which are allowed:

NUMBER (an integer number. no decimal places)

IDENTIFIER (basically a variable name. can start with upper or lower case letter. can contain letters, digits, and underscores)

LINECOMMENTS(the usual ‘//’ for line comments is allowed. these arent actually technically a token since they are ignored by the lexer)

PLUS(+), MINUS(-), DIVIDE (/), MULTIPLY (*), EQUALS (=), SEMI(;), LPAREN( ‘(’ ), and RPAREN ( ‘)’ ).

Given these tokens, I define a very basic grammer for the different types of statements which are valid. Basically we only have 2 types of statements: a straight forward expression to be evaluated, or an assignment statement where the value of an expression is placed into a variable.

An assignment statement is defined as: IDENTIFIER EQUALS expression SEMI

where expression is defined as one of: NUMBER or IDENTIFIER or LPAREN expression op expression RPAREN SEMI

and op is defined as: PLUS or MINUS or DIVIDE or MULTIPLY

Furthermore, the value of a straightforward expression is printed to the console while nothing is printed in an assignment statement. So, an example script could end up looking like:

//This is just a simple script…

(3+4);
(12 - (3*7));
((10-5) * (3+5));
(((5-2) + (3*2)) + 10);
A = (3+4);
A = (A + 4);
B = A;
B;

The syntax is far from elegant, but that’s not really the point. The parsing is my attempt at something resembling recursive descent parsing, which you can read a bit more about here.  My actual code is heavily influenced in style from that in the article. However, I did do some things a bit differently, especially because I also wanted to actually evaluate the expressions as I was parsing them.

It’s still nothing amazing, but I feel like my code is more easily understood and organized for now. speaking of the code, you can get it here. I wrote it in Microsoft Visual C++ Express Edition and I simply zipped up the Visual Studio project to post. Take a look at it if you’re interested and feel free to share any comments or critisism. Its getting late, and I’m off to bed. Goodnight….

Why, Hello There…

Yeah, I made a blog.

As I approach graduation I’ve become more and more torn as to how I ought to spend my time.  I have more ‘free’ time than I have had in years, and plenty of ideas and projects to use it for. However, over the last few weeks I have spent most of my time thinking about what I could be doing, instead of doing much of anything. I decided to create this blog in order to help stop this. In an attempt to no longer think or worry too much about jobs, moving, classes, or anything else. I have decided to focus on doing one thing: coding.

This blog might be used for all sorts of things. Perhaps sharing thoughts about programming and software development in general and anything else that is on my mind.  But most of all, it is a place for me to write about and share the projects I want to build in my spare time. This blog is a place for me to start seeing some sort of  organized results for the things I create.

And, obviously, it’s a place for you to see it all as well…

On the right side is a link to where I plan to post some info about projects as I work on them. I’ll probably write more about projects of interest in separate posts as well. For now, I’ve added a link and a little description about a simple interactive shell I wrote a while back. Check it out. More will be coming.