LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   writing a few lines of comments that work in most languages (https://www.linuxquestions.org/questions/programming-9/writing-a-few-lines-of-comments-that-work-in-most-languages-4175723599/)

Skaperen 03-30-2023 05:36 PM

writing a few lines of comments that work in most languages
 
i want to write some reasonably arbitrary text as comments to be prepended and/or appended to source code for most languages or all major languages used in BSD or Linux the code that will write this commented text will not know which language it is, or get to even see the code that the comments will be attached to for to guess the language. the comments will not be inserted in the middle of the code so multi-line code (such as multi line triple quotes in python) will not be affected.

the language i will be coding this in needs to not matter. i will prototype it in one language and finalize it in another. others may translate it to the language they use, maybe FOSS, maybe not.

astrogeek 03-30-2023 06:04 PM

Quote:

Originally Posted by Skaperen (Post 6421294)
i want to write some reasonably arbitrary text as comments to be prepended and/or appended to source code for most languages or all major languages used in BSD or Linux the code that will write this commented text will not know which language it is, or get to even see the code that the comments will be attached to for to guess the language. the comments will not be inserted in the middle of the code so multi-line code (such as multi line triple quotes in python) will not be affected.

the language i will be coding this in needs to not matter. i will prototype it in one language and finalize it in another. others may translate it to the language they use, maybe FOSS, maybe not.

[humor-sarcasm]
Could you be a little more vague please?
[/humor-sarcasm]

Asking for a near universal generated markup syntax, originating from an application defined by language independent source is a bit of a stretch for my tired old brain cell.

Even a UML transform direct from model to source will require knowledge of the target language. You seem to be asking for a single comment syntax which will be recognized by any arbitrary language compiler or interpreter... and I cannot easily parse what you mean by a generating application which is itself language independent (i.e. a universal executable model).

A clear description of your ultimate use case would probably help others, certainly myself to understand what you are asking.

dugan 03-30-2023 06:41 PM

As is the case with many of your questions, the answer is that there is no such thing.

pan64 03-30-2023 11:39 PM

would be nice to show an example, but maybe not

NevemTeve 03-30-2023 11:53 PM

Maybe you could use emojis, they are language-independent.:twocents:

Michael Uplawski 03-31-2023 07:16 AM

Quote:

Originally Posted by NevemTeve (Post 6421338)
Maybe you could use emojis, they are language-independent.:twocents:

... Darn... ascii art. Wait, I have to check out a few things ...

Skaperen 03-31-2023 07:48 PM

Quote:

Originally Posted by dugan (Post 6421302)
As is the case with many of your questions, the answer is that there is no such thing.

i was afraid of that.

i remember my college days when a friend wrote a mainframe program that took in source code, detected the language, and invoked the compiler for that language feeding it the whole original file. i then created a file that could be fed to either the Fortran compiler or the PL/1 compiler with each producing different binaries that did the same thing (copied input to output). i ran it both ways and showed him the results (printed job output back in those days) and asked him which language his program would choose. he tried his program on my source code. his program hung in a loop.

of course that was a limited scope of just two specific languages. i later tried to do the same thing with COBOL but was unsuccessful.

pan64 04-01-2023 02:04 AM

still not understand what are you looking for. Usually we have flowcharts, which means we have some kind of input data and would like to process it and finally produce some kind of output. The flowchart will explain the process itself, step by step, but it is not executable. It should be translated to something which can really do the job. That's why we have programming languages. But you can almost never translate a real source code from one language to another, there is no such tool. And because of the complexity (and incompatibility) of the existing languages it will never exist.
(even moving from python2 to python3 or perl5 to perl6 are not that trivial and works only in one direction)

So what are you really looking for? a general pseudo-language, which can be used to generate real source code on different languages? No, that does not exist and never will.
More than 25 years ago there was a c++ -> c cross compiler (translator?) (because that time we did not have real c++ environment), but the result was terrible.

Michael Uplawski 04-01-2023 05:33 AM

Quote:

Originally Posted by pan64 (Post 6421537)
More than 25 years ago there was a c++ -> c cross compiler (translator?) (because that time we did not have real c++ environment), but the result was terrible.

Was not the very first C++ environment dependent of a meta-compiler that created C-code from C++ ? I really mean Bjarne-C++.

On-Topic: one of my (2) ingenuous bosses developed a generic code generator, based on XML and some pipeline-architecture, similar to a big XML-munging Java-framework the name of which I cannot remember right now (began with a 'C' *) ). The first version and the only one I was involved with, spit out C++ code for GUI-elements that were drawn in a vector-graphics editor with the capacity to parameterize “actions”. You draw, you push button, you include, compile and link => Your military submarine-simulator. Enjoy.

When the customers had become too fearsome, it all came to a halt, but in the meantime, the thing has evolved into a payed online-application. In a version I saw, it could produce Java as well.

This is not something very revolutionary, the guy had simply been too early with the idea (to “never having to program anything at all”).

Code-comments were – of course – coming with the XML-code, as well.

Edit: *) Cocoon !
The similarities were though accidental.

dugan 04-01-2023 11:25 AM

So your boss built an in-house CASE application? Impressive.

Michael Uplawski 04-01-2023 11:31 AM

Quote:

Originally Posted by dugan (Post 6421647)
So your boss built an in-house CASE application? Impressive.

Maybe, but the demands were fewer: make projects quickly and let customers do their adaptations and fixes themselves, while we advance towards other things, as coding takes too long.

Skaperen 04-03-2023 01:48 PM

Quote:

Originally Posted by astrogeek (Post 6421297)
[humor-sarcasm]
Could you be a little more vague please?
[/humor-sarcasm]

if you have something with only one language class, then maybe you can list some of the languages it can handle and some that it cannot. you seem to expect only things that are limited, such as supporting only one language. i've see things that can go beyond that. may you see as being vague things that can deal with a great many situations. would a development requirement that let the developer choose certain things to be supported be vague enough?

Skaperen 04-03-2023 01:50 PM

Quote:

Originally Posted by dugan (Post 6421302)
As is the case with many of your questions, the answer is that there is no such thing.

ah! you have figured out why i ask them.

Skaperen 04-03-2023 01:53 PM

Quote:

Originally Posted by NevemTeve (Post 6421338)
Maybe you could use emojis, they are language-independent.:twocents:

good idea! i'll look for that feature if any exist.

sundialsvcs 04-03-2023 06:13 PM

I recommend that you implement some kind of template-driven system. First detect the language, then invoke the appropriate template for that language.


All times are GMT -5. The time now is 06:28 AM.