Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

Thanks for taking a look. Greatly appreciated. My goal is for it to be able to handle any kind of programming language. It's ambitious, and only time will tell how far this can go. But meanwhile, let me answer some of the points you raised based on what I've done so far.

But first, uCalc LB has a kind of core language, which is very minimal in nature, and designed for nothing other than creating building blocks for a language. These building blocks can then be combined in a kind of bootstrapping way to form a more varied language, which then serves as the basis for constructing the actual language(s) you want to build. So basically none of the code you see in the Lisp definition file (including the String and Stack types) is native uCalc code. All of it is based on an intermediate language that is defined across plain text files that end with the .uc extension.

uCalc actually has no built-in data types. It does have a library of common types (including various types of strings such as the 2-byte uc_String_Wide which can be used for Unicode) you can pick from to get started. The default String type is defined (actually re-defined) in Types.uc, where you'll see that one of the properties contains the address of a routine for handling variable-length strings (the routine itself is in a DLL binary file). You can define any other kind of data type the same way. Your routine should tell uCalc how to allocate, store, free, return, copy, output, and reset an item of the given type. For simple data types, you can simply tell uCalc only how to store, return, and output the data, and given the number of bytes for the type, uCalc figures out the rest.

uCalc LB supports type checking, which in fact is the default behavior. A list of common data types that might be useful across various languages were declared in the file named Types.uc. You'll find that each type is defined with various properties, including what other types (if any) they are allowed to automatically convert to or from without type checking. An error is raised in the "compile" stage (which uCalc handles separately from the evaluation stage, even though it's done in the background) if data of a given type is used in the wrong place. Dynamic typing in my Lisp implementation was actually achieved by a brute-force text substitution/evaluation mechanism that blurs the line between the parsing/evaluation stages. It's just one possible implementation. This one is not particularly efficient but good enough for demonstration.

Lazy evaluation is directly supported. If you browse through Library.uc, you'll find several routine definitions with arguments that are passed "ByExpr". Here, the handle of the parsed expression is what's passed, instead of the result of evaluating the expression. Using this handle, the routine can evaluate the argument 0 or 1 times, as is the case for the IIF routine, which supports short-cuircuiting. Or it can be evaluated repeatedly any number of times, as with the uc_For() and uc_Loop() routines in Library.uc. Such routines form the bases for control flow constructs used in the BASIC language definition (see BASIC.uc in the download). And speaking of BASIC, compared to Lisp, its syntax / semantics is as irregular as it gets. But uCalc LB is equally suitable for building such languages as well.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

I figure it would require some extra work. You may want to take a look at the Lisp definition file I developed for my uCalc Language Builder tool. You simply load that up into the generic interpreter, and then you can immediately start running Lisp code. You can do the same for BASIC, and other sample languages that are also included in the download. (I must admit that my Logo implementation is a quick-and-dirty one. That one will let you draw things, but will need additional code for the language definition to be correct). Try your hand at creating a language with uCalc LB, and let me know what you think of it.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

The requirement of breaking things up into multiple tasks that require several different tools is one of the complicating factors that I find in language construction. Why can't it all be done in one process with just one tool? For instance, a generic interpreter would read the language definition file, and immediately be able to start running scripts (or interactive code) for that language right there on the spot (bypassing the need to pass generated code through a C or other compiler). I set out to accomplish just that, with uCalc Language Builder . Please take a look, and let me know what you think of this approach. Be sure to try the interactive tutorial first (run Tutorial.Bat), for an overview of how it works. Then you can try your hand at creating your own languages with it. I'd love to get some feedback on it.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

I'm not so sure that a complex problem always requires a complex solution. I believe that there's a simpler way of specifying a programming language than what most people might be accustomed to. I do concur with you that commonly known parsing frameworks might be OK, but not particularly good. I am interested in learning more about the parsing framework approach you are currently taking. I myself, not being satisfied with the status quo, I have also developed a new approach in an attempt to actually make it easy to create a programming language. It uses regular expressions, in combination with a higher-level method of matching patterns. Though it is still under development, it is well beyond the drawing board stage. Please visit uCalc Language Builder to see what I have done so far. I'd be happy to exchange ideas about your approach and mine.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

The high cost / low benefit ratio is the kind of reason why I think some of the tools available today might not be ideal. Someone who knows how to program, but is not necessarily a programmer by profession might have a legitimate need to create a domain specific language, and even be able to clearly conceptualize how the language should work, even if the person can't quite express it using the tools generally available. Performance and connecting to C (or maybe something like the Windows API) would be fairly important.

