Nick Mudge Ignition Software Consulting & Development

I recently wrote a parser in C that parses arthmetic expressions. It's a stepping stone towards creating the parser for the compiler I'm working on. It takes as input a string that consists of an equation. It reads the string once while creating a graph data structure. The data structure can then be traversed with the "parse" function to make all the calculations in the correct order and arrive at the answer.

After it is compiled, it is ran like this: ./parser "var = 77 + 3 / 2 + 90 * 100;"

I made a little web interface for it that just takes an expression, passes the expression to the parser and then outputs the result from the parser to the webpage: http://nickmudge.info/c/arithmetic_parser/arith.php

Here's the C code:
parser.c
scanner.c
symbol_table.c

Next Steps

  • Right now the parser reads its input starting from the right, moving to the left. I want to rewrite some code to make it read from left to right. Providing syntax error information will be easier to do if it reads from left to right.
  • Add parentheses to the language.
  • Start adding more programming language constructs.

I think the compiler is going to implement ANSI C. This is part of the operating system I said I was going to write.

Lately I've been thinking about what good programming is. I don't think good programming is just opinion, but actually a real thing.

I think a lot of programmers don't really understand programming and think good programming is what code meets their latest fad methodology, design pattern, or is written in or is similar to how things are done in their new favorite programming language.

A good set of criteria for good code doesn't include whether it is object oriented, or is written in a functional programming style, or is strongly typed, or dynamic, or is written in one language or another, or uses this tool or that one etc. Code evaluated by such criteria is a matter of opinion. Technologies and methodologies can make it easier to write good code, but it depends on how they are used and what kind of problems they are being used to solve.

It is more important and useful to understand what good code is and aim to write good code, than to know and use a methodology or technology.

It could be said that any code is on a scale of quality with contrasting unattainable absolutes at each end. One end being the most horrible code possible and the other being the best code possible. To place any code on this scale, I'd judge it according to this:

How good code is depends upon how simple, direct, clear, short, correct and expressive it is in solving the problem or implementing the algorithm for which it is written while meeting the speed and efficiency demands required.

This sums it up exactly:

"Make everything as simple as possible, but not simpler." - Albert Einstein

(I have been hesitant to bash certain programming languages/methodologies/technologies because any such technology that can be used to write good code can be a good technology.)

OO C is passable