Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Program Announcements / DBPre - a fully fledged DBP preprocessor

Author
Message
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 27th Sep 2006 18:42 Edited at: 27th Sep 2006 18:49
Link to the english version of DBPre: http://www.thequest03.de/DBPre_RC1_english.rar

Hi everybody,

something I always missed in DarkBASIC Pro, was a descent (c-style) preprocessor, so I recently decided to write my own.
I'm finished with RC 1 .

It works mostly exactly like it's gnu-c-counterpart, i.e. everyone who has already worked in C with it's preprocessor, should have no problems using this in DarkBasic.
In fact, it is written on the basis of the following documentation (http://tigcc.ticalc.org/doc/cpp.html).

There might be a few exceptions though and some things are just not supported.
Here is the complete feature-list of things supported and tested:

Quote: "
1. macros and inline-functions may be defined/undefined/redefined


2. testing, if a given macro is defined and (of course) performing actions (#ifdef, #ifndef, #if, #else, #elif, #endif)


3. testing, if a given (constant) expression has a certain value or fulfills a certain equation


4. compute constant expressions at compiletime (in doubled precision)


5. get the actual line and file (__LINE__, __FILE__)


6. get the time, date and currently parsed function (__TIME__, __DATE__, __FUNC__, __TIMEDATE__)


7. get ASCII from character (e.g. 'a', 'b', etc.)


8. use control-characters in strings ("Hello\nworld")


9. concatenation of tokens (##)


10. stringification of tokens (#)


11. special #options for setting values in the setup.ini (see changelog at the bottom)


12. dbp-comments are removed (we all know, the dbp-compiler has had its issues with ignoring comments - now they just don't pass through)
"


Since the preprocessor will necessarily change the sourcefiles formatting, the error lines given by the compiler, will not match anymore.
This problem has been taken care of, by using hooks to inject code into the original compiler, which automatically transform "wrong" lines into error lines (and file) matching your code.
This feature has been testet with the standard-IDE, BlueIDE and jaPROe and seems to work for all three.
I expect that to work with every IDE now and in the future, because it simulates compiler-behaviour.

Installation is simple.
Simply copy the files included in the above archive into the DBP-compiler-dir and execute the DBPre.exe.
It'll then rename the original compiler into "compiler.exe" and itself into "DBPcompiler.exe".
In addition, a keyword-file called dbpre.ini will be created in the editorkeywords folder and a file called "dbpre-uninstall.bat" in the original compiler folder.
To uninstall DBPre, simply doubleclick that file and everything is, as it was before (i.e. no registry-entry or something like that).
This software will in no way harm your computer or DBP, nor will it "call back" to me, the creator (if you don't believe me, you may wait until the source is open to compile it yourself).

I recommend you to read the documentation for the GNU-C-Preprocessor in advance.
Nearly everything should be supported, with a few exceptions.
If something is supported, but does not work as described in the manual, I consider it a bug and would be pleased to hear from you soon .
If something is not supported, but you would like to have it supported for the final release, you may email me or just write that into this thread as a suggestion (email-address is: d-man ät thequest03.de).

With the final release, I intend to also release the (C-) source code, so please help me by testing this tool to have a stable first release!

Changelog from public beta to RC1: (public to the german board)
Quote: "
Version 1.0.0.587
- first non-beta release -

ADDED
* support for the "defined"-Keyword in evaluations for quickly determining wether a given macro is defined or not
* support for the predefined macro "__FUNC__", which returns the name of the currently parsed function
-> top level is called "$main$"
* support for the stringification operator "#", which stringifies macros and words
-> ensured, that it only works in macros, not normal source
-> also ensured, that internal quotes are properly replaced
* support for the concatenation operator "##", which connects two words in the final sourcecode
-> ensured, that it only works in macros, not normal source
* support for the compiler directive "#option" for specifying preprocessor options
-> added option "mergelines", which enables global line concatenation, when _ or is found at an end of line
-> added option "nomergelines", which disables global line concatenation (default)
- concatenation in definitions of macros is always active
-> added option "release", which disables error-checking in the final exe and no local temp folder at execution time
-> added option "debug", which enables additional error-checking such as array boundary checks and local temp folder at execution time
* multilanguage support
-> supported languages at the moment are german and english

CHANGED
* introduced warnings, which do not stop the compile process, but may show possible errors
* all comments are now ignored globally, even in macro definitions
* if non constant identifiers are found in an constant evaluation, a warning is thrown and the identifier is assumed to be zero
* leading and trailing whitespaces in parameters are now ignored - whitespaces between words or parameters are still recognized

FIXED
* error was illegally thrown, when identifier used in evaluations, which would normally have been defined, but where turned off through conditional compiletime
* replacement of inline macro parameters was incorrectly done, if the first part of parameter content was the name of any parameter
* small memory leak, when new layers in symtab were created (strdup was accidently called twice and one pointer got lost)
* compiler reported error lines are now corrected automatically by the preprocessor
* error lines reported by the preprocessor should now be more accurate
* preprocessor errors now simulate compiler behaviour, hopefully causing 100% compatibility with all DBP-IDEs
* negative numbers in expressions are now valid, even in exponents
* parameter stack is now only limited by available memory instead of static 100 entries (I wonder if anybody needs more than 100 parameters though)
"


I know, there might be some things unclear, but I try to write the documentation for the english version ASAP .

Feedback would be greatly appreciated!

God is real, unless declared integer.
empty
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 28th Sep 2006 02:07 Edited at: 28th Sep 2006 02:07
Great to hear you got the error line reports working now.
Excellent job!


Play Nice! Play Basic! -- Styx Plug-In for DBPro- Coming September 2006!
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Sep 2006 08:21
Wow, this is a pretty good idea! Unfortunately I don't program a lot in DBP anymore so it won't get a lot of use out of me, but I'll install it sometime and give it a try.

Tempest - P2P UDP Multiplayer Plugin (DBP/DBCe)
Download the free version
Darth Vader
18
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 28th Sep 2006 09:39
What exactly is a preprocessor?


Jack LOL
17
Years of Service
User Offline
Joined: 4th Aug 2006
Location: Near the CPU Close to the graphic card
Posted: 28th Sep 2006 15:36
ooooo i wanna know too

(forgive my english) lol?! xD
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Sep 2006 16:54
.. Or rather than spam a thread with questions you could look it up.

http://en.wikipedia.org/wiki/Preprocessor

Tempest - P2P UDP Multiplayer Plugin (DBP/DBCe)
Download the free version
Death Swarm
17
Years of Service
User Offline
Joined: 25th Aug 2006
Location:
Posted: 29th Sep 2006 18:32
looks good i'm going to try it out in a minute. The newline \n is probably the most useful feature for all the programmers especially me cos i'm sick of multiple prints

I know what your thinking
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 29th Sep 2006 20:55 Edited at: 29th Sep 2006 21:03
Thanks for the comments so far.
There is something I forgot to mention... when using BlueIDE, you first have to turn off BlueIDEs own preprocessing abilities, because it will complain about the commands used (Tools > IDE Preferences > Advanced, unmark enable preprocessing by editor plugins).

Secondly, the "\n" really is an EOL marker, i.e. theres no multiple prints used and therefore the next print command will start at line 2, even if the old print also printed in line 2.
I might change that, if I get feedback on this issue, otherwise it will remain like that.

Example:


I also forgot to mention, that you have line control via the #line-directive.
You might set a new codeline and file at any point in the source.
All error-messages will then be relative to this definition.

Example:


When using DBPre I also recommend, that you use the #include directive, rather than the IDE means of including source, because the IDE will simply concatenate all included files to a big chunk of code and the preprocessor has no means to discover, to which source file a line actually belongs, when an error occurs (because it only gets a big sourcefile).
When you still want to use the IDEs include devices, you may want to make use of the line-control directive via #line, to explicitly tell the preprocessor, which file and line this is, when an included file starts.

God is real, unless declared integer.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2006 03:08
I have this installed now, and it's gonna stay that way. This is really great work.

One question - Where does the preprocessor search when including with < and >?

... and a few suggestions/requests:

- More options at the project level, such as window or fullscreen mode, initial resolution etc - in fact, all of the options you would see in the original IDE's 'settings' sidebar.

- A DBPro compatible multi-line define. When you use the traditional backslash, you don't quite get what you expect.



It's right for C, but doesn't seem quite right for DBPro. It would be nice if the multi-line aspect of the define was preserved. Currently you have to play around with colons to get the correct line separation.

- #constant treated like #define, for compatibility.

- A define for the compiler version information, for example the latest version of DBPro might be reported as 1062

D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 30th Sep 2006 04:36 Edited at: 30th Sep 2006 05:56
Quote: "I have this installed now, and it's gonna stay that way. This is really great work."


Great to hear . Makes my work worth the time.

Quote: "One question - Where does the preprocessor search when including with < and >?"


Nowhere, this should throw an error.
This feature is one of these not supported ones, because it doesn't make sence for DBP in my opinion. DBP has no equivalent concept of standard-library or headers, as it is multipass and sequential conceptionally.
In C you have the opportunity to compile sourcefiles independent from each other and link them separately - this is obviously not the case with DBPro.

I thought about using #include <DLLNAME> to explicitly include a plugin, but then you also would've needed something like #exclude imho.
If you have concrete conceptional ideas of implementing something like the include of standard-libraries in C, feel free to tell me about them . I'll be happy to implement that for the final release, if these make sense.

Quote: "- More options at the project level, such as window or fullscreen mode, initial resolution etc - in fact, all of the options you would see in the original IDE's 'settings' sidebar."

Quote: "- A define for the compiler version information, for example the latest version of DBPro might be reported as 1062"


Well, why not... they're in for the release.

Quote: "- A DBPro compatible multi-line define. When you use the traditional backslash, you don't quite get what you expect."


This is sort of a dilemma.
In C you've got any command ended with a semicolon, so C doesn't need the newlines for separation.
I could implement these backslash-newlines to automatically place colons, but then something like that would be invalid:



which should be valid according to the C89-standard for the preprocessor. That's why I decided in the first place to let DBPre behave like the C-pre-processor.
In your example, one would write:



which is pretty similar to the C version:



I think I might include an additional option for that.
This way everyone gets what he wants.

Quote: "- #constant treated like #define, for compatibility."


I thought about that, the time I wrote DBPre, but decided not to interfere with the DBP-types of constants, because if Lee changes something in the compiler, DBPre-users could be disadvantaged.

God is real, unless declared integer.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 30th Sep 2006 09:30
Quote: "There is something I forgot to mention... when using BlueIDE, you first have to turn off BlueIDEs own preprocessing abilities, because it will complain about the commands used (Tools > IDE Preferences > Advanced, unmark enable preprocessing by editor plugins)."


That makes sense, should have thought of that.


Awe sweet. Wish I had this 8 months ago.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2006 13:35
Quote: "because it doesn't make sence for DBP in my opinion. DBP has no equivalent concept of standard-library or headers"


The reason I asked was because I keep a central repository of source files, and have the choice of copying them to my project folder (where they won't get updated unless I do it), or specifying full pathnames in the IDE.


Oh, and you are right about #constant - it already operates differently to #define and its behaviour has already changed a couple of times in the past. It just sounded like a good idea late last night.

Supremacy
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location:
Posted: 1st Oct 2006 12:14
in computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The amount and kind of processing done depends on the nature of the preprocessor; some preprocessors are only capable of performing relatively simple textual substitutions and macro expansions, while others have the power of fully-fledged programming languages.

A common example from computer programming is the processing performed on source code before the next step of compilation. In some languages (eg, C) the language actually includes a phase of translation that is known as a preprocessor.

gotta love wikipedia

Your signature has been erased by a mod because it's larger than 600x120....
Ekko
19
Years of Service
User Offline
Joined: 27th Apr 2004
Location:
Posted: 2nd Oct 2006 11:15
@D Man
IanM is right; I too would love to have a some standard library directory. I have some standard functions that I use for almost all my projects and I constantly add to or modify them. Just because it's not a feature of DBPro, doesn't mean it's not a useful feature we would like to have
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Oct 2006 20:48
I had an error which crashed the editor - it was simply that I didn't close a double-quote in a line.

I also have another problem that causes the same problem, but I haven't narrowed it down yet - I think it's something to do with backslashes in literal strings.

If I stop any more, I'll let you know.

D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 2nd Oct 2006 21:42
Quote: "IanM is right; I too would love to have a some standard library directory."


Ok, sounds quite useful to me.

Quote: "I had an error which crashed the editor - it was simply that I didn't close a double-quote in a line."


I could reproduce that (i.e. it's fixed for the final).

Quote: "I think it's something to do with backslashes in literal strings."


I should've mentioned that... every time you use backslashes in literal strings, you should better use two instead (\\).
Imagine a path "C:\new folder\".
There will be 2 errors here... the "\n" will be interpreted as newline and the "\"" as quote.
Better use "C:\\new folder\\" instead (like you would in C).

God is real, unless declared integer.

Login to post a reply

Server time is: 2024-04-18 14:51:45
Your offset time is: 2024-04-18 14:51:45