711 |
711 |
712 // Parse the right operand, |
712 // Parse the right operand, |
713 MustNext (); |
713 MustNext (); |
714 DataBuffer* rb = ParseExprValue (reqtype); |
714 DataBuffer* rb = ParseExprValue (reqtype); |
715 |
715 |
716 // Write to buffer |
716 // Ternary operator requires - naturally - a third operator |
717 retbuf->Merge (rb); |
717 if (oper == OPER_TERNARY) { |
718 long dh = DataHeaderByOperator (NULL, oper); |
718 MustNext (":"); |
719 retbuf->Write<word> (dh); |
719 MustNext (); |
|
720 DataBuffer* tb = ParseExprValue (reqtype); |
|
721 |
|
722 // It also is handled differently: there isn't a dataheader for ternary |
|
723 // operator. Instead, we abuse PUSHNUMBER and IFNOTGOTO for this. |
|
724 int mark1 = retbuf->AddMark (""); // start of "else" case |
|
725 int mark2 = retbuf->AddMark (""); // end of expression |
|
726 retbuf->Write<word> (DH_IFNOTGOTO); |
|
727 retbuf->AddMarkReference (mark1); |
|
728 retbuf->Merge (rb); |
|
729 retbuf->Write<word> (DH_GOTO); |
|
730 retbuf->AddMarkReference (mark2); |
|
731 retbuf->MoveMark (mark1); // start of "else" case |
|
732 retbuf->Merge (tb); |
|
733 retbuf->Write<word> (DH_GOTO); |
|
734 retbuf->AddMarkReference (mark2); |
|
735 retbuf->MoveMark (mark2); // move endmark to end |
|
736 } else { |
|
737 // Write to buffer |
|
738 retbuf->Merge (rb); |
|
739 retbuf->Write<word> (DataHeaderByOperator (NULL, oper)); |
|
740 } |
720 } |
741 } |
721 |
742 |
722 return retbuf; |
743 return retbuf; |
723 } |
744 } |
724 |
745 |
744 !oper.compare ("+") ? OPER_ADD : |
765 !oper.compare ("+") ? OPER_ADD : |
745 !oper.compare ("-") ? OPER_SUBTRACT : |
766 !oper.compare ("-") ? OPER_SUBTRACT : |
746 !oper.compare ("*") ? OPER_MULTIPLY : |
767 !oper.compare ("*") ? OPER_MULTIPLY : |
747 !oper.compare ("/") ? OPER_DIVIDE : |
768 !oper.compare ("/") ? OPER_DIVIDE : |
748 !oper.compare ("%") ? OPER_MODULUS : |
769 !oper.compare ("%") ? OPER_MODULUS : |
|
770 !oper.compare ("?") ? OPER_TERNARY : |
749 -1; |
771 -1; |
750 |
772 |
751 if (o != -1) { |
773 if (o != -1) { |
752 return o; |
774 return o; |
753 } |
775 } |