1
|
/**
|
2
|
*
|
3
|
* OOAS Compiler (Deprecated)
|
4
|
*
|
5
|
* Copyright 2015, Institute for Software Technology, Graz University of
|
6
|
* Technology. Portions are copyright 2015 by the AIT Austrian Institute
|
7
|
* of Technology. All rights reserved.
|
8
|
*
|
9
|
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
10
|
*
|
11
|
* Please notice that this version of the OOAS compiler is considered de-
|
12
|
* precated. Only the Java version is maintained.
|
13
|
*
|
14
|
* Contributors:
|
15
|
* Willibald Krenn (TU Graz/AIT)
|
16
|
* Stefan Tiran (TU Graz/AIT)
|
17
|
*/
|
18
|
|
19
|
using System;
|
20
|
using System.Collections.Generic;
|
21
|
//using TUG.Mogentes.Codegen;
|
22
|
|
23
|
namespace TUG.Mogentes
|
24
|
{
|
25
|
public abstract class UlyssesBasicClass
|
26
|
{ }
|
27
|
|
28
|
|
29
|
public class SymbolTable
|
30
|
{
|
31
|
private Dictionary<string, Identifier> m_symbols;
|
32
|
|
33
|
public List<Identifier> symbolList { get { return new List<Identifier>(m_symbols.Values); } }
|
34
|
|
35
|
public SymbolTable()
|
36
|
{
|
37
|
m_symbols = new Dictionary<string, Identifier>();
|
38
|
}
|
39
|
|
40
|
public SymbolTable(SymbolTable toCopy)
|
41
|
{
|
42
|
if (toCopy != null)
|
43
|
m_symbols = new Dictionary<string, Identifier>(toCopy.m_symbols);
|
44
|
else
|
45
|
m_symbols = new Dictionary<string, Identifier>();
|
46
|
}
|
47
|
|
48
|
|
49
|
public bool Defined(Identifier aValue)
|
50
|
{
|
51
|
return ReferenceEquals(aValue,m_symbols[aValue.tokenText]);
|
52
|
}
|
53
|
|
54
|
public bool Defined(string aKey)
|
55
|
{
|
56
|
return m_symbols.ContainsKey(aKey);
|
57
|
}
|
58
|
|
59
|
public Identifier Get(string aKey)
|
60
|
{
|
61
|
return m_symbols[aKey];
|
62
|
}
|
63
|
|
64
|
public void AddIdentifier(Identifier anIdent)
|
65
|
{
|
66
|
if (anIdent != null)
|
67
|
m_symbols.Add(anIdent.tokenText, anIdent);
|
68
|
}
|
69
|
|
70
|
public void AddSymbolTable(SymbolTable otherTable)
|
71
|
{
|
72
|
foreach (var x in otherTable.m_symbols)
|
73
|
if (x.Key != "self")
|
74
|
m_symbols.Add(x.Key, x.Value);
|
75
|
}
|
76
|
|
77
|
public void Replace(string aKey, Identifier anIdent)
|
78
|
{
|
79
|
if (anIdent != null)
|
80
|
{
|
81
|
m_symbols.Remove(aKey);
|
82
|
m_symbols.Add(anIdent.tokenText, anIdent);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
public void SetSymbolList(List<Identifier> newList)
|
87
|
{
|
88
|
newList.Sort();
|
89
|
m_symbols = new Dictionary<string, Identifier>();
|
90
|
foreach (var x in newList)
|
91
|
AddIdentifier(x);
|
92
|
}
|
93
|
|
94
|
|
95
|
internal void Sort()
|
96
|
{
|
97
|
List<Identifier> newList = new List<Identifier>(m_symbols.Values);
|
98
|
newList.Sort();
|
99
|
m_symbols = new Dictionary<string, Identifier>();
|
100
|
foreach (var x in newList)
|
101
|
AddIdentifier(x);
|
102
|
}
|
103
|
}
|
104
|
|
105
|
/* All AST Elements that define some scope */
|
106
|
public interface IScope
|
107
|
{
|
108
|
Identifier ResolveIdentifier(string aName);
|
109
|
IScope GetParentScope();
|
110
|
void SetParentScope(IScope parentScope);
|
111
|
|
112
|
void AddIdentifier(Identifier anIdentifier, object tag);
|
113
|
}
|
114
|
|
115
|
/* All Elements of the AST */
|
116
|
public enum AstNodeTypeEnum { type, identifier, expression, statement }
|
117
|
public interface IAst
|
118
|
{
|
119
|
AstNodeTypeEnum nodeType { get; }
|
120
|
void Accept(IAstVisitor visitor);
|
121
|
}
|
122
|
|
123
|
|
124
|
|
125
|
}
|