So you searched and found Backus Naur Form. And maybe you saw some examples like (this is from Oberon):
number = integer | real.
integer = digit {digit} | digit {hexDigit} "H" .
real = digit {digit} "." {digit} [ScaleFactor].
ScaleFactor = ("E" | "D") ["+" | "-"] digit {digit}.
hexDigit = digit | "A" | "B" | "C" | "D" | "E" | "F".
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".
So now you can define your language!
Then you can parse it following these rules.
Hi,
Care to explain what all that was about ?
Frankly, I am interested to write my own C like compiler too.
Example, in C, you use PRINTF to spit an input on the screen but my language's command would be simply PRINT.
So, how can I teach this to the C compiler so if anyone now types in a source code PRINT it actually means PRINTF ?
I mean, underneath since C is programmed to understand the PRINTF only then I must teach it to understand the PRINT command too.
SO, how do I do it ?
What's the first thing I do ?
I will not only change 1 (PRINTF to PRINT) only but I will change others too.
For example PRINT in my language is CHAP so if anyone writes in the source-code CHAP then my compiler must do the same function as PRINTF.
Understand ?
Frankly, I really do not want to write a whole compiler but teach the C compiler to understand other words (PRINT, CHAP) too.
Get it ?
This way, people of my country who do not know english can learn the C in our own language.
So, to do all this, which part of the C compiler's source codes should I change/update ?
Or alternatively, shall I give you my function words (PRINT, CHAP, etc.) and you can change/add them on the C compiler ?
Afterwards, I can check the source code to see which parts you have updated. This way, I can learn which parts need updating should I wish to create another version of C in another language this time such as Arabic and then Hindi and then Urdu etc.
Cheers.