Author Topic: How to add another programming language to C::B? Preparsers?  (Read 487 times)

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 3
How to add another programming language to C::B? Preparsers?
« on: February 14, 2017, 09:13:41 am »
C::B has built-in support for C, C++ and Fortran I wonder what steps are necessary to add another language (despite of the compiler configuration part which is "open").
Can anybody please leave a link on documentation how to do this or some detailed steps?

A related question: How to work with pre-parsers? If I understood the docs correctly a first step is to add an entry for the file extension in Settings->Compiler->Other settings. How to go on if the resulting file is neither .c nor .cpp?

Thank you for the response,
cb_mensch

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1267
Re: How to add another programming language to C::B? Preparsers?
« Reply #1 on: February 14, 2017, 03:25:14 pm »
can you elaborate more, what the new language needs?
For the lexer (code coloring) http://wiki.codeblocks.org/index.php/Creating_a_custom_lexer_for_Code::Blocks_editor
For code completion you need to write a plugin... See the code for the python plugin or for the clang code completion or the native code completion...
For compiler integration (if you need a compilation step, you do not give any information on that...)  http://wiki.codeblocks.org/index.php/Installing_a_supported_compiler#Misc._Custom_Compilers
For creating a template for the scripting wizard: http://wiki.codeblocks.org/index.php/Scripting_Code::Blocks

your question does not provide any information to give you some hard answers... Ask exact questions, get exact answers...

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to add another programming language to C::B? Preparsers?
« Reply #2 on: February 14, 2017, 11:02:55 pm »
Thank you, this is actual enough to start the work :-)

Offline gafling

  • Single posting newcomer
  • *
  • Posts: 1
Re: How to add another programming language to C::B? Preparsers?
« Reply #3 on: February 19, 2017, 02:06:13 pm »
@BlueHazzard

One language that I would like to be able to integrate into C::B is Cobol.  Before you scoff you should know that the newer dialects of Cobol (like GnuCobol) resolve the source code down to 'c'.  Therefore it would be helpful to be able to build projects that combine both languages and can manage the each type of source code.

The GNUCobol would need to be able to edit source code, call a pre-compiler which will translate the Cobol to 'c', and then call the 'c' compiler of choice to finish up.  C::B appears to be able to do all that except for the actual source code editing part.

Your post suggests the places where Cobol support would need to be added.  Actually I would find it surprising that this has not been addressed by someone, but maybe not.  In any case any additional suggestions are welcome.

Thank you for your time.


Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1267
Re: How to add another programming language to C::B? Preparsers?
« Reply #4 on: February 19, 2017, 03:01:33 pm »
Actually I would find it surprising that this has not been addressed by someone, but maybe not
Never heard of any cobol integration in codeblocks.

In any case any additional suggestions are welcome.
Good luck and have fun! I am happy to answer any specific question!

FYI: The editor of codeblocks bases on scite, so if you find a lexer for cobol there you can easily integrate it in cb. It seems that there are some efforts but this post is 15 years old...
http://git.net/ml/editors.scite.general/2003-12/msg00127.html

[EDIT:] It seems that codeblocks has an lexer for cobol!  https://sourceforge.net/p/codeblocks/code/HEAD/tree/trunk/src/sdk/wxscintilla/src/scintilla/lexers/LexCOBOL.cxx

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9415
Re: How to add another programming language to C::B? Preparsers?
« Reply #5 on: February 19, 2017, 08:01:10 pm »
One language that I would like to be able to integrate into C::B is Cobol.
A lexer for C::B seems feasible (Cobol is supported by scintilla). However, the build system is not really suited to integrate the compiler easily. It could work with custom pre-compiler steps or customising compiler commands.

However, for Cobol I would recommend an own plugin from scratch, similar how its done for Fortran. You will certainly work mainly on the Cobol files and not on the underlying C-Code, won't you? So you'll need more support than just the lexer. Its really similar to Fortran that also translates to C (well hidden) using the GNU compiler tool chain.

So if you want to start such effort, have a look at the Fortran plugin. For the custom lexer you can do it probably yourself, if you read this:
http://wiki.codeblocks.org/index.php/Creating_a_custom_lexer_for_Code::Blocks_editor
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline cb_mensch

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to add another programming language to C::B? Preparsers?
« Reply #6 on: February 20, 2017, 10:35:34 am »
As GnuCOBOL knows best how to call the underlying C compiler (depending on the C compiler it was built with/configured for and depending on the given command line options to the GnuCOBOL compiler `cobc`) - I guess this is what is done for Fortran, too - I'd suggest to not use it as a pre-compiler step but as a "real" compiler.

A different thing is that COBOL is often used via pre-parsers (for example `EXEC SQL` and lot of COBOL-shop-specific-self-written-pre-parsers), therefore it would be nice to end with an option for the chain Source -> Pre-Parser-Step X (for example a shop specifc one) -> maybe Pre-Parser-Step Y (for example the SQL preparser `dbpre`, Oracle's `procob` or whatever) -> plain COBOL source -> `cobc` (+ internal: `gcc`, `clang` or `cl.exe`).

And yes, I think a full-integrated approach - which seems to need a plugin, given the comments so far - would be best.