lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
231 stars 62 forks source link

Use simple braces instead of {- -} #2

Closed mehrdadn closed 5 years ago

mehrdadn commented 5 years ago

I'd suggest we just use simple braces instead of {- -}. The use of dashes doesn't really prevent lexing ambiguity (since you can have an array starting with e.g. {-10 in C, as well as any characters in strings and comments) but I think it makes typing significantly harder and therefore the language much less friendly to use.

edwardalee commented 5 years ago

I suggest we find another pattern that doesn’t have the ambiguity. I believe that a distinctive syntax is important because you are de limiting a foreign language. No other programming environment I know of mixes languages this way, so an entirely new syntax is justified.

Edward


Edward A. Lee EECS, UC Berkeley eal@eecs.berkeley.edu http://eecs.berkeley.edu/~eal

On Mar 4, 2019, at 11:52 PM, mehrdadn notifications@github.com wrote:

I'd suggest we just use simple braces instead of {- -}. The use of dashes doesn't really prevent lexing ambiguity (since you can have an array starting with e.g. {-10 in C, as well as any characters in strings and comments) but I think it makes typing significantly harder and therefore the language much less friendly to use.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

mehrdadn commented 5 years ago

I think React does something like this, where they mix HTML inside Javascript directly. But another pattern could indeed work out better -- indentation might be a decent alternative (like in Python or Makefiles)?

edwardalee commented 5 years ago

I think using indentation is not a good idea, particularly because it has meaning in at least one of the target languages (Python).

Edward

On 3/4/19 10:05 PM, mehrdadn wrote:

I think React does something like this, where they mix HTML inside Javascript directly. But another pattern could indeed work out better -- indentation might be a decent alternative (like in Python or Makefiles)?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icyphy/lingua-franca/issues/2#issuecomment-469551201, or mute the thread https://github.com/notifications/unsubscribe-auth/AIHnNvAbZGJibhtIWbxnSKmdxOGb70U4ks5vTgkSgaJpZM4bdYAu.

-- Edward A. Lee Professor of the Graduate School and Robert S. Pepper Distinguished Professor Emeritus EECS Department, UC Berkeley http://ptolemy.eecs.berkeley.edu/~eal

MattEWeber commented 5 years ago

Regarding React, there are two different ways html and js are mixed. You can use assign an html element to a js variable without any special characters. But if you want to evaluate a js expression within html you do that by wrapping the js in brackets. Mixing the languages this way started feeling very natural to me when I got the hang of React, partly because you already use brackets a lot in javascript. LF might have a similar appeal because many of the target languages we're discussing use brackets as well.

lhstrh commented 5 years ago

I'd prefer using normal curly braces, but if that requires us to parse the target language code that would be a high cost...

schoeberl commented 5 years ago

I am for a unique symbol that is not being used in any host language we enision. Otherwise one would need the compiler need to know that language. Simply counting matching {} is not enough. Example:

foo() { // :-{ }

Martin

On 7 Mar, 2019, at 0:02, Marten Lohstroh notifications@github.com wrote:

I'd prefer using normal curly braces. Reactions and preambles can only be declared at the actor level (not within reactions, for instance), and target language code cannot occur outside of the scope of reactions/preambles, so it should be no problem to disambiguate in the parser.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/icyphy/lingua-franca/issues/2#issuecomment-470312600, or mute the thread https://github.com/notifications/unsubscribe-auth/AAntmD2BUnDKdesidSWaRaHxqRvWO5vSks5vUEkUgaJpZM4bdYAu.

mehrdadn commented 5 years ago

I don't think any such symbol exists, since it could always be part of a comment or a string. We'd always need some kind of rudimentary lexer for comments and strings, and at that point dealing with braces or tabs shouldn't be an issue for typical languages.

schoeberl commented 5 years ago

I wrote “in any host language we envision”. And {- -} is good for all the “C” heritage languages (Java, JavaScript, Rust,…).

Martin

On 7 Mar, 2019, at 3:42, mehrdadn notifications@github.com wrote:

I don't think any such symbol exists, since it could always be part of a comment or a string. We'd always need some kind of rudimentary lexer for comments and strings, and at that point dealing with braces or tabs shouldn't be an issue for typical languages.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icyphy/lingua-franca/issues/2#issuecomment-470361620, or mute the thread https://github.com/notifications/unsubscribe-auth/AAntmLU9oGOjI5HmqtgZUlffBpxYQwA9ks5vUHymgaJpZM4bdYAu.

mehrdadn commented 5 years ago

Would something like int arr[] = {-1, i--} not cause a problem?

schoeberl commented 5 years ago

Yes, the i—} probably.

Martin

On 7 Mar, 2019, at 4:28, mehrdadn notifications@github.com wrote:

Would something like int arr[] = {-1, i--} not cause a problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icyphy/lingua-franca/issues/2#issuecomment-470370488, or mute the thread https://github.com/notifications/unsubscribe-auth/AAntmI0cxDsiQ2hyuVP-9JINV_wTXLf6ks5vUId1gaJpZM4bdYAu.

blackplane commented 5 years ago

A common notation is to use double curly brackets {{ and }} or {% and %} when embedding code fragments. See also the jinja2 template language for inspiration (http://jinja.pocoo.org/)

lhstrh commented 5 years ago

{{ looks like a rather common sub expression in target languages. {% less so (can't think of an example off the top of my head).

mehrdadn commented 5 years ago

If we choose a >= 2-character symbol then changing {- -} doesn't really do any good IMO. The idea was to make it easier to type.

schoeberl commented 5 years ago

Then let’s keep {- host code -} for now. At least for pragmatic reasons, because it is easy to parse ;-)

It is not sooo much to type.

Martin

On 7 Mar, 2019, at 22:15, mehrdadn notifications@github.com wrote:

If we choose a >= 2-character symbol then changing {- -} doesn't really do any good IMO. The idea was to make it easier to type.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icyphy/lingua-franca/issues/2#issuecomment-470697067, or mute the thread https://github.com/notifications/unsubscribe-auth/AAntmIj0iv--pv9Xh1EpDJ0Akj-nfjCUks5vUYFigaJpZM4bdYAu.

lhstrh commented 5 years ago

Another option to consider: put all of our LF statements in comment blocks (similar to pragmas in OMP). That way, people also get to use their favorite editor without breaking syntax highlighting, etc. This also prevents corner cases where target language code accidentally gets parsed as LF code. The only thing we'll have to know about the target language is how it specifies comments. That's a simple thing to get right.

Example: Source.lf could look something like the following rough sketch:

// actor Source
// language JavaScript;

// parameter period(int):1000;
// trigger t(int), period
// output y(int);

// init
var n = 0;

// reaction(t) -> y
n = n + 1;
set(y, n);
blackplane commented 5 years ago

Sounds good, so there are two options to separate target language code from LF in the same source file:

edwardalee commented 5 years ago

I suggest we use {= ... =} This looks to me more like left and right delimiters than {% ... %} Also, % is the comment symbol in Latex, which won't create any ambiguity, but just cognitive dissonance.