• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂586efdb424a2688ab0dfd47709bc0f10b3cdfbb6 (tree)
時間2018-11-17 23:28:20
作者dhrname <dhrname@user...>
Commiterdhrname

Log Message

Modify the ST_parse

Change Summary

差異

--- a/source_code/shadowstar.c
+++ b/source_code/shadowstar.c
@@ -419,6 +419,7 @@ static inline void free_stacklist (ST_Stack_List s)
419419 }
420420
421421 /*ST_parse関数
422+ * N-木のfreetreeは、後でfreenode関数で解放するためのもの
422423 * トークン配列arrayでパーサ解析
423424 * 連結リストのlistは束縛変数の値を格納している
424425 * 返り値はパースされたノードリスト
@@ -431,7 +432,7 @@ static inline void free_stacklist (ST_Stack_List s)
431432 * 2, y x.xλ
432433 * 3, 「y x」(x)
433434 * 4,「yをx」(x)*/
434-ST_Node ST_parse(ST_Token_Mode *array, size_t length, ST_Ordered_Pair *list)
435+ST_Node ST_parse(ST_Node freetree, ST_Token_Mode *array, size_t length, ST_Ordered_Pair *list)
435436 {
436437 if (ST_isEmpty(list))
437438 {
@@ -473,7 +474,10 @@ ST_Node ST_parse(ST_Token_Mode *array, size_t length, ST_Ordered_Pair *list)
473474 ST_Node seq = ST_EMPTY_NODE;
474475
475476 /*変数seqが空ノードに初期化されるので、この変数にキャッシュしておく*/
476- ST_Node seq_cache = ST_createNode(ST_EMPTY_NODE);
477+ ST_Node seq_cache = ST_createNode(freetree);
478+
479+ /*返り値となるルート*/
480+ ST_Node root = seq_cache;
477481
478482 for (int_fast32_t i=length-1; i>=0; i--)
479483 {
@@ -499,7 +503,7 @@ ST_Node ST_parse(ST_Token_Mode *array, size_t length, ST_Ordered_Pair *list)
499503 case ST_KAGIKAKKO_END_TOKEN:
500504 /*新しく子ノードとして追加したものの末子ノードが現在ノードになる
501505 *その現在ノードをseq_cacheに入れる*/
502- seq_cache = ST_insertBefore(ST_getParentNode(seq), ST_createNode(ST_EMPTY_NODE), seq);
506+ seq_cache = ST_insertBefore(seq_cache, ST_createNode(ST_EMPTY_NODE), seq);
503507 seq = ST_EMPTY_NODE;
504508 break;
505509 case ST_KAGIKAKKO_BEGIN_TOKEN:
@@ -513,8 +517,15 @@ ST_Node ST_parse(ST_Token_Mode *array, size_t length, ST_Ordered_Pair *list)
513517 }
514518 }
515519 free_stacklist(bound_vstacklist);
516-
517- return seq;
520+
521+ if (ST_isEmptyNode(seq))
522+ {
523+ return ST_EMPTY_NODE;
524+ }
525+ else
526+ {
527+ return root;
528+ }
518529 }
519530
520531 /*ST_eval 関数
--- a/source_code/shadowstar.h
+++ b/source_code/shadowstar.h
@@ -28,7 +28,7 @@ ST_Ordered_Pair* ST_tokenize(ST_Char*, ST_Token_Mode*);
2828 /*ST_parse関数
2929 * トークン配列からパーサを作る
3030 * 返却値は解析リスト*/
31-ST_Node ST_parse(ST_Token_Mode*, size_t, ST_Ordered_Pair*);
31+ST_Node ST_parse(ST_Node, ST_Token_Mode*, size_t, ST_Ordered_Pair*);
3232
3333 /*ベータ簡約を用いて、解析リストの評価を行う*/
3434 ST_Node ST_eval(ST_Ordered_Pair*, ST_Node);
Binary files a/source_code/shadowstar.o and b/source_code/shadowstar.o differ
--- a/source_code/startest.c
+++ b/source_code/startest.c
@@ -277,24 +277,26 @@ int main(int argc, char **argv)
277277
278278 init_token(tokens);
279279 length = sizeof(tokens)/sizeof(tokens[0]);
280- ST_parse(tokens, length, ST_EMPTY);
281- assert(ST_isEmptyNode(ST_parse(tokens, length, ST_EMPTY)));
280+ /*解放用のツリー*/
281+ ST_Node freetree = ST_createNode(ST_EMPTY_NODE);
282+ ST_parse(freetree, tokens, length, ST_EMPTY);
283+ assert(ST_isEmptyNode(ST_parse(freetree, tokens, length, ST_EMPTY)));
282284 varlist = ST_tokenize(u8"aBa愛", tokens);
283- assert(ST_isEmptyNode(ST_parse(tokens, length, varlist)));
285+ assert(ST_isEmptyNode(ST_parse(freetree, tokens, length, varlist)));
284286 ST_freelist(varlist);
285287 init_token(tokens1);
286288 length = sizeof(tokens1)/sizeof(tokens1[0]);
287- ST_parse(tokens1, length, ST_EMPTY);
288- assert(ST_isEmptyNode(ST_parse(tokens1, length, ST_EMPTY)));
289+ ST_parse(freetree, tokens1, length, ST_EMPTY);
290+ assert(ST_isEmptyNode(ST_parse(freetree, tokens1, length, ST_EMPTY)));
289291 varlist = ST_tokenize(u8"aBa愛", tokens1);
290- assert(ST_isEmptyNode(ST_parse(tokens1, length, varlist)));
292+ assert(ST_isEmptyNode(ST_parse(freetree, tokens1, length, varlist)));
291293 ST_freelist(varlist);
292294
293295 ST_Token_Mode tokens2[7] = {0};
294296 init_token(tokens2);
295297 length = sizeof(tokens2) / sizeof(tokens2[0]);
296298 varlist = ST_tokenize(u8"(愛あ)(愛)", tokens2);
297- assert(ST_isEmptyNode(ST_parse(tokens2, length, varlist)));
299+ assert(ST_isEmptyNode(ST_parse(freetree, tokens2, length, varlist)));
298300 assert(ST_first(ST_second(varlist)) != ST_first(varlist));
299301 ST_freelist(varlist);
300302 init_token(tokens2);
@@ -303,23 +305,23 @@ int main(int argc, char **argv)
303305 tokens2[5] = 0;
304306 tokens2[6] = 0;
305307 varlist = ST_tokenize(u8"「愛あ」(愛)", tokens2);
306- assert(!ST_isEmptyNode(ST_parse(tokens2, length, varlist)));
308+ assert(!ST_isEmptyNode(ST_parse(freetree, tokens2, length, varlist)));
307309 assert(ST_first(ST_second(varlist)) == ST_first(varlist));
308310 ST_freelist(varlist);
309- /*
311+
310312 ST_Token_Mode tokens3[12] = {0};
311313 length = sizeof(tokens3) / sizeof(tokens3[0]);
312314 varlist = ST_tokenize(u8"「愛「愛」(愛)」(愛)", tokens3);
313- assert(!ST_isEmptyNode(ST_parse(tokens3, length, varlist)));
315+ assert(!ST_isEmptyNode(ST_parse(freetree, tokens3, length, varlist)));
314316 assert(ST_first(ST_second(varlist)) != ST_first(varlist));
315317 assert(ST_getItem(varlist, 1) != ST_first(varlist));
316318 assert(ST_getItem(varlist, 0) == ST_first(varlist));
317319 ST_freelist(varlist);
318-
320+ /*
319321 ST_Token_Mode tokens4[12] = {0};
320322 length = sizeof(tokens4) / sizeof(tokens4[0]);
321323 varlist = ST_tokenize(u8"「愛」(愛)「愛」(愛)", tokens4);
322- assert(!ST_isEmptyNode(ST_parse(tokens4, length, varlist)));
324+ assert(!ST_isEmptyNode(ST_parse(freetree, tokens4, length, varlist)));
323325 assert(ST_first(ST_second(varlist)) == ST_first(varlist));
324326 assert(ST_getItem(varlist, 2) != ST_first(varlist));
325327 assert(ST_getItem(varlist, 3) != ST_first(varlist));
@@ -330,7 +332,7 @@ int main(int argc, char **argv)
330332 ST_Token_Mode tokens5[12] = {0};
331333 length = sizeof(tokens5) / sizeof(tokens5[0]);
332334 varlist = ST_tokenize(u8"「謎」(謎)「愛」(愛)", tokens5);
333- assert(!ST_isEmptyNode(ST_parse(tokens5, length, varlist)));
335+ assert(!ST_isEmptyNode(ST_parse(freetree, tokens5, length, varlist)));
334336 assert(ST_first(ST_second(varlist)) == ST_first(varlist));
335337 assert(ST_getItem(varlist, 2) != ST_first(varlist));
336338 assert(ST_getItem(varlist, 3) != ST_first(varlist));
@@ -340,7 +342,7 @@ int main(int argc, char **argv)
340342
341343 init_token_length(tokens5, length);
342344 varlist = ST_tokenize(u8"謎は「愛を愛する」(愛)", tokens5);
343- ST_Node btr = ST_parse(tokens5, length, varlist);
345+ ST_Node btr = ST_parse(freetree, tokens5, length, varlist);
344346 assert( ST_isEmpty(ST_getPreviousNode(ST_getPreviousNode(btr))) );
345347 assert( ST_isEmpty(ST_getPreviousNode(ST_getPreviousNode(ST_getLastChild(btr)))) );
346348 assert( ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0));
@@ -352,7 +354,7 @@ int main(int argc, char **argv)
352354
353355 init_token_length(tokens5, length);
354356 varlist = ST_tokenize(u8"「謎」(謎)「愛」(愛)", tokens5);
355- btr = ST_parse(tokens5, length, varlist);
357+ btr = ST_parse(freetree, tokens5, length, varlist);
356358 assert( ST_isEmpty(ST_getPreviousNode(ST_getPreviousNode(btr))) );
357359 assert( ST_isEmpty(ST_getPreviousNode(ST_getLastChild(btr))) );
358360 assert( ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0));
@@ -370,7 +372,7 @@ int main(int argc, char **argv)
370372
371373 init_token_length(tokens5, length);
372374 varlist = ST_tokenize(u8"「「謎」(謎)愛」(愛)", tokens5);
373- btr = ST_parse(tokens5, length, varlist);
375+ btr = ST_parse(freetree, tokens5, length, varlist);
374376 assert( ST_isEmpty(ST_getPreviousNode(btr)) );
375377 assert( ST_isEmpty(ST_getPreviousNode(ST_getPreviousNode(ST_getLastChild(btr)))) );
376378 assert( ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0));
@@ -385,7 +387,7 @@ int main(int argc, char **argv)
385387
386388 init_token_length(tokens5, length);
387389 varlist = ST_tokenize(u8"「涙を思考する言葉」(世界)", tokens5);
388- btr = ST_parse(tokens5, length, varlist);
390+ btr = ST_parse(freetree, tokens5, length, varlist);
389391 assert(ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
390392 lastvar = ST_getLastChild(btr);
391393 assert( ST_first(ST_getNodeValue(lastvar)) == ST_getItem(varlist, 1) );
@@ -399,7 +401,7 @@ int main(int argc, char **argv)
399401 ST_Token_Mode tokens6[24] = {0};
400402 length = sizeof(tokens6) / sizeof(tokens6[0]);
401403 varlist = ST_tokenize(u8"「言葉」(世界)「「涙」(謎)愛」(謎)", tokens6);
402- btr = ST_parse(tokens6, length, varlist);
404+ btr = ST_parse(freetree, tokens6, length, varlist);
403405 assert( ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
404406 assert( ST_getBoundVariable(ST_getNodeValue(ST_setChurchNumber(1, ST_getPreviousNode, btr))) == ST_getItem(varlist, 4) );
405407 lastvar = ST_getLastChild(btr);
@@ -415,7 +417,7 @@ int main(int argc, char **argv)
415417
416418 init_token_length(tokens6, length);
417419 varlist = ST_tokenize(u8"「言葉」(半角括弧)「「涙」(謎)愛」(謎)", tokens6);
418- btr = ST_parse(tokens6, length, varlist);
420+ btr = ST_parse(freetree, tokens6, length, varlist);
419421 assert(ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
420422 assert(ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(ST_getLastChild(btr)))) == ST_getItem(varlist, 2) );
421423 assert(ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(btr))) == ST_getItem(varlist, 4) );
@@ -424,7 +426,7 @@ int main(int argc, char **argv)
424426
425427 init_token_length(tokens6, length);
426428 varlist = ST_tokenize(u8"「「涙」(謎)言葉」(世界)「愛」(謎)", tokens6);
427- btr = ST_parse(tokens6, length, varlist);
429+ btr = ST_parse(freetree, tokens6, length, varlist);
428430 assert(ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
429431 assert(ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(btr))) == ST_getItem(varlist, 2) );
430432 assert(ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(ST_getLastChild(ST_getPreviousNode(btr))))) == ST_getItem(varlist, 4) );
@@ -439,7 +441,7 @@ int main(int argc, char **argv)
439441
440442 init_token_length(tokens6, length);
441443 varlist = ST_tokenize(u8"「「「涙」(謎)言葉」(世界)愛」(謎)", tokens6);
442- btr = ST_parse(tokens6, length, varlist);
444+ btr = ST_parse(freetree, tokens6, length, varlist);
443445 assert( ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
444446 lastvar = ST_getLastChild(btr);
445447 assert( ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(lastvar))) == ST_getItem(varlist, 2) );
@@ -452,7 +454,7 @@ int main(int argc, char **argv)
452454
453455 init_token_length(tokens6, length);
454456 varlist = ST_tokenize(u8"「「涙」(謎)「言葉」(世界)愛」(謎)", tokens6);
455- btr = ST_parse(tokens6, length, varlist);
457+ btr = ST_parse(freetree, tokens6, length, varlist);
456458 assert(ST_getBoundVariable(ST_getNodeValue(btr)) == ST_getItem(varlist, 0) );
457459 lastvar = ST_getLastChild(btr);
458460 assert(ST_getBoundVariable(ST_getNodeValue(ST_getPreviousNode(lastvar))) == ST_getItem(varlist, 2) );
@@ -467,7 +469,7 @@ int main(int argc, char **argv)
467469 length = sizeof(tokens2) / sizeof(tokens2[0]);
468470 init_token_length(tokens2, length);
469471 varlist = ST_tokenize(u8"「涙」(謎)", tokens2);
470- btr = ST_parse(tokens2, length, varlist);
472+ btr = ST_parse(freetree, tokens2, length, varlist);
471473 ST_Node evalresult = ST_eval(varlist, btr);
472474 assert(btr != evalresult);
473475 assert( ST_getBoundVariable(ST_getNodeValue(evalresult)) == ST_getItem(varlist, 0) );
@@ -480,7 +482,7 @@ int main(int argc, char **argv)
480482 length = sizeof(tokens6) / sizeof(tokens6[0]);
481483 init_token_length(tokens6, length);
482484 varlist = ST_tokenize(u8"「海」(愛)とは、「涙」(謎)", tokens6);
483- btr = ST_parse(tokens6, length, varlist);
485+ btr = ST_parse(freetree, tokens6, length, varlist);
484486 evalresult = ST_eval(varlist, btr);
485487 assert( ST_getBoundVariable(ST_getNodeValue(evalresult)) == ST_getItem(varlist, 0) );
486488 assert( ST_first(ST_getNodeValue(ST_getLastChild(evalresult))) == ST_getItem(varlist, 1) );
@@ -494,7 +496,7 @@ int main(int argc, char **argv)
494496
495497 init_token_length(tokens6, length);
496498 varlist = ST_tokenize(u8"「海」(愛)とは、「謎」(謎)", tokens6);
497- btr = ST_parse(tokens6, length, varlist);
499+ btr = ST_parse(freetree, tokens6, length, varlist);
498500 evalresult = ST_eval(varlist, btr);
499501 assert( ST_getBoundVariable(ST_getNodeValue(evalresult)) == ST_getItem(varlist, 2) );
500502 assert( ST_first(ST_getNodeValue(ST_getLastChild(evalresult))) == ST_getItem(varlist, 3) );
Binary files a/source_code/startest.o and b/source_code/startest.o differ