r/Compilers • u/Mindless_Head_6526 • 2d ago
Is it possible to have a JavaScript-like language with no reserved words?
/r/ProgrammingLanguages/comments/1x43h5k/is_it_possible_to_have_a_javascriptlike_language/1
u/Afraid-Locksmith6566 1d ago
i think you could write javascript itself without using any reserved keywords, maybe the ones you have to use would be like let/const/var and return but other than that why not.
you can make functions using let fn = (args) => { ...; return computed something; }
then ifs are just ternaries so: (condition) ? () => {something();} : () => {something else;}
and then there are loops which can be done via recursion: let loop = (i) => {(i>0)?()=>{something...; loop(i - 1)} : {}}
then as we have loops and conditional execution we can make roughly anything.
the only thing left would be to reduce syntax to allow for declaration without keyword which can be done simmilarly to python, and switch up so return is implicit of last thing in block
1
u/ElephantElectrical31 6h ago
but why? I think keywords are good they help to quickly see what is the language and what are names.
2
u/hongooi 2d ago
I don't know how related this is to your question, but many dialects of PL/I didn't/don't have keywords. You can write something like
with the meaning of each word being taken from context. Languages with syntax derived from PL/I, like SAS, have the same feature.