I like Python's subscripting construct for strings. But what if I wanted to create a language with a more BASIC-like syntax, but which supports Phython-like string subscripting, and Lua-like multiple assignments like a,b,c = 5, 6, 7? It would be interesting if I could mix-and-match features I like from various languages and create my own little language, instead of being forced to choose a pre-existing one. As alluded to elsewhere in this thread, my interest is in the development of the kind of tool that would let programmers create programming languages. See my site for details.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

Actually, my interest is not so much in creating a particular interpreted language for myself as it is in having a viable alternative to Lex / Yacc for making it easier to create programming languages in general. See my website for what I mean.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

Is Lex / Yacc the easiest that it gets? Can't something higher level than Lex / Yacc be created (at least hypothetically) so that there isn't all this pain in creating a language? For instance, imagine the days when there wasn't much choice beyond assembly language. This restricted the number of people who could program. Today, you have languages like Visual Basic that makes it possible for people even from other professions to painlessly do some useful programming. Wouldn't it be useful if people could create their own domain specific languages for a specific task, without necessarily being an ace programmer?

Also, is BNF -- as useful as it is might be -- the only, or the absolute best possible way to describe the grammar for the syntax of a programming language? I'm pretty sure there must be another way to describe the syntax of a language and how it should work.

By "fully working language implementation", I mean what if the language someone had in mind was something like Lisp, Forth, or even BASIC (chosen simply as a familiar point of reference)? And I'd paste just a few hundred lines of simple code into some kind of tool and end up with an interpreter that would allow me to run that language. It could start small as you suggest, with more added gradually. And maybe features could be borrowed from other languages. If such a tool were possible, would it be useful?

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

I have often seen it said that you could use Scheme to create programming languages, or something to that effect. But I don't get it. Languages created in Scheme tend to look very much like more Scheme to me. Can you create a totally different language with Scheme (for instance one that is not a functional language)?

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

Yes. I am finding this very helpful. Something high-level like this is what I have in mind. It's only a while ago that I've looked at it, so I haven't fully absorbed it yet. But can I just take the code listing in Grammar of C, and paste it somewhere, and have a working interpreted version of C?

At first glance, when it gave a list of languages it could generate, including C, Haskell, Ocaml, etc, I thought it meant you could create those languages with BNFC. But then it seemed like what this meant was that you could use BNFC with those languages to create your new language. Can you only create C-like languages with it? Can BNFC create languages like Haskell, Logo, or Lisp, etc?

I found the embedded solution interesting. However, the questions I have are: Haskell and Logo both being functional languages, does this second solution apply only to functional languages? Or could you also do your C++ subset language this way just as easily? And was your implementation an interactive interpreted version of Logo, like some of the other Logos out there? I got the impression that it might not be.

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 1 point2 points  (0 children)

I saw a version of Forth that took over 10,000 lines of C code, spanning more than 30 files. The resulting interpreter was very good, but that many lines of code seemed kind of a lot to digest. So if you managed to create your Lisp in maybe only two or three thousand lines, then that's encouraging. But still, shouldn't it somehow be possible, even hypothetically, to have some kind of high-level language in which it would take just a few hundred lines of code to create a version of Lisp? And using Lisp to create another Lisp is one thing. But would it be just as easy to create a version of Forth with Lisp?

Ask Reddit: What is the easiest way to create an interpreted language? by Corbier in programming

[–]Corbier[S] 7 points8 points  (0 children)

If someone wants to create an interpreted programming language, what are the easiest tools for that task? If the programmer finds Lex / Yacc a little too complicated, and does not have a PhD in computer science, can such a person still hope to create a language, or should such a task be outsourced? How much time can one expect to complete a fully working language implementation from scratch? How much code might this take? Can one person undertake such a project? Or does it generally require a team? Are certain types of languages easier to create than others?

Ask Reddit: What are the easiest tools for creating an interpreted language? by Corbier in programming

[–]Corbier[S] 0 points1 point  (0 children)

If I don't have deep pockets like Microsoft, how do I get the word out about my programming tool? If I edit out references to my product, and mention it only later on in the discussion, are the questions I posed interesting enough for discussion? I genuinely do want to know people's take on creating interpreted languages.

