Does anyone have a BNF grammar for SPIN ?
Yoda
Posts: 132
I am curious if some one has a BNF grammar for SPIN - I did find one for the assembler from deSilva but was looking for a proper one for the SPIN language
Thanks
Thanks
Comments
Some time ago I started on an assembler for PASM with the idea that it would understand all of a normal Spin file except the actual Spin code. That is I wanted it to deal with VAR and DAT and accept all the spin syntax for defining the expressions used in constants, immediates in PASM etc.
This was quite a trick for me as Spin does some quirky things. There was quite some discussion here about how to handle some constructs. It crossed my mind to write this down in BNF as I went along. Sadly that only crossed my mind.
Now the assembler got to the point where it parses most stuff, creating the right constant and immediate values etc but does not actually emit any code. I think it was the arrival of BST that put and end to that developments.
Because I'm crazy the assembler is written in ADA. Potentially one could read that source code and start to right down the BNF from it. Then you'd have to tackle the actual Spin constructs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Wow - I was thinking of doing almost exactly the same thing myself - such a tool is pretty much all I need by way of a PASM compiler for Catalina. But even though I'm a fan it would never have occurred to me to do such a thing in Ada - much as I love it as a language, C is much easier for that kind of application (and you also have a wealth of existing tools to help out - up to and including completely configurable assemblers already writen in C!).
But I'd be interested in seeing it - any chance you might be willing to publish that code?
Ross.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Now that I'm thinking about it I'm going to be embarrassed to show that code to the world. You see the whole thing started to go horribly wrong.
Here was my demented reasoning at the time:
1) I had a toy compiler for Jack Crenshaw's TINY language that produces LMM PASM. TINY was to be expanded into something more useful.
2) It needed an assembler to get that PASM into the Prop.
3) I wanted to refresh my fading memories of ADA.
4) I wanted to try and understand the newer object oriented features of ADA, tagged types etc.
I think number 4) was the killer. Object orientation in ADA is actually impossible to understand. One of the best online ADA tutorials I found, written by a professor in the states, clearly showed this. His example of polymorphism was hopelessly wrong and he had put some cludge in there to make it produce the correct result. He also added a comment in the code that ADA was "absurd" at that point. He clearly did not realize the correct way to do it. Well, if the guys who were teaching this stuff don't "get it" then I give up.
The last nail in the coffin for this assembler was the arrival of Propasm, Homespun and BST. Now I could get off Windows for Prop development[noparse]:)[/noparse]
All in all the whole project was to much for me.
Having said all that I will post the code here in a while, I have to sort out which of my many backups was actually the last effort. I'll get GNAT installed again and make sure I can build it. Looking at it now, two years later, I don't understand any of it any more...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
I sympathize with your predicament - I had much the same experience when I needed to move from Ada83 (non-object oriented) to Ada95 (object oriented). I discovered that very few people really appreciated Ada's aproach to object orientation - even some supposed "experts" - mostly because they had been ruined by prior exposure to C++ (a language which has quite a sloppy and confused approach to object orientation).
Ada's approach is simpler, more consistent and also perfectly logical - but you have to discard the C++ mindset and approach it from first principles. For one thing, C++ uses the term "class" to mean several different and completely unrelated things - things which Ada uses distinct mechanisms to accomplish. Also, many of the advantages that object-orientation is claimed to deliver - such as improved code-reuse - do not in fact require object orientation at all, and existed in Ada well before it became "object-oriented". Object-oriented languages often use object oriented mechanisms to achieve these things simply because they lack more appropriate constructs for doing so. For example, Ada pretty much pioneered "generic programming" - which is in many circumstances a better way to achieve code re-use than "classes" - and does not require object-orientation at all. C++ recognized this and subsequently adopted it - to such good effect that you sometimes now hear people claiming that C++ came up with the whole notion in the first place!
A good one-page summary of the differences in approach can be found here.
But to get back to your code - if you can find it, please post it. I recently downloaded the latest GNAT Ada compiler, and have been looking for an excuse to use it. The trouble is that these days I feel too guilty whenever I take time off from Catalina!
Ross.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
Thanks for that link. It might help to clear things up a little. But it seems to me at the end of the day the mechanisms are the same. You define a blob of data with whatever you want in it, characters, integers, arrays, pointers bla bla. You can create as many instances of that as you like. As a bonus you can have it full of pointers to routines that operate on that data. As another bonus you can define other blobs of data and routines that builds on one or more of what you have already defined. As another bonus you get all the complexity that goes with managing all that.
Now the problem comes in the language used to describe all of that as much as the actual languages themselves. One example is the meaning of the word "class". I found it very hard to get into ADA because the language used to talk about it, object oriented or not, is so alien and complex.
Oh I found the code. Gives me headache to look at it. I have to check it still does whatever it did when I left it.
RossH: "The trouble is that these days I feel too guilty whenever I take time off from Catalina!"
And so you should[noparse]:)[/noparse] Perhaps I should not diver you with this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.