Thread overview
spec: What is the definition of a symbol?
Nov 20
Basile B.
Nov 21
Basile B.
November 20
The language spec uses the term symbol but I don't think this term is defined anywhere.

What would be the best way to define it (other than saying it is a symbol in symbol table in the compiler)?
November 20
On Friday, 20 November 2020 at 19:03:30 UTC, Dibyendu Majumdar wrote:
> The language spec uses the term symbol but I don't think this term is defined anywhere.
>
> What would be the best way to define it (other than saying it is a symbol in symbol table in the compiler)?

Anything other than an expression?
November 20
On Fri, Nov 20, 2020 at 07:10:41PM +0000, Max Haughton via Digitalmars-d wrote:
> On Friday, 20 November 2020 at 19:03:30 UTC, Dibyendu Majumdar wrote:
> > The language spec uses the term symbol but I don't think this term is defined anywhere.
> > 
> > What would be the best way to define it (other than saying it is a symbol in symbol table in the compiler)?
> 
> Anything other than an expression?

A symbol is not an expression.  It may *refer* to an expression, though.


T

-- 
"Real programmers can write assembly code in any language. :-)" -- Larry Wall
November 20
On Friday, 20 November 2020 at 19:03:30 UTC, Dibyendu Majumdar wrote:
> The language spec uses the term symbol but I don't think this term is defined anywhere.
>
> What would be the best way to define it (other than saying it is a symbol in symbol table in the compiler)?

A symbol is a name that refers to some entity in the program--a module, a package, a type, a function, a variable, a template, or an `enum` constant. (I think that's the complete list.)
November 20
On Friday, 20 November 2020 at 19:03:30 UTC, Dibyendu Majumdar wrote:
> The language spec uses the term symbol but I don't think this term is defined anywhere.
>
> What would be the best way to define it (other than saying it is a symbol in symbol table in the compiler)?

I'd go for something like that:

«A symbol is a declaration. This includes

- variables
- functions
- aggregate types (classes, structures, unions, interfaces)
- aliases
- templates
- enumerations
- modules
- imports

One of the most basic but important task of the compiler is to resolve identifiers to symbols. Identifiers as found in expressions are never symbols but they always resolve to one. If an identifier cannot be resolved to a symbol then compilation stops.»

See also [1].

[1] https://en.wikipedia.org/wiki/Symbol_(programming)#:~:text=A%20symbol%20in%20computer%20programming,languages%2C%20they%20are%20called%20atoms.
November 20
On Friday, 20 November 2020 at 19:25:26 UTC, H. S. Teoh wrote:
>
> A symbol is not an expression.  It may *refer* to an expression, though.

In fact, an expression is one of the few things a symbol *cannot* refer to.

November 20
On Friday, 20 November 2020 at 21:16:47 UTC, Basile B. wrote:
>
> I'd go for something like that:
>
> «A symbol is a declaration. This includes

A symbol is not a declaration. `int x;` is a declaration, but `x` by itself is not.
November 21
On Friday, 20 November 2020 at 21:23:24 UTC, Paul Backus wrote:
> On Friday, 20 November 2020 at 21:16:47 UTC, Basile B. wrote:
>>
>> I'd go for something like that:
>>
>> «A symbol is a declaration. This includes
>
> A symbol is not a declaration. `int x;` is a declaration, but `x` by itself is not.

`int x;` is a variable declaration. Variable declarations are all symbols (DSymbol in the compiler). `x` in this case represents the symbol name, `int` its type.
November 21
On Saturday, 21 November 2020 at 00:02:15 UTC, Basile B. wrote:
> On Friday, 20 November 2020 at 21:23:24 UTC, Paul Backus wrote:
>>
>> A symbol is not a declaration. `int x;` is a declaration, but `x` by itself is not.
>
> `int x;` is a variable declaration. Variable declarations are all symbols (DSymbol in the compiler). `x` in this case represents the symbol name, `int` its type.

You're confusing the map for the territory. The fact that `Declaration` is a subclass of `Dsymbol` in the DMD frontend does not necessarily mean that a declaration *is* a symbol from the perspective of the language spec.

For example, `StaticAssert` is also a subclass of `Dsymbol`, but I don't think anyone would seriously argue that `static assert(x == y)` is a symbol.