if_statement(KurumiNumber stop_p) { next(); if_statement_count += 1; rexpr(); next(); KurumiNumber next_p = new KurumiNumber(-1); expression.add(new KurumiCommand(KurumiCommandType.JMPIN)); expression.add(next_p); bool additional_branching = false; KurumiToken current = get_current_token(); while (current != null) { KurumiKeyword kw = current.is_keyword(); if (kw == KurumiKeyword.END) { int end_position = expression.size(); stop_p.number = end_position; if (!additional_branching) { next_p.number = end_position; } break; } else if (kw == KurumiKeyword.ELSE) { additional_branching = true; expression.add(new KurumiCommand(KurumiCommandType.JMP)); expression.add(stop_p); next_p.number = expression.size(); next(); } else if (kw == KurumiKeyword.ELIF) { additional_branching = true; expression.add(new KurumiCommand(KurumiCommandType.JMP)); expression.add(stop_p); next_p.number = expression.size(); if_statement(stop_p); break; } else { lexpr(); } current = get_current_token(); } next(); if_statement_count -= 1; }
lexpr() { KurumiToken current = get_current_token(); switch (current.type) { case TokenType.Identifier: KurumiKeyword keyword = current.is_keyword(); if (keyword == KurumiKeyword.UNKNOWN) { KurumiToken n = get_current_token(1); if (n == null) { return; } OperatorType type = n.to_operator_type(); if (type == OperatorType.COLON) { KurumiNumber number = goto_storage.get(current.data); number.number = expression.size(); next(); next(); } else if (type == OperatorType.LBRACKET) { function_call(current, 0); } else { rexpr(); } } else { keyword_expression(keyword); } break; case TokenType.Operator: next(); return; default: throw new Exception("Identifier or Keyword is expected in the left-sided expression."); } }
rexpr() { KurumiToken current = get_current_token(); while (current != null) { OperatorType type = current.to_operator_type(); bool v1 = current.type == TokenType.Operator && (type == OperatorType.ENDLINE || type == OperatorType.COLON); bool v2 = current.is_keyword() == KurumiKeyword.END; if (v1 || v2) { break; } int assigment_count = 0; assign_expr(ref assigment_count); current = get_current_token(); } }