Closed haasn closed 13 years ago
I'm having trouble understanding why the number of arguments affect how it's parsed. I've only studied one way of parsing, and that's top down LL(1). It seemed to me as long as the grammar of the language didn't have any ambiguity, was context free, not left recursive, then the parser would be able to handle it. Also what do you mean by the value of the function, it's name, memory location?
I think I'm thinking about it differently because I'm imagining it being compiled and not interpreted, which my implementation might be.
It seemed to me as long as the grammar of the language didn't have any ambiguity
The problem here is that the grammar of the language HAD ambiguity.
Previously,
>foo >bar bat baz
was ambiguous between the following:
And the actual result would be determined based on how many parameters foo and bar take, respectively.
Now, with the addition of semicolons, it would be
>foo >bar bat; baz;
Which makes it clear that foo(bar(bat), baz) is meant, and nothing else.
ah i see, so how the hell does perl do it lol? there is always the option of adding parens, which I'm not entirely against.
perl is interpreted and slow as shit for a reason :)
Edit: Doesn't perl force parentheses where it would be ambiguous otherwise?
For the reference, my implementation is basically working. The hello world compiles except for three parts:
Otherwise, the rest is working fully.
Update: I added a comparison function now, so now the only issue I still need to solve is comments and gb2. :)
damn you work fast
I'm closing this. If we get any better ideas later on, open a new issue.
On second thought, I'm adding a delimiter to function calls, for which I'll use ‘;’ for now.
The problem is, if the number of parameters for a function determines the way it's parsed, then we need to know the value of a function during the parsing step, which means we can't build a complete AST before execution, so we'd have to parse stuff in realtime.
This causes two drawbacks: 1. We can't use a standard EBNF or Parsec-based parser library, 2. We can't JIT or compile the language at all.
If we introduce a ; as proposed, this gives us several advantages:
And two cosmetic drawbacks:
What do you think? I'm going to add it to the spec for now, since my current implementation breaks / is not really possible otherwise, unless I constantly re-run the parser and move expressions between blocks at runtime, but this would be very hard to do and also very slow.