Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am in the process of writing interpreters for a couple of languages, in TeX, which would allow TeX users to insert some code from their favorite language (if supported), and have TeX run it when producing the pdf result.
I started by writing an interpreter for Brainfuck, since it is a very simple language. I thought GolfScript would be a piece of cake, but it is richer than I had expected (mostly because it is based on the rather elaborate Ruby). I'll probably do Whitespace for the sake of it. But none of those is actually used by people, so up to now the whole process is mostly an exercise to see how to best write interpreters in TeX.
My question is: what real-world language should I consider? It should have the following qualities:
simple (I'm not ready for Python),
typically be used as one-liners (if possible),
and have a reasonably large user base.
I'm assuming that every language can have an interpreter (compiling only enhances the speed), please mention if you think of technical hurdles for the proposed language.
EDIT: I am also interested in comments such as "implement Perl 2, then gradually add support for later versions" (no idea if that particular scenario is a good idea, though). I've already coded some support for regular expressions.
How about a stack based language like Forth (or even a subset of PostScript)? Stack operations should translate to TeX constructs relatively easily. Finally, if all of this is done for the sake of an exercise, what about implementing a C preprocessor?
You can use some LISP based language like Beginning Student Language or some ML variant like OCaml. For a simple exercise in interpreting ML-like code, just implementing definitions, function applications, arithmetic and conditional expressions gives you a nice start:
let rec factorial n =
if n = 0 then 1 else n * (factorial (n-1))
let sqr x = x * x
let compose f g x = f (g x)
(compose sqr sqr) (factorial 3)
Also consider Lua which aims at being a good scripting language that can be used to let users customize your applications and is pretty popular.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have 2 year of experience in IT. I haven't seen any recursive code. I would like to know If there is any company or organization Who use recursive code on their Production Environment. It would be great If some also explain the use cases also.
All code which uses variadic templates necessarily uses recursion, see e.g. http://kevinushey.github.io/blog/2016/01/27/introduction-to-c++-variadic-templates/.
The answers to this question give a few recursion examples. The most convincing one is a hand-coded compiler (or rather parser) implementation for a recursively defined language (like C and most others, where blocks can contain blocks, expressions expressions etc.). Perhaps it's only most convincing to me because I did that in a CS course, but still. Even here it is admittedly possible that production compilers are created with tools and are not recursive. If anybody shed light on the inner workings of gcc or one of the other open source compilers, I'd appreciate it.
I would generally assume that some programs handling recursive data structures with a limited recursion depth (like balanced trees, as opposed to normal trees or lists) use recursion, just because it is simple and elegant, and the depth limit removes the greatest obstacle for recursion.
Come to think of it, I have actually used recursion to parse a simple "option language" for an internal custom-made program which has an option -eval <file>, where the referenced file contains more options, possibly including more -evals. The referenced files are indeed simply recursively evaluated.
If the programs are basically CRUD (create, retrieve, update, delete) screens to interface to a database of some kind, you won't see much call for recursion. And that's a lot of of serious, real world programming.
But large numbers of programs have trees. E.g. an artwork tree, or a 3D animated object tree. Once you work with trees, recursion is by far the easiest way to solve problems.
There's also the "functional programming" paradigm which replaces iteration with recursion. It has some theoretical benefits and is used in some environments, though it's still a bit academic and experimental.
For your information I was into a IT company in my earlier days where I use to write loads of recursive code in production Environment. and more over it depends upon the coder if you wish to c I can send some recursive code example
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to know if there is any language that compiles to VBA, like we have coffeescript for js, less for css...
If there is not, is there something that prevents us from achieving that? Would it be a bad idea?
I guess that would help people that are used to work with more modern languages to be a LOT more productive.
What would it take to do that ? Could we reuse the coffeescript grammar and parser, but hack into the steps that generate Javascript and generate VBA instead ? A subset of VBA would be just fine.
In general, it's always possible to compile from one Turing-complete language to any other. The result might not be fast, but it's generally fairly straightforward.
So, why was Coffeescript created ex nihilo, instead of using an existing language? Integration.
Suppose, for example, that we wanted to write JS in Haskell. You could easily implement a Haskell to JavaScript compiler. Now, suppose, writing in Haskell, you wanted to pop up a dialog box on a Web page. In JS, you'd write alert("hello"), but if your H2JS compiler is correct, there won't be any alert function, because Haskell functions don't have side-effects (perhaps the whole reason that you wanted to write in Haskell was so that you could have nice guarantees like that calling functions won't pop up dialog boxes).
There are many ways that your H2JS compiler could provide this functionality, but it's not necessarily obvious which one was chosen. You can't just read JavaScript documentation to learn how to do browser-y things; you also need to read the documentation for your H2JS compiler!
On the other hand, Coffeescript is similar enough to JS that it's pretty obvious how to pop up alerts, edit the DOM, etc., just from knowing how it's done in JS.
So, it's not hard to do in a slapdash way, but, if the source language is much different from VBA, it'll likely be tricky to do the VBA-specific things that make the project useful in the first place.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to understand context-sensitive grammars, and I understand why languages like
{ww | w is a string}
{an bn cn | a,b,c are symbols}
are not context free, but what I'd like to know if a language similar to the untyped lambda calculus is context sensitive. I'd like to see an example of a simple, but non-toy (I consider the above toy examples), example of a context-sensitive grammar that can, for some production rule, e.g., tell whether or not some string of symbols is in scope currently (e.g. when producing the body of a function). Are context sensitive grammars powerful enough to make undefined/undeclared/unbound variables a syntactic (rather than semantic) error?
Yes, context-sensitive grammars (CSG) are powerful enough to make undefined/undeclared/unbound variables check, but unfortunately we don't know any efficient algorithm to parse strings of CSG.
A real example of a context-sensitive language is the C programming language. A feature like declare variables first and then use them later make C-language a context-sensitive language (CSL). (I don't know about untyped lambda calculus).
And because we don't know any linear parsing algorithm for CSL (or CSG). That is the reason in compiler design, we use CFG (and its parsing algoritm only) for syntax checking since we know efficient algorithms to parse CFG (if it's in restricted form). Compilers first parse a context free feature and then later handle context-sensitive features in a problematically way (for example, checks any used variable in the symbol table if it's defined. Otherwise, it generates an error).
Also context-sensitive grammar is used in natural-language processing (NLP). And most natural languages are examples of context-sensitive languages. (I am not sure for the Sanskrit language).
I will try to explain it with a silly but simple example (it's just an idea, you can refine it):
NOUN --> { BlueBomber, Grijesh, I, We}
TENSE --> { am, was, is, were}
VERB --> { going, eating, working}
SENTENCE --> <NOUN> <TENSE> <VERB>
Now, using this grammar, we can generate some correct statements, but some are wrong too. For example,
SENTENCE --> <NOUN> <TENSE> <VERB>
Grijesh is working [Correct statement]
But
Grijesh am working [wrong statement]
Reason: the value of <TENSE> depends on value <NOUN> (for example, I <TENSE> --> I am) and hence the grammar doesn't generate correct statements in the English language.
Actually we can't write a context-free grammar for complete English!
You might have noticed, any natural language translator or grammar checker doesn't works correctly (try with long statements). Because this problem comes under the context-sensitive parsing algorithm.
REFERENCE: You can watch Dr. Arun Kumar's lectures.
In some lecture he explains exactly what you are interested in.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Can any language be used to program in any paradigm? For example C doesn't have classes but s it is possible to program in OOP. There are some languages (such as assembly) I can't see using OOP in.
Yes, simply due to the fact you can implement an interpreter for your $favorite $paradigm in the host language.
Practically though, this is not feasible, efficient or right.
C++ is ultimately assembly, you just have a compiler to write the assembly for you from a nicer description. So sure you can do OOP in assembly, just as you can do OOP in C; it's just that a lot of the OO concepts end up being implemented with convention and programmer discipline rather than being forced by the structure of the language, with the result that huge classes of bugs become possible that your language tools probably won't be very good at helping you find.
Similar arguments follow for most paradigm/language mismatches. Lots of object-oriented programs have been written in C this way, so it can even be a somewhat practical thing to do, not just an academic matter.
It can be a little harder when what you want is to remove restrictions rather than add them.
In purity-enforced languages such as Haskell and Mercury you can't suddenly break out object-oriented style packets-of-encapsulated-mutable-state in the middle of arbitrary pure code (at least not without using "all bets are off" features like unsafePerformIO in Haskell or promise_pure in Mercury to lie to the compiler, at which point your program may well completely fail to work unless you can wrap a pure interface around the regions in which you do this). However you can write whole programs in procedural or object-oriented style in these languages, by never leaving the mechanism they use to do IO.
Likewise, if you consider the use of duck typing in dynamic languages to be a paradigm, it's pretty painful to get something similar in languages with static typing, but you can always find a way to represent your dynamic types as data. But you again find yourself doing thing with convention and reimplementation that you would get for free if you were really using a duck typing language.
I'm pretty sure it would be hard to find a language (usable for writing general purpose programs) that can't be adapted to write code in any paradigm you like. The adaptation may not produce very efficient code (sometimes it can though; adapting C or assembly to any paradigm can usually be made pretty much as efficient as if you had a language tuned for that paradigm), and it will almost certainly be horribly inefficient in terms of programmer time.
No, not all languages can be used to program in any paradigm. However, the more popular ones - python, c++, etc all allows you to chose how you want to program. Even php is adding OO support.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I just wanted to know if you know of some projects that can help to decide whether the analyzed Source it is good code or bad RPG code.
I'm thinking on the terms of Software metric, McCabe Cyclomatic Number and all those things.
I know that those numbers are mere a hunch or two, but if you can present your management a point score they are happy and i get to modernize all those programs that otherwise work as specified but are painful to maintain.
so yeah .. know any code analyzers for (ILE)RPG ?
We have developed a tool called SourceMeter that can analyze source code conforming to RPG III and RPG IV versions (including free-form as well). It provides you the McCabe Cyclomatic Number and many other source code metrics that you can use to rate your RPG code.
If the issue is that the programs are painful to maintain, then the metric should reflect how how much pain is involved with maintaining them, such as "time to implement new feature X" vs "estimated time if codebase wasn't a steaming POS".
However, those are subjective (and always will be). IMO you're probably better off refactoring mercilessly to remove pain points from your development. You may want to look at the techniques of strangler applications to bring in a more modern platform to deliver new features without resorting to a Big Bang rewrite.
The SD Source Code Search Engine (SCSE) is a tool for rapidly search very large set of source code, using the langauge structure of each file to index the file according to code elements (identifiers, operators, constants, string literals, comments). The SD Source code engine is usable with a wide variety of langauges such as C, C++, C#, Java ... and there's a draft version of RPG.
To the OP's original question, the SCSE engine happens to compute various metrics over files as it indexes them, including SLOC, Comments, blank lines, and Halstead and Cyclomatic Complexity measures. The metrics are made available as byprooduct of the indexing step. Thus, various metrics for RPG could be obtained.
I've never seen one, although I wrote a primitive analyser for RPG400. With the advent of free form and subprocedures, it was too time consuming to modify. I wish there was an API that let me have access to the compiler lexical tables.
If you wanted to try it yourself, consider the notion of reading the bottom of the compiler listing and using the line numbers to at least get an idea of how long a variable lives. For instance, a global variable is 'worse' than a local variable. That can only be a guess because of GOTO and EXSR.
Lot of work.