|
|
Subscribe / Log in / New account

Generics parameter syntax

Generics parameter syntax

Posted Jul 3, 2020 18:49 UTC (Fri) by mathstuf (subscriber, #69389)
In reply to: Generics parameter syntax by davecb
Parent article: Generics for Go

How complicated can `T` get syntactically? Can you decide before you see the `>` somehow? This is the reason for the weird `obj.mem1.mem2.template foo<T>` syntax in C++: T can be very complicated and "type or expression" is not something one can answer without actually having a name lookup table.


to post comments

Generics parameter syntax

Posted Jul 3, 2020 22:39 UTC (Fri) by davecb (subscriber, #1574) [Link] (2 responses)

Thanks: I come from an era when we assumed a symbol table, and so did not realize Go does not have one in it's parser. Rather amazing!

Generics parameter syntax

Posted Jul 5, 2020 2:26 UTC (Sun) by mathstuf (subscriber, #69389) [Link] (1 responses)

Note that I actually don't know how Go's parser in particular works. I surmise that the parser requiring access to a symbol table would be unacceptable for performance. It'd be better to let the parser go and make ASTs for all the source and only then figure out what symbols are defined where (using the imports as a guideline). In fact, the mere existence of the AST module in the standard library likely means that symbol tables cannot be allowed (because requiring `import` to actually do work and look at what symbols are available just to parse `sym<arg>` would be a little ridiculous IMO).

Generics parameter syntax

Posted Jul 17, 2020 17:08 UTC (Fri) by anton (subscriber, #25547) [Link]

I expect that symbol table lookup in the parser is not a performance problem. It is a conceptual problem because you need to know the parse tree to know the scope of an identifier; of course, for some kinds of languages the problem is solvable (LL(1) languages with definitions before use of symbols should be fine), but it means that the language requires an integration of parsing and "static semantics". And possibly scanning, if, e.g., the syntax requires a token for a type that's separate from an identifier token.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds