@@ -288,7 +288,8 @@ bool _elsif_statement() {
288
288
bool result = false;
289
289
if (_token == KEY_WORD_ELSIF ) {
290
290
_read_token ();
291
- if (_expression ()) {
291
+ _ast * _past = (_ast * ) malloc (sizeof (_ast ));
292
+ if (_expression (_past )) {
292
293
_read_token ();
293
294
if (_token == KEY_WORD_THEN ) {
294
295
_read_token ();
@@ -385,33 +386,51 @@ bool _relation_aux(_ast *_past) {
385
386
if (DEBUG_MODE == true) printf ("_relation_aux() : %s\n" , yytext );
386
387
bool result = false;
387
388
if (_token == DELIMITER_EQUAL ) {
389
+ * _past = _ast_create_operation_node (OPERATION_EQUAL , * _past , NULL );
390
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
388
391
_read_token ();
389
- if (_simple_expression (_past )) {
392
+ if (_simple_expression (_right )) {
393
+ (* _past )-> value .operation .right = * _right ;
390
394
result = true;
391
395
}
392
396
} else if (_token == DELIMITER_DIVIDE_EQUAL ) {
397
+ * _past = _ast_create_operation_node (OPERATION_NOT_EQUAL , * _past , NULL );
398
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
393
399
_read_token ();
394
- if (_simple_expression (_past )) {
400
+ if (_simple_expression (_right )) {
401
+ (* _past )-> value .operation .right = * _right ;
395
402
result = true;
396
403
}
397
404
} else if (_token == DELIMITER_LESS_THAN ) {
405
+ * _past = _ast_create_operation_node (OPERATION_LESS_THAN , * _past , NULL );
406
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
398
407
_read_token ();
399
- if (_simple_expression (_past )) {
408
+ if (_simple_expression (_right )) {
409
+ (* _past )-> value .operation .right = * _right ;
400
410
result = true;
401
411
}
402
412
} else if (_token == DELIMITER_LESS_THAN_EQUAL ) {
413
+ * _past = _ast_create_operation_node (OPERATION_LESS_THAN_EQUAL , * _past , NULL );
414
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
403
415
_read_token ();
404
- if (_simple_expression (_past )) {
416
+ if (_simple_expression (_right )) {
417
+ (* _past )-> value .operation .right = * _right ;
405
418
result = true;
406
419
}
407
420
} else if (_token == DELIMITER_GREATER_THAN ) {
421
+ * _past = _ast_create_operation_node (OPERATION_GREATER_THAN , * _past , NULL );
422
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
408
423
_read_token ();
409
- if (_simple_expression (_past )) {
424
+ if (_simple_expression (_right )) {
425
+ (* _past )-> value .operation .right = * _right ;
410
426
result = true;
411
427
}
412
428
} else if (_token == DELIMITER_GREATER_THAN_EQUAL ) {
429
+ * _past = _ast_create_operation_node (OPERATION_GREATER_THAN_EQUAL , * _past , NULL );
430
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
413
431
_read_token ();
414
- if (_simple_expression (_past )) {
432
+ if (_simple_expression (_right )) {
433
+ (* _past )-> value .operation .right = * _right ;
415
434
result = true;
416
435
}
417
436
} else if (
@@ -457,18 +476,24 @@ bool _simple_expression_aux(_ast *_past) {
457
476
if (DEBUG_MODE == true) printf ("_simple_expression_aux() : %s\n" , yytext );
458
477
bool result = false;
459
478
if (_token == DELIMITER_PLUS ) {
479
+ * _past = _ast_create_operation_node (OPERATION_PLUS , * _past , NULL );
480
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
460
481
_read_token ();
461
- if (_term (_past )) {
482
+ if (_term (_right )) {
462
483
_read_token ();
463
- if (_simple_expression_aux (_past )) {
484
+ if (_simple_expression_aux (_right )) {
485
+ (* _past )-> value .operation .right = * _right ;
464
486
result = true;
465
487
}
466
488
}
467
489
} else if (_token == DELIMITER_DASH ) {
490
+ * _past = _ast_create_operation_node (OPERATION_MINUS , * _past , NULL );
491
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
468
492
_read_token ();
469
- if (_term (_past )) {
493
+ if (_term (_right )) {
470
494
_read_token ();
471
- if (_simple_expression_aux (_past )) {
495
+ if (_simple_expression_aux (_right )) {
496
+ (* _past )-> value .operation .right = * _right ;
472
497
result = true;
473
498
}
474
499
}
@@ -509,18 +534,24 @@ bool _term_aux(_ast *_past) {
509
534
if (DEBUG_MODE == true) printf ("_term_aux() : %s\n" , yytext );
510
535
bool result = false;
511
536
if (_token == DELIMITER_STAR ) {
537
+ * _past = _ast_create_operation_node (OPERATION_MULT , * _past , NULL );
538
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
512
539
_read_token ();
513
- if (_factor (_past )) {
540
+ if (_factor (_right )) {
514
541
_read_token ();
515
- if (_term_aux (_past )) {
542
+ if (_term_aux (_right )) {
543
+ (* _past )-> value .operation .right = * _right ;
516
544
result = true;
517
545
}
518
546
}
519
547
} else if (_token == DELIMITER_SLASH ) {
548
+ * _past = _ast_create_operation_node (OPERATION_DIV , * _past , NULL );
549
+ _ast * _right = (_ast * ) malloc (sizeof (_ast ));
520
550
_read_token ();
521
- if (_factor (_past )) {
551
+ if (_factor (_right )) {
522
552
_read_token ();
523
- if (_term_aux (_past )) {
553
+ if (_term_aux (_right )) {
554
+ (* _past )-> value .operation .right = * _right ;
524
555
result = true;
525
556
}
526
557
}
@@ -565,8 +596,10 @@ bool _primary(_ast *_past) {
565
596
if (DEBUG_MODE == true) printf ("_primary() : %s\n" , yytext );
566
597
bool result = false;
567
598
if (_token == INTEGER_VALUE ) {
599
+ * _past = _ast_create_constant_node (NODE_CONSTANT_INT , atof (yytext ));
568
600
result = true;
569
601
} else if (_token == FLOAT_VALUE ) {
602
+ * _past = _ast_create_constant_node (NODE_CONSTANT_DOUBLE , atof (yytext ));
570
603
result = true;
571
604
} else if (_token == KEY_WORD_NULL ) {
572
605
result = true;
@@ -577,6 +610,8 @@ bool _primary(_ast *_past) {
577
610
_add_semantic_error (NOT_DECLARED , yylineno , yytext );
578
611
} else if (_var_initialized (yytext ) == false) {
579
612
_add_semantic_error (NOT_INITIALIZED , yylineno , yytext );
613
+ } else {
614
+ * _past = _ast_create_variable_node (yytext );
580
615
}
581
616
result = true;
582
617
} else if (_token == DELIMITER_PAR_OPENED ) {
0 commit comments