Pike is an interesting programming language with syntax like C but interpreted.
Is it possible to use external C libraries in Pike?
For example Apophenia: http://apophenia.info/
I could not find this in its documentation.
Thanks for your help.
Yes, it's possible and it's stated in the doc you've linked. This is covered by Writting modules in C - the CMOD step by step link.
Unfortunatelly it's not that straight-forward. You need to translate C library API into form that is understandable from Pike side. For example there are no pointers in Pike and there are no mappings or strings in C. So you need to write a CMOD that will expose the API into Pike and will do the translation. There is a number of CMODs in the Pike's source code, which you can use as an example and reference.
Related
While writing a Haskell binding for some libs written in C, a thing has to do is writing docs in haddock format. But since normally the binding is just plain, the doc would be just reformat of original libs' doc.
So my question is, is there some tools to help with this? Thanks.
I don't know of any tool for that. Since C docs can take many forms, I don't think there is any tool.
If the binding is indeed plain, essentially everything in IO, same names as the C library, etc. there is a very lazy option: provide a link to the C docs and refer to that.
Better: if the C docs are online, and each function/variable/entity has its own link, provide a link for each entity. In such way, the Haskell programmer can find your docs in Hackage, as usual, and then it's just one more click away to the real docs.
Of course, ideally one should copy the C docs, so that it's immediately available. However, this can require a lot of work, and some care in handling copyright correctly.
I have a question that was bugging me for a while, sorry if it is rookie question:
Is there a way to develop an application with more than one programming language?
Today i was looking for a Video Player in Linux and i saw this:
MPV Player: Written in C, Objective-C, Lua and Python, MPV is...
Can anyone explain how they write an application in multiple language?
Thanks for helping...
You just need the ability to call a function written in one language (and implementation) from a function written in another one (and its implementation).
The lua scripting language (and interpreter) was designed to be easily embeddable in C applications. Read the chapter The Application Program Interface of Lua manual (Lua uses some stack for arguments and results). And Guile is also designed to be easily embeddable, and has a nice tutorial explaining that (you give the arity of your foreign functions to the Guile runtime).
Sometimes, you need to follow specific conventions (which depends upon the implementation) to call a foreign function. For examples, Python has a chapter on Extending and Embedding The Python Interpreter; C++ code need to annotate with extern "C" the declaration of functions coded in C (or callable from C), Ocaml's manual has a chapter about Interfacing C with Ocaml, etc.
More generally, be aware of calling conventions and of ABIs. Sometimes, you might want to use libffi which enables you to call functions of signature known only at runtime.
BTW, MPV is open-source, so why don't you study its source code?
This article would gives you answer of your question :
https://www.computerworld.com/article/2467812/internet/polyglot-programming----development-in-multiple-languages.html
I'm just asking this out of curiosity :
Is there any tool that can automatically convert a source code of reasonable complexity from one language to another ?
Is there any "meta-language" that can compile into several other languages ? For example CoffeeScript compiles into Javascript.
If you know any open-source example, it'd be great !
Thank you for your time.
PS: No idea how to tag this. Feel free to edit.
GCC converts complex C++ code into machine code and thus technically is an answer to your question. In fact, there are lots of compiler like this, but I don't think these are what you intended to ask.
There are tools that are hardwired to translate just one language to another as source code (another poster suggested "f2C", which is a perfect example). These are just like compilers... but rarer.
There are virtually no tools that will map from one language to many others, out of the box. The problem is that languages have different execution models, data types, and execution schemes, which such a translator has to simulate properly in the target language.
The are "code generators" that claim to do this, but they are largely IMHO specifications of rather simple functions that translate trivially to simple code in the target langauge.
If you want to translate one language to another in a sort of general way, you need a program transformation system, e.g., a system that can parse arbitrary langauges, and for which you can provide translation rules that map to other languages in a sort of straightforward way.
Our DMS Software Reengineering Toolkit is one of these. This SO What kinds of patterns could I enforce on the code to make it easier to translate to another programming language? discusses the issues in more detail.
You can convert Fortran code to C using the f2c tool.
For python, you can convert a subset of the language to C++ using shedskin.
The vala language is converted to C before the real compilation.
I am trying to understand how a language interpreter works. Can you guys point me the general lines on how an interpreter works?
I mean, suppose I have some lines written like this
10 x = 200;
20 for r = x to 1000 step 1
25 z = r + 32;
30 print z;
40 next r;
50 end;
what's the best way to build an interpreter that could run something like that?
Having a large matrix containing all functions allowed and searching for a match? The first line, for example: it is assigning 200 to a variable x, but these are symbols that does not exist.
If you guys can give me the direction...
Thanks for any help.
Compiler creation is a complex topic (an interpreter can be seen as a special compiler).
You have to first parse it - try to understand the syntax and then create some internal representation (abstract syntax tree) and then create some execution logic.
Wikpedia suggests http://mcs.une.edu.au/~comp319/
I know this is an old thread but most of the related questions are marked as duplicate or closed. So, here are my two cents.
I am surprised no one has mentioned xtext yet. It is available as Eclipse plugin and IntelliJ plugin. It provides not just the parser like ANTLR but the whole pipeline (including parser, linker, typechecker, compiler) needed for a DSL. You can check it's source code on Github for understanding how, an interpreter/compiler works.
Perhaps you are talking about creating a DSL.
You might find this helpful (if you are ok with spending $$)
http://gilesbowkett.blogspot.com/2010/03/create-your-own-programming-language.html
I'm interested in learning more about this as well. I found Douglas Crockford's JavaScript parser interesting, though from what I understand he's using a different method than is typical for parsing languages. It's not the full picture for interpreting and compiling, but I found it helpful to see some actual parsing implementation and the resulting restructuring of the code.
you can find an open source 'Gold Parsing System' at http://goldparser.org. :)
there are some explained concepts on their site too where you can learn some rudimentary basics of the process.
Learn about tools such as lex/flex and yacc/bison. These are most popular tools for building compilers in open software world. Many well known open source programs are written using them (including PHP, gcc, doxygen). You'll find a lot of free books and tutorials. They not only show how to use lex and yacc tools, but also explain general ideas behind compilers.
When working on hobby projects I really like to program in low-level languages (in the sense that C and C++ are low level). I don't want to work with managed languages with garbage collection and whatnot that takes all the fun away (yeah, we're all different ;-) ).
Normally I use C++ for these type of projects. C++ is rather complex and not so elegant so I have been looking for a language to replace it. Anybody can give me suggestions?
Preferences (not requirements):
should be low-level (like C and C++)
compile to native code (kind of follows from the above but no harm in being explicit)
preferrably target win32/win64
object oriented
statically typed
I have looked at Objective C but I don't like it.
D? (Wikipedia page)
The D language is statically typed and
compiles directly to machine code.
It's multiparadigm, supporting many
programming styles: imperative, object
oriented, and metaprogramming. It's a
member of the C syntax family, and its
appearance is very similar to that of
C++. For a quick comparison of the
features, see this comparison of D
with C, C++, C# and Java.
I think that covers everything in your requirements except Windows support, which it has too.
Note that it has garbage collection, but your question seems to associate garbage collection with being managed - they're not the same thing. I believe garbage collection can be pretty tightly controlled in D.
I should note that I have absolutely no experience in the language whatsoever :)
Ada - http://en.wikipedia.org/wiki/Ada_programming_language
Oberon - http://en.wikipedia.org/wiki/Oberon_(programming_language)
Modula 3 - http://en.wikipedia.org/wiki/Modula-3
Delphi? Pascal syntax, but still quote powerful and just a little more high-level than C++.
Requesting no gc is rather strong and eliminate almost every modern language - things like Ocaml, for example, fill all the other requirements.
There is also ADA which fill every of your desire, but that's a very strict language. The syntax is somewhat similar to Pascal I think, and the language has much less holes compared to C. It has built-in support for threads and 'modules' (better than C headers).
FreePascal
Delphi
Oberon
Any 3 would be great replacements. They're easier to use than C++ too.
Ada is a really good language, however, it uses garbage collections (noticed that mamboking mentioned it.) Not sure about Oberon and Modula 3.
Pascal/Delphi is also using garbage collection as far as I know. (or at least smart pointers of some kind.)
I suggest Limbo!
It's a language created by Rob Pike (co-author with Kerninghan of many programming books). This language is interpreted by the DIS virtual (memory-to-memory) machine or compiled.
It has many data types built in like tuple, pipe, list, array, channel (useful to EASILY comunicate between thread), etc. it's concurrent, modular.
It implements many modern features! and it's used to write application for the Inferno OS.
Limbo review by Dennis Ritchie and
Limbo review by Kernighan
I would suggest Vala! try it is is amazing