Comments (6)
Honestly, I've been thinking about making the then
and do
keywords optional for a while.
Let me explain better; since the language already uses newlines as statement ending characters, we can do something like this:
if cond
...
end
in this instance the parser would see this:
TOK(if) TOK(cond) TOK('\n') <-- This will take the place of 'then' while parsing
...
TOK(end)
And use the '\n' in place of then
for the start of the block.
Same goes for while
/ for
and the do
keyword.
Now, this solution would work well, but I still want to mantain support for the old syntax, both for backwards-compatibility and because it permits writing one-line statements:
if cond then print('true!') end
Without then
the parser would have no idea when to stop parsing the condition and start the block.
Unfortunately this means that the old keywords would still be reserved.
As for the end
keyword, well, this is unfortunately necessary.
The only way to get rid of it would be to use braces (which I don't want to do at this stage of the language), or by using indentation-style blocks like in python, which would add other classes of problems in the language at large.
Having said that, if you're intrested in this change i would gladly implement it.
I still need to figure a few things like how to restructure the CLI to permit multi-line input without relying on the then
or do
keyword to signal the start of a block, but aside from this should be pretty simple.
from jstar.
I don't have much of a problem with the end keyword at all, I really like this solution
from jstar.
I sort of implemented the change in the opt-keywords branch. You can take a look at the core.jsr file to see how the language looks without the then
and do
keyword.
Honestly, the change looked good on paper but without the keywords the code is a bit harder to read in my opinion, I'm not quite sure if I want to merge it into the main branch at this point. I need to think this through.
from jstar.
I looked at it, It does seem hard to read. I also didn't think about how it made the language more dependent on white space. I think the way you made the language was better.
from jstar.
I decided to take a look at how other languages handle the then
and do
keywords. As I was searching I stumbled upon Julia, that simply omits them and doesn't seem to rely on newlines to tell the start of a block. It made me realize that, since in J* we do not allow side-effect-free expressions to appear as statements, we don't need to check for newlines too! Code like this is actually possible:
if condition print("true!") end
As a bonus, omitting the keywords in this way, actually simplifies the implementation of the parser a fair bit!
Also, after some time getting used to the syntax I changed my opinion on it, and think this way the code is more pleasant to write and more approachable to newcomers.
So, in the end I completely stripped the keywords from the grammar, making it more simple and allowing the use of then
and do
as variable names.
You can check out the changes in version 1.7
from jstar.
Implemented in f49d72c
from jstar.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jstar.