-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokensStack.cs
More file actions
executable file
·52 lines (50 loc) · 1.32 KB
/
Copy pathTokensStack.cs
File metadata and controls
executable file
·52 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleCompiler
{
public class TokensStack
{
public int Count { get { return m_sTokens.Count; } }
public Token LastPush { get; private set; }
public Token LastPop { get; private set; }
private Stack<Token> m_sTokens;
public TokensStack()
{
m_sTokens = new Stack<Token>();
}
public TokensStack(List<Token> lTokens)
{
m_sTokens = new Stack<Token>();
for (int i = lTokens.Count - 1; i >= 0; i--)
Push(lTokens[i]);
}
public void Push(Token t)
{
m_sTokens.Push(t);
LastPush = t;
}
public Token Pop()
{
Token t = m_sTokens.Pop();
LastPop = t;
return t;
}
public Token Peek()
{
return m_sTokens.Peek();
}
public Token Peek(int cItems)
{
Stack<Token> aux = new Stack<Token>();
for (int i = 0; i < cItems; i++)
aux.Push(m_sTokens.Pop());
Token t = m_sTokens.Peek();
while (aux.Count > 0)
m_sTokens.Push(aux.Pop());
return t;
}
}
}