-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.cpp
More file actions
51 lines (47 loc) · 1.35 KB
/
Copy pathtoken.cpp
File metadata and controls
51 lines (47 loc) · 1.35 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
#include "sign.h"
#include "token.h"
#include "externs.h"
Token* CreateNewToken()
{
Token* newtoken = (Token*)malloc(sizeof(Token));
newtoken->type = Type::None;
memset(newtoken->value, 0, sizeof(newtoken->value));
newtoken->next = NULL;
return newtoken;
}
Token* CreateNewToken(Type type, char* value)
{
Token* newtoken = (Token*)malloc(sizeof(Token));
newtoken->type = type;
newtoken->next = NULL;
strcpy(newtoken->value, value);
return newtoken;
}
TokenList* TokenListInit()
{
TokenList* ptr = (TokenList*)malloc(sizeof(TokenList));
ptr->head = CreateNewToken();
return ptr;
}
void TokenList::pushback(Token* newtoken)
{
Token* cur = head;
while(cur->next!=NULL)
cur = cur->next;
cur->next = newtoken;
// printf("token: %s\n", newtoken->value);
}
void PrintToken(Token* word)
{
printf("Type: %-18s Value: %s\n",
word->type == Type::Macro ? "Macro" :
word->type == Type::Keyword ? "Keyword" :
word->type == Type::Int ? "Int" :
word->type == Type::Float ? "Float" :
word->type == Type::Identifier ? "Identifier" :
word->type == Type::Annotation ? "Annotation" :
word->type == Type::Operator ? "Sign" :
word->type == Type::String ? "String" :
word->type == Type::EndSymbol ? "EndSymbol" :
"Wrong syntax!", word->value);
}