LLogicStitch
Workflows

Coding workflows · Flat boolean precedence

03
Built around your work

A concrete starting point

Evaluate a flat sequence of boolean values joined by AND and OR with AND taking precedence. Check True OR False AND False and reject empty input, misplaced operators, parentheses or non-boolean operands without executing strings.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Flat boolean precedence

A concrete starting point
def evaluate_flat(tokens):
    if not tokens or len(tokens) % 2 == 0:
        raise ValueError("logic.shape")
    if any(type(x) is not bool for x in tokens[::2]):
        raise ValueError("logic.value")
    if any(x not in ("AND", "OR") for x in tokens[1::2]):
        raise ValueError("logic.operator")
    terms, term = [], tokens[0]
    for i in range(1, len(tokens), 2):
        if tokens[i] == "AND":
            term = term and tokens[i + 1]
        else:
            terms.append(term)
            term = tokens[i + 1]
    return any([*terms, term])

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