I have just finished a 458 page 'crash-course' of the basic theory of compiler prac in pascal (which I had no knowledge of until now). IT IS REALLY EASY TO WRITE A WORKING COMPILER.
Anyway, I've discovered that writing a compiler is much easier if you break it down into 70 different parts (as defined in my BNF statements) and instead of writing a whole compiler it is even easier if you write a program to convert one language (in my case C) into assembly (to be processed by WLA - which takes care of all the memory addressing and SNES Headers (that really confuse me)).
SCC will rely entirely on static variables. This means that there can be over 256 bytes of variables, but functions cannot be called within itself (or any other linked function). (See the BNF for more reasons why I'm taking the static approach to SCC).
So far I've written a mathematical parser, that will convert almost any mathematical assignment to 65186 asm (ie. run it and type a=a+1 and see what comes out). I know that the code is not tight, but I will be able to fix most of it up with a peephole optimizer.
I have posted my current work (theory and prac) below. I would like my BNF statements checked by someone else (even though they're 5 pages long).
Here is a short description of a BNF statement, for those who don't understand what they are. Here is a short description.
This example BNF shows the how simple expressions are parsed:
Code: Select all
<expression> ~~ <term> (<addop> <term>)*
<term> ~~ <factor> (<mulop> <factor>)*
<factor> ~~ <number> | '(' <expression> ')' | <ident>
<addop> ~~ '+' | '-'
<mulop> ~~ '*' | '/'
A term is made up of one or more factors separated by '*'or '/' signs.
A factor is either a number or another expression in brackets or an identifier(variable, function or pointer).
Here is a diagram if your still confused:
Code: Select all
-----> expressions
/ / | \
/ '+' v '-'
| terms
| / | \
| '*' v '\'
| factors
| / | \
| |_ v _|
(expression) numbers identity
In the expression a + b * (b + c), the parser will load a and add it to b multiplied by the sum of b + c. Because addition is less important then multiplication (ect).
Can any suggestions or comments be made that affect the initial design and planning (modifications to BNF statements, parsing to assembly conversions, necessary tables (like variable/function tables) including what they contain and any optimization ideas)
Thanks:
MarcTheMER
(The un-ordained, un-sacrid scribe and un-disbeliever of the Church Of The SubGenius)[/code]