Mercurial > projects > dil
annotate trunk/src/dil/semantic/SymbolTable.d @ 600:041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 06 Jan 2008 00:52:20 +0100 |
parents | 26addda6365b |
children | c24be8d4f6ab |
rev | line source |
---|---|
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
1 /++ |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
2 Author: Aziz Köksal |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
3 License: GPL3 |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
4 +/ |
591
26addda6365b
Moved dil.SymbolTable to dil.semantic.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
589
diff
changeset
|
5 module dil.semantic.SymbolTable; |
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
6 |
589
de365ddcfbd4
Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
564
diff
changeset
|
7 import dil.semantic.Symbol; |
600
041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
591
diff
changeset
|
8 import dil.lexer.Identifier; |
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
9 import common; |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
10 |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
11 /++ |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
12 Maps an identifier string to a Symbol. |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
13 +/ |
562
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
14 struct SymbolTable |
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
15 { |
564
3c867a683258
Fixed VariableDeclaration.semantic().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
562
diff
changeset
|
16 Symbol[char[]] table; |
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
17 |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
18 /// Look up ident in the table. |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
19 Symbol lookup(Identifier* ident) |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
20 { |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
21 assert(ident !is null); |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
22 auto psym = ident.str in table; |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
23 return psym ? *psym : null; |
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
24 } |
562
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
25 |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
26 void insert(Symbol s, Identifier* ident) |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
27 { |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
28 table[ident.str] = s; |
b0533550d64c
Added semantic() to VariableDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
556
diff
changeset
|
29 } |
556
19554e79e6d2
Added module dil.SymbolTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
30 } |