www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - spec: What is the definition of a symbol?

reply Dibyendu Majumdar <mobile majumdar.org.uk> writes:
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)?
Nov 20 2020
next sibling parent reply Max Haughton <maxhaton gmail.com> writes:
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?
Nov 20 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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
Nov 20 2020
parent Paul Backus <snarwin gmail.com> writes:
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.
Nov 20 2020
prev sibling next sibling parent Paul Backus <snarwin gmail.com> writes:
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.)
Nov 20 2020
prev sibling parent reply Basile B. <b2.temp gmx.com> writes:
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_
Nov 20 2020
parent reply Paul Backus <snarwin gmail.com> writes:
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.
Nov 20 2020
parent reply Basile B. <b2.temp gmx.com> writes:
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.
Nov 20 2020
parent Paul Backus <snarwin gmail.com> writes:
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.
Nov 20 2020