Live data from Hacker News

Weird Lexical Syntax

justine.lol

221–230 of 234 posts

Re: Weird Lexical Syntax

#221
post #36

> Every C programmers (sic) knows you can't embed a multi-line comment in a multi-line comment. And every Standard ML programmer might find this to be a surprising limitation. The following is a valid Standard ML program: (* (* Nested (**) *) comment *) val _ = print "hello, world\n" Here is the output: $ sml Given how C was considered one of the "expressive" languages when it arrived, it's curious that nested commen…

Pascal always supported the same nested comment syntax as your example.

Re: Weird Lexical Syntax

#222
post #17

I’d be interested to see a re-usable implementation of joe's[0] syntax highlighting.[1] The format is powerful enough to allow for the proper highlighting of Python f-strings.[2] 0. https://joe-editor.sf.net/ 1. https://github.com/cmur2/joe-syntax/blob/joe-4.4/misc/HowItW... 2. https://gist.github.com/irdc/6188f11b1e699d615ce2520f03f1d0d...

I've actually made several lexers and parsers based on the joe DFA style of parsing. The state and transition syntax was something that I always understood much more easily than the standard tools.

The downside is your rulesets tend to get more verbose and are a little bit harder to structure than they might ideally be in other languages more suited towards the purpose, but I actually think that's an advantage, as it's much easier to reason about every production rule when looking at the code.

Re: Weird Lexical Syntax

#223

Earlier quoted context omitted.

> this is only relevant if you want to highlight the multiplication operator differently from the dereferencing operator Can you mention one editor which does that?

I could be stretching the definition of "does" but the newfound(?) tree-sitter support in Emacs[1] I believe would allow that since it for sure understands the distinction but I don't possess enough font-lock ninjary to actually, for real, bind a different color to the distinct usages /* given foo.c */ int main() { int a, *b; a = 5 * 10; b = &a; printf("a is %d\n", *b); } and then M-x c-ts-mode followed by navigating…

These examples are unambiguous. Try with something more spicy like

  return (A)*(B);
which depends on A being a type or a variable.

Re: Weird Lexical Syntax

#224

Earlier quoted context omitted.

I somehow thought Conan[1] was the C++ package manager; it's at least partially supported by GitLab, for what that's worth 1: https://docs.conan.io/2/introduction.html

No, if anything vcpkg is "the C++ package manager", but it's nowhere near pervasive and easy-to-use enough to come close to even Pip. It's leagues away from Cargo, Go, and other actually good PL package managers.

[deleted]

Re: Weird Lexical Syntax

#225
post #187

Earlier quoted context omitted.

Ruby takes this to 100. As much as a I love Ruby, this is valid Ruby, and I can't defend this: puts "This is #{ Just to combine the string interpolation with her concern over Ruby heredocs. My other favorite evil quirk in Ruby is that whitespace is a valid quote character in Ruby. The string (without the quotes) "% hello " is a quoted string containing "hello" (without the quotes), as "%" in contexts where there is n…

And don't overlook the fact that the bare-world, or its "HERE" friend, are still in an interpolation context, so... puts "hello #{ yields hello recursion is recursive world that was fun and then there's its backtick friend puts "hello #{ coughs up hello Sun Nov 3 17:25:32 UTC 2024 world and for those trying out your percent-space trick, be aware that it only tolerates such a thing in a standalone expression context s…

> $ /usr/bin/ruby -e 'puts % hello + "world"'

Yes, it's roughly limited in use to places where it is not ambiguous whether it would be the start of a quoted string or the modulus operator, and after a method name would be ambiguous.

> but, at the intersection is "ruby parsing is the 15th circle of hell"

It's surprisingly (not this part, anyway) not that hard. You "just" need to create a forward reference, and keep track of heredocs in your parser, and when you come to the end of a line with heredocs pending, you need to parse them and assign them to the variable references you've created.

It is dirty, though, and there are so many dark corners of parsing Ruby. Having written a partial Ruby parser, and being a fan of Wirth-style grammar simplicity while enjoying using Ruby is a dark, horrible place to live in. On the one hand, I find Ruby a great pleasure to use, on the other hand, the parser-writer in me wants to spend eternity screaming into the void in pain.

Re: Weird Lexical Syntax

#226
post #176

Earlier quoted context omitted.

The grandparent post is specifically about trigraphs. Saying something about trigraphs was the end-in-itself, trigraphs were chosen to illustrate something about trigraphs. So your question made no sense. Hope that helps.

My question was precisely about why the user like trigraphs over using just || on this case. It is a very clear question and makes all the sense.

I think the misunderstanding is a bit of missing context from the original comment. I read it as “one of my favorite trigraphs [that I have seen]”. Their comment didn’t make a claim to using said trigraph, just that they had seen it somewhere and thought it was interesting.

Your comments seem to suggest your reading was “one of my favorite trigraphs [to use is]”, which is understandable as a valid interpretation.

The whole of this chain of comments is a misunderstanding on the original comment’s ambiguity.

Re: Weird Lexical Syntax

#227
post #225

Earlier quoted context omitted.

And don't overlook the fact that the bare-world, or its "HERE" friend, are still in an interpolation context, so... puts "hello #{ yields hello recursion is recursive world that was fun and then there's its backtick friend puts "hello #{ coughs up hello Sun Nov 3 17:25:32 UTC 2024 world and for those trying out your percent-space trick, be aware that it only tolerates such a thing in a standalone expression context s…

> $ /usr/bin/ruby -e 'puts % hello + "world"' Yes, it's roughly limited in use to places where it is not ambiguous whether it would be the start of a quoted string or the modulus operator, and after a method name would be ambiguous. > but, at the intersection is "ruby parsing is the 15th circle of hell" It's surprisingly (not this part, anyway) not that hard. You "just" need to create a forward reference, and keep tr…

How are you so awesome?

Re: Weird Lexical Syntax

#228
post #37

> You'll notice its hash function only needs to consider a single character in in a string. That's what makes it perfect, Is that a joke? https://en.m.wikipedia.org/wiki/Perfect_hash_function

It just so happens that a single character was all that's needed in that case. In the general case it wouldn't be

Re: Weird Lexical Syntax

#230
post #204

Earlier quoted context omitted.

The post shows a “favorite C trigraph” thing, not that they were going out of their way to use trigraphs in actual code or that you should. Using trigraphs is the whole premise so no, your question makes no sense in that context. FWIW the ??!??! double trigraph as error processing is funny because of the meaning of ?! and various combinations of ? and !. It is funny and it has trigraphs. That’s the whole point.

> The post shows a “favorite C trigraph” thing, not that they were going out of their way to use trigraphs in actual code or that you should. But I am free to be curious and ask the author why he choose it! We are not computers but human beings! There is no HN rule that says that I cannot be curious and asks a question that arised from a thread but it is not connected to that! [1]. [1] https://www.iflscience.com/char…

> But I am free to be curious and ask the author why he choose it

They chose it because the discussion is about trigraphs. It is not a particularly surprising choice to talk about trigraphs in that context.

> There is no HN rule that says that I cannot be curious and asks a question that arised from a thread but it is not connected to that!

I did not write that you did not follow HN rules, just that your question was very strange in the context. I did not downvote you, but I understand why some people did. Your question was a bit passive agressive, even if you did not mean it.

Post reply on HN