-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyun_test.c
49 lines (44 loc) · 920 Bytes
/
yun_test.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
/*
* yun_test.c
*
* Created on: Oct 2, 2011
* Author: pozen
*/
#include "yun_lex.h"
#include "yun_parser.h"
#include "yun_vm.h"
#include "stdio.h"
int main()
{
FILE *fp = fopen( "lex_ss", "rb" );
int size;
char *buf;
if( fp == 0 )
{
fprintf( stderr, "Cannot open %s\n", "lex_test" );
return -1;
}
fseek( fp, 0, SEEK_END );
size = ftell( fp );
fseek( fp, 0, SEEK_SET );
buf = (char*) malloc( size + 1 );
fread( buf, size, 1, fp );
buf[size] = 0;
fclose( fp );
LexToken *tk = lex_get_token( buf );
LexToken *tmp = tk;
SynState *ss = (SynState*)malloc( sizeof( SynState ) );
ss->pos = tk;
/*while( tmp )
{
printf("line:%d type:%d value:%s\n", tmp->line_num, tmp->token.type, tmp->token.value);
tmp = tmp->next;
}*/
SynNode *st = syn_parse( ss );
VM *vm = create_vm();
create_bytecode( st, "main", vm );
execute( vm );
lex_destroy_token( tk );
printf("end\n");
return 0;
}