-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_parser.c
56 lines (44 loc) · 1.7 KB
/
test_parser.c
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
53
54
55
56
//
// Created by Frantisek on 18.11.2020.
//
#include "error.h"
#include "parser.h"
#include <string.h>
extern int token_pos;
void rand_str(char *dest, size_t length) {
char charset[] = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
while (length-- > 0) {
size_t index = (double) rand() / RAND_MAX * (sizeof charset - 1);
*dest++ = charset[index];
}
*dest = '\0';
}
token_type array[100] = {TOKEN_PACKAGE, TOKEN_ID, TOKEN_EOL,
TOKEN_FUNC, TOKEN_ID, TOKEN_LBRACKET, TOKEN_ID, TOKEN_INT, TOKEN_RBRACKET,TOKEN_LBRACKET, TOKEN_INT, TOKEN_COMMA, TOKEN_INT, TOKEN_RBRACKET, TOKEN_LCURLY, TOKEN_EOL,
TOKEN_ID, TOKEN_ASSIGN, TOKEN_ID ,TOKEN_EOL,
TOKEN_FOR, TOKEN_ID,TOKEN_DEFINITION,TOKEN_ERROR,TOKEN_SEMICOLON,TOKEN_ERROR, TOKEN_SEMICOLON,TOKEN_ID,TOKEN_ASSIGN,TOKEN_ID,TOKEN_LCURLY,TOKEN_EOL,
TOKEN_RCURLY,
TOKEN_EOL, TOKEN_EOL,
TOKEN_RCURLY, TOKEN_EOL, TOKEN_EOL,
TOKEN_FUNC, TOKEN_ID, TOKEN_LBRACKET,TOKEN_RBRACKET,TOKEN_LCURLY,TOKEN_EOL,
TOKEN_RCURLY, TOKEN_EOL,
TOKEN_EOF};
int get_next_token(token_t* token){
token->type = array[token_pos++];
if(array[token_pos-2] == TOKEN_PACKAGE)
strcpy(token->actual_value.str,"main");
else
rand_str(token->actual_value.str,5);
return SUCCESS;
}
int main(){
printf("Done\n");
int ret = parser();
if(ret)
printf("Parsing error_code = %i\n", ret);
else
printf("Parsing Successful!!");
return 0;
}