-
Notifications
You must be signed in to change notification settings - Fork 0
Grammar multiline support
It appears that creating a grammar for Scilab is rather difficult.
If one wants to test, just play around with the continuation mark (..
). Using the continuation mark, the interpreter will glue two lines together, like nothing is happened in between (comments are ignored).
There arises the problem on "howto define a function/variable/etc." in a relativly fixed grammar (since continuation marks can only be resolved during runtime, or you will end up with a grammar which has a painfully amount begin/end
-patterns).
I have tried my best to make the multi-line code capabilities as bulletproof as possible, but even then the continuation mark will mess up the code.
For the implementation, that means:
- Implement two version:
first for one line, second for multiple lines. - Be as generic as possible.
There is no need for fancy stuff to identifiy the last bit. - Get the elements right - and only describe them.
It was my initial idea to also rewrite all assignments and include multiline return values. Appears, this is not as easy as thought.
Scilab return values uses bracktes ([]
) to start matrix/vector definitions, as well as defining return values of functions or doing multiple assignments at the same time.
This might appear "natural", but please bear in mind that this will make it impossible to determine what you expect:
[my, vec];
[my, vec] = SomeFunc();
// 1. Example:
foo = [my, ...
vec];
// 2. Example:
[my, ..
vec] = Foo()
Clear to see that here a begin
/ end
pattern is needed.
Now bear in mind that the Atom language parser works that way:
- Start at everything which is stated as
begin
- End if you find a matching
end
or at EOF Since defining a vector and expecting multiple return values, that means that either one will win.
Now also keep in mind that all matrices are rectangular shaped, e.g. [1:10;1:10]
denotes a 10x2 matrix.
You cannot say this for return values: [foo,bar] = Foo()
where foo
might be a matrix, struct etc. and bar
is another type and/or of another dimenstion.
That means:
Since both share the same pattern, which is not distinguishable by their beginning, multiline return values are not supported.