Earlier quoted context omitted.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.
The reason for LISP or SCHEME as the tutorial is that parsing is easy and doesn't call for Flex/Bison. There is a level of semantics also that if you don't strain yourself on edge cases you can do a decent interpreter or compiler pretty quickly. Without making this post long I could "tempt" or encourage you by suggesting that if you take the outermost paren pair off an s-expression, you sortof have a language of func…
Writing Your Own Programming Language
71–80 of 95 posts
Re: Writing Your Own Programming Language
#72Re: Writing Your Own Programming Language
#73Earlier quoted context omitted.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.
At a high level, compilers just translate one programming language to another. A key part of this translation is the Abstract Syntax Tree (AST), which represents the programming language transformed into a tree of computation independent of the syntax of the language. Once you have the AST, you can then step through it and translate the tree to anther language like java bytecode, ASM, CIL, etc. When compiling the AST…
Given the current state of machine learning, could an AST be generated to accommodate a given language?
And more importantly, can the form of an AST cause a difference in performance of the overall program?
Re: Writing Your Own Programming Language
#74Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.
Recent GCC commit:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=28251d450e034f...
GCC has some Lisp-like data structures inside, and those give a language to the commit comment also, making it easy to comprehend what is going on with the abstract syntax.
Re: Writing Your Own Programming Language
#75I have a friend who wrote this book: http://createyourproglang.com/ Jeremy Ashkenas created CoffeeScript after reading that book. I can't recommend it enough for someone going down this road.
Re: Writing Your Own Programming Language
#76Earlier quoted context omitted.
I've built interpreters for both a subset of Java and a full Lisp. Here's my take. > Is there something inherently easier to implementing a functional language instead of something more imperative? Other answers have focused on the parsing of the language (that is, the production of an AST) which is much easier to cover instructionally for a Lisp because it's basically the AST already. To my mind the semantics' of im…
In particular when defining and/or implementing the semantics for an imperative language, eventually store (memory) management comes up and everything gets much more complicated instantly. Why? Isn't C-like "call malloc" simpler than the GC which is required for most (all?) functional languages?
Re: Writing Your Own Programming Language
#77There are a TON of resources like this which focus on lexing and parsing which is all fine and dandy but interpreting the resulting Abstract Syntax Tree will be extremely slow. Are there any resources on the code generation side of things? Even getting from a high level language down to SSA seems like a big leap (nevermind going from SSA to assembly).
Cooper and Torczon's "Engineering a Compiler" is mostly focused on the back end. I liked it a lot.
Re: Writing Your Own Programming Language
#78Earlier quoted context omitted.
At a high level, compilers just translate one programming language to another. A key part of this translation is the Abstract Syntax Tree (AST), which represents the programming language transformed into a tree of computation independent of the syntax of the language. Once you have the AST, you can then step through it and translate the tree to anther language like java bytecode, ASM, CIL, etc. When compiling the AST…
Surely a left-field type of question but here goes. Given the current state of machine learning, could an AST be generated to accommodate a given language? And more importantly, can the form of an AST cause a difference in performance of the overall program?
No machine learning required. It is certainly possible to automatically generate an AST based on a grammar.
The more interesting question is whether you can automatically generate a grammar based on samples of the language - https://en.wikipedia.org/wiki/Grammar_induction - although it is unclear why you'd bother trying for a programming language (as opposed to natural language).
> And more importantly, can the form of an AST cause a difference in performance of the overall program?
If you are compiling to machine code, or to bytecode for some VM, or transpiling to another source language (e.g. JavaScript): not really. The form of an AST could make a difference to compilation speed or the ease of implementing later stages of the compiler, but I can't see how it would directly make any difference to the performance of the compiled program.
However, if you are doing tree-based interpretation: Yes, differences in choice of AST can make a significant difference to runtime performance.
Re: Writing Your Own Programming Language
#79Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.
Just swap [] with (), then they're a lot easier to hit. It's weird that parentheses are shifted but square brackets are not: the former are a lot more common in English text than the latter, as well as in many programming languages.
Re: Writing Your Own Programming Language
#80Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.
When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.