alshdavid / BorrowScript

TypeScript with a Borrow Checker. Multi-threaded, Tiny binaries. No GC. Easy to write.
1.45k stars 16 forks source link

Keep the gramma of the language context free #37

Closed Isaac-Leonard closed 1 year ago

Isaac-Leonard commented 3 years ago

I believe its probably best to attempt to keep the syntax / Gramma of the language context free to make building parses easier and to limit ambiguity in the syntax. C++ for example is not context free and is a mess to the point where its syntax is now Turing complete from what I've heard. Avoiding this is best I think.

alshdavid commented 2 years ago

Can you give some examples please?

mindplay-dk commented 2 years ago

I'm no expert, but I think context-free grammar basically means every parser rule is a simple replacement - so, determining whether the syntax is valid does not depend on any contextual information deduced by the compiler while parsing.

Importantly, it implies the syntax can be described in Backus-Naur form, which most languages can - having an official, properly versioned BNF (perhaps as part of a reference parser implementation with good test coverage) is an important piece of a language specification, if you want to encourage others to experiment with compiler implementations on different platforms.

mindplay-dk commented 2 years ago

I guess I would propose to close this issue, in favor of a new issue, which calls for a formal BNF. 🙂

asafigan commented 2 years ago

Also note that typescript's type system is turning complete. Or at least it isn't possible to know if a type can ever be resolved. This is a huge issue because it means that arbitrary limits have to be put in place to insure that the compiler always stops and doesn't run forever. My company ran into this limit when our code base got to a current size. The typescript compiler just stopped compiling our code base one day and we had to do a lot of work to figure out why. We had to break our code base into multiple packages to grow the code base anymore. This was a huge pain because we had to use third party tools to do this as npm and typescript don't really support multi package code bases.

I am bringing this up because the syntax is inspired by typescript. Turning complete type systems should be avoided as much as possible. It causes real issues for end users.