-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.php
52 lines (45 loc) · 1.16 KB
/
Token.php
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
<?php
namespace SimpleInterpreter\Core;
use SimpleInterpreter\Core\{
TokenInterface,
TokenType,
};
class Token implements TokenInterface, TokenType
{
public string $type;
public string $value;
/**
* Init a new Token
* @param string $type
* @param string $value
* @return Token
*/
public static function Create(string $type, string $value): Token
{
$token = new Token;
$token->type = $type;
$token->value = $value;
return $token;
}
/**
* Init a new Token from string
* @param string $char
* @return Token
*/
public static function GetFromString(string $char): Token
{
switch ($char) {
case '=':
return Token::Create(self::EQUALS, $char);
case ';':
return Token::Create(self::SEMI, $char);
case '(':
return Token::Create(self::LPAREN, $char);
case ')':
return Token::Create(self::RPAREN, $char);
case ',':
return Token::Create(self::COMMA, $char);
}
return Token::Create(self::EOF, "\0");
}
}