- Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathjavascript_syntax.cpp
More file actions
Latest commit
140 lines (127 loc) · 6.22 KB
/
Copy pathjavascript_syntax.cpp
File metadata and controls
140 lines (127 loc) · 6.22 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
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
#include"disable_warning.h"
#include"baselib_string.h"
#include"javascript_base.h"
#include"javascript_function.h"
#include"javascript_envirment.h"
#include"javascript_variant.h"
booleval_for(string& express) {
trim(express);
if (check_string("for",express.c_str())) {
// for (var var_name=express;term;express) {code_block} or
// for (var var_name=express;term;express) code_line;
express=express.substr(3);
trim(express);
unsignedlong left_bracket_index=express.find('(');
unsignedlong right_bracket_index=get_matching_outside_right_bracket(express,0);
if (INVALID_VALUE!=left_bracket_index && INVALID_VALUE!=right_bracket_index) {
string term(express.substr(left_bracket_index+1,right_bracket_index-left_bracket_index));
trim(term);
unsignedlong split_index=term.find(';');
if (INVALID_VALUE!=split_index) {
eval(term.substr(0,split_index));
term=term.substr(split_index+1);
split_index=term.find(';');
if (INVALID_VALUE!=split_index) {
string for_express(term.substr(split_index+1));
for_express=for_express.substr(0,for_express.length()-1);
term=term.substr(0,term.find(';'));
express=express.substr(right_bracket_index+1);
trim(express);
unsignedlong next_right_brace_index=get_matching_outside_right_brace(express,0);
string for_execute_code_block;
if ('{'==express[0] && '}'==express[next_right_brace_index]) {
for_execute_code_block=express.substr(1,next_right_brace_index-1);
express=express.substr(next_right_brace_index+1);
} elseif (INVALID_VALUE!=express.find(';')) {
for_execute_code_block=express.substr(0,express.find(';'));
express=express.substr(express.find(';')+1);
}
trim(for_execute_code_block);
trim(express);
while (true) {
if (!execute_calculation_term(term))
returnfalse;
unsignedlong eval_result=0;
support_javascript_variant_type eval_result_type=NONE;
get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&eval_result,&eval_result_type);
if (!eval_result)
break;
if (!eval(for_execute_code_block))
returnfalse;
if (!eval(for_express))
returnfalse;
}
returntrue;
}
}
}
}
returnfalse;
}
booleval_if(string& express) {
trim(express);
if (check_string("if",express.c_str())) { // if (term2) {if_inside_code_block_2}
express=express.substr(2); // ->(term2) {if_inside_code_block_2}
} elseif (check_string("else if",express.c_str())) { // else if (term2) {if_inside_code_block_2}
express=express.substr(7); // ->(term2) {if_inside_code_block_2}
} elseif (check_string("else",express.c_str())) { // else {if_inside_code_block_3}
express=express.substr(4); // ->{if_inside_code_block_2}
}
trim(express);
unsignedlong left_bracket_index=express.find('('),right_bracket_index=get_matching_outside_right_bracket(express,0);
string if_term;
if (INVALID_VALUE!=left_bracket_index && INVALID_VALUE!=right_bracket_index) { // check if term syntax ..
if_term=express.substr(left_bracket_index+1,right_bracket_index-left_bracket_index-1);
express=express.substr(right_bracket_index+1);
trim(express);
} else {
returnfalse;
}
string if_inside_code_block;
unsignedlong matching_right_brace=get_matching_outside_right_brace(express,0);
if ('{'==express[0] && '}'==express[matching_right_brace]) {
if_inside_code_block=express.substr(0,matching_right_brace);
express=express.substr(matching_right_brace+1);
trim(express);
} elseif (INVALID_VALUE!=express.find(';')) {
if_inside_code_block=express.substr(0,express.find(';'));
express=express.substr(express.find(';')+1);
trim(express);
} else {
returnfalse;
}
if (!if_term.empty()) {
if (execute_calculation_term(if_term)) {
unsignedlong term_calcu_result=0;
support_javascript_variant_type term_calcu_result_type=NONE;
get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&term_calcu_result,&term_calcu_result_type);
if (term_calcu_result)
eval(if_inside_code_block);
} else {
returnfalse;
}
} else {
eval(if_inside_code_block);
}
returntrue;
}
booleval_decleare_function(string& express) {
trim(express); // function function_name(function_argment_list) {function_code_block};
express=express.substr(8); // function_name(function_argment_list) {function_code_block};
trim(express);
unsignedlong left_bracket_index=express.find('('),right_bracket_index=express.find(')');
if (INVALID_VALUE!=left_bracket_index && INVALID_VALUE!=right_bracket_index) {
string function_name(express.substr(0,left_bracket_index));
string function_argment(express.substr(left_bracket_index+1,right_bracket_index-left_bracket_index-1));
express=express.substr(right_bracket_index+1); // {function_code_block};
trim(express);
unsignedlong matching_right_brace=get_matching_outside_right_brace(express,0); // all thinks packet success ,just pick these string and call ..
if ('{'==express[0] && '}'==express[matching_right_brace]) {
add_javascript_function("",function_name,function_argment,express.substr(1,matching_right_brace-1));
express=express.substr(matching_right_brace+1);
trim(express);
returntrue;
}
}
returnfalse;
}