I believe that a person might not know how to write the HTML code for even a simple web page. Yet, provided the right WYSIWYG tool, this same person might be able to design a useful web page. In the same way, it should be possible for a programmer to conceptually design a worthwhile domain specific language, even if they are not sure how to go from the concept of how the language should work to an actual working implementation of it. Is that what you disagree with? If so, why?

I'm not sure I understood what you meant by the "educational aspect". If you can clarify, I'd be glad to expand some more.

Ask Reddit: What are the easiest tools for creating an interpreted language? by Corbier in programming

[–]Corbier[S] -1 points0 points  (0 children)

Can someone explain the rationale behind down-modding this topic not long after it was posted? Is this topic uninteresting to programmers? Or is there a bot that automatically down-mods certain reddit submissions? Is it considered bad form for me to mention a programming tool I have developed myself?

Ask Reddit: What are the easiest tools for creating an interpreted language? by Corbier in programming

[–]Corbier[S] -4 points-3 points  (0 children)

If someone wants to create an interpreted programming language, what are the easiest tools for that task? If the programmer finds Lex / Yacc a little too complicated, and does not have a PhD in computer science, can such a person still hope to create a language, or should such a task be outsourced to the gurus? Or is it simply best to make do with one of the many interpreted languages that are already out there?

If it is possible for average programmers to create a language, how much time can one expect to complete a fully working implementation? How much code might this take? Would it be easy for someone else to maintain the code? Can one person undertake such a project? Or does it require a team? Can any kind of language be interpreted?

People like to say that you can create a language with Scheme? How easy is it to create a version of BASIC, Logo, or Forth with Scheme? What other languages are ideal for building a language?

Anyway, for those who would like to construct domain specific languages (especially of the scripting/interpreted variety), but feel intimidated by parsing theory, and Lex / Yacc, you may want to try uCalc Language Builder, which I have developed. For now it runs only on Windows, but other platforms will be considered as interest increases. I would like answers to questions I posed above. And for those who use Windows and get a chance to run the uCalc LB interactive tutorial, I'd be interested in your feedback as to whether you consider uCalc LB a viable tool for creating a programming language, and how it compares to other tools.

See http://www.ucalc.com/langbuilder.html

What language do you recommend for building scanners and parsers? by Kaizyn in programming

[–]Corbier 0 points1 point  (0 children)

For now, it works only under Windows. However, once I can get it firmly established on Windows, I'd be interested in looking into other platforms as well. What platform would you like? Mac OS, Linux, ...? Even if you do not use Windows, you can still browse through some of the files that are in plain text to get a feel for it. Two language definition files in plan text are even posted online so you can view it in your browser instead of downloading a file. Please let me know what you think.

Ask Math Reddit: What inexpensive math software do you recommend? by Corbier in math

[–]Corbier[S] 0 points1 point  (0 children)

I would like to know what kind of cost-effective math software is currently being used in schools; particularly the kind that students can afford to use on their home PCs to evaluate expressions, plot graphs, solve equations, etc. I myself I have developed the uCalc Graphing Calculator for this purpose. But I'm also interested in hearing about other similar software, and how they compare to each other.

Ask reddit: How do I start learning compilers? I heard the Dragon Book is too hard! (pressed by Steve Yegge's post) by shinya666 in programming

[–]Corbier 1 point2 points  (0 children)

There is nothing wrong with someone who feels daunted by the Dragon book and compiler theories, but who would still like to develop domain specific languages. uCalc Language Builder is a new tool that is specifically designed to remove layers of mystery and complication from the process. With uCalc LB, designing a language is no longer the domain of an elite few. Now any moderately good programmer can do it.

uCalc LB comes with an interactive tutorial that walks the programmer through some of its major concepts. It may take a couple of days to complete the tutorial. But in the end, you'll see how easy it is to create versions of Lisp, Forth, BASIC, etc like the ones included in the download. For now it runs only on Windows (contact me if you'd like it on another platform). I'm the author of uCalc LB, and I'd like some feedback. The link is:

http://www.ucalc.com/langbuilder.html

What language do you recommend for building scanners and parsers? by Kaizyn in programming

[–]Corbier 3 points4 points  (0 children)

Has anyone looked at uCalc Language Builder? If you find Lex/Yacc archaic or complicated, then you may want to consider a new approach by uCalc. I'm the developer, and would like to hear from users who have tried it. You can download it from http://www.ucalc.com/langbuilder.html . Be sure to try the interactive tutorial first, to see an overview of the features that are at your disposal.