Language description thoughts

Hi,

I love the draft and have gone through it. The language itself is simple and basic - but there is one thing that you might consider adding that seems very relevant to your description of the language. You describe the language as:

But the compiler’s source or input language is a subset (or a simpli-
fied version) of TypeScript.

One thing that I think migh be important to some is the idea of reserved keywords (or in your language - there does not seem to be any). For example - in your language - I can do this:

var if = 10;

Which allows one to do this:

if (if == 10)

To some this might seem like a small thing - but I think by adding in a quick note about there not being any reserved keywords for variable names and the like - it would be helpful to others.

1 Like

Hi @nerdboy, and welcome!

That’s a very interesting observation. I will have to add some explanation to the book. Sometimes this behavior is advantageous, like when JS introduced let they had to make sure that the old code like var let = 10 still works. But for other cases, this should be avoided, like in the var if = 10 example you made.

To disallow code like var if = 10 the identifier rule should be adjusted. You need to have one more primitive combinator, notFollowedBy that asserts that the source doesn’t match a rule (this is called syntactic predicate in PEG). So the identifier rule should be something like:

let keyword = IF.or(ELSE).or(FUNCTION) // etc...
let id = notFollowedBy(keyword).and(ID)

I am a bit hesitant to introduce a whole new primitive combinator only to solve this problem. I’ll have to give this some thought. Maybe I can come up with something simpler. Or maybe, just a textual explanation of this problem will suffice.

@nerdboy, does this make sense?

Yes - that makes perfect sense to me.

I’d say that since this is supposed to be a simple language - a text explanation would be good enough.

I think that any more would overcomplicate this for just a quick language developed to show the process from beginning to end.

I wonder if having a section on “Future things you can do” would be a neat idea. This might make a good item for that section. Another might be related to selective case sensitivity for keywords/variables.

1 Like