MCPcopy Create free account
hub / github.com/ChiyukiGana/Quickinput / infixToPostfix

Method infixToPostfix

source/src/scriptinterpreter.h:343–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341 else if (op == "==" || op == "!=" || op == ">" || op == "<" || op == ">=" || op == "<=")
342 prec = 1;
343 else if (op == "||" || op == "&&")
344 prec = 0;
345
346 tokens.emplace_back(OPERATOR, op, prec);
347 pos++;
348 }
349 // Parentheses
350 else if (c == '(' || c == ')')
351 {
352 tokens.emplace_back(PAREN, std::string(1, c));
353 pos++;
354 }
355 // Args
356 else if (c == ',')
357 {
358 tokens.emplace_back(ARG_SEPARATOR, ",");
359 pos++;
360 }
361 else throw ScriptException(ScriptException::error_invalid_character, {}, std::string(1, c));
362 }
363 return tokens;
364 }
365 auto infixToPostfix(const std::vector<Token>& tokens) -> std::vector<Token>
366 {
367 std::vector<Token> output;
368 std::vector<Token> opStack;
369
370 for (const auto& token : tokens)
371 {
372 if (token.type == VARIABLE || token.type == NULLOPT || token.type == NUMBER || token.type == STRING || token.type == TRUE_ || token.type == FALSE_)
373 {
374 output.push_back(token);
375 }
376 else if (token.type == PAREN)
377 {
378 if (token.value == "(")
379 {
380 opStack.push_back(token);
381 }
382 else
383 {
384 while (!opStack.empty() && opStack.back().value != "(")
385 {
386 output.push_back(opStack.back());
387 opStack.pop_back();
388 }
389 if (!opStack.empty())
390 {
391 opStack.pop_back();
392 if (!opStack.empty() && opStack.back().type == FUNCTION)
393 {
394 output.push_back(opStack.back());
395 opStack.pop_back();
396 }
397 }
398 }
399 }
400 else if (token.type == OPERATOR)

Callers

nothing calls this directly

Calls 1

backMethod · 0.80

Tested by

no test coverage detected