-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdolang.h
162 lines (129 loc) · 2.63 KB
/
dolang.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef dolang
#define dolang
#include "safe_alloc.h";
safe_alloc alloc;
typedef struct {
char type;
void * val;
float floatVal;
//double num;
} variable;
variable *StringClass;
variable *ArrayClass;
variable *ObjectClass;
variable *RegExpClass;
variable *MathClass;
variable *consoleClass;
donvar( b, c) {
variable *a = safe_alloc_new(&alloc, sizeof( variable ) );
a->val = b;
a->type = c;
return a;
}
#define dovar(a,b,c) \
variable *a = safe_alloc_new(&alloc, sizeof( variable ) );\
a->val = b;\
a->type = c;
char *file_ext;
#define TOK_IF 2
#define TOK_ELSE 3
#define TOK_WHILE 4
#define TOK_BREAK 5
#define TOK_RETURN 6
#define TOK_FOR 7
#define TOK_DEFINE 8
#define TOK_MAIN 9
#define TOK_VAR 10
#define TOK_NEW 11
#define TOK_CLASS 12
#define TOK_IN 15
#define TOK_THIS 16
#define TOK_FUNC 17
#define TOK_LET 18
#define TOK_EXTENDS 19
#define TOK_IMPORT 20
#define TOK_SWITCH 21
#define TOK_TRY 22
#define TOK_CATCH 23
#define TOK_THROW 24
#define TOK_TYPEOF 25
#define TOK_STATIC 26
#define TOK_FUNCTION 27
#define TOK_PACKAGE 28
#define TOK_TRUE 29
#define TOK_FALSE 30
#define TOK_DO 31
#define TOK_REGEX 32
#define TOK_CONST 33
#define TOK_FINALLY 34
#define DOTYPE_STRING 1
#define DOTYPE_INT 2
#define DOTYPE_ARRAY 3
#define DOTYPE_FUNC 4
#define DOTYPE_CHAR 5
#define DOTYPE_LONG 6
#define DOTYPE_RES 7
#define DOTYPE_CLS 8
#define DOTYPE_UNDEF 9
#define DOTYPE_REGEX 10
#define DOTYPE_OBJECT 11
#define DOTYPE_FLOAT 12
#define TOK_IDENT 999
#define TOK_STRING 1000
#include "array.h";
#include "string.h";
dofloat( float b ) {
variable *a = safe_alloc_new(&alloc, sizeof( variable ) );
a->floatVal = b;
a->type = DOTYPE_FLOAT;
return a;
}
dostring( char *a ) {
string *s = newstring( a );
return donvar(s, DOTYPE_STRING);
}
doobject() {
array *a = safe_alloc_new(&alloc, sizeof(array));
array_init( a );
return donvar(a, DOTYPE_OBJECT);
}
doarray() {
array *b = safe_alloc_new( &alloc, sizeof(array ));
array_init( b );
return donvar(b, DOTYPE_ARRAY);
}
doint( a ) {
return donvar(a, DOTYPE_INT);
}
donvar1( b, c ) {
if( c == DOTYPE_STRING ) {
return dostring(b);
} else if( c == DOTYPE_FLOAT ) {
return dofloat( b );
} else if( c == DOTYPE_OBJECT ) {
return doobject();
} else if( c == DOTYPE_ARRAY ) {
return doarray();
}
return donvar( b, c );
}
char * mstrcat( char *a, char *b) {
char* result;
asprintf(&result, "%s%s", a, b);
return result;
/*
char *r;
char *r1;
//printf("%d\n", strlen(a)+strlen(b)+1);
r1 = r = malloc( strlen(a)+strlen(b)+1);
while( *a ) {
*(char *)r++ = *a++;
}
while( *b ) {
*(char *)r++ = *b++;
}
*r = '\0';
//printf("%s\n", r1 );
return r1;*/
}
#endif