1Parser biến luật của Lan thành cây, giữ phần trong ngoặc dưới Or để không hiểu nhầm điều kiện. Service lưu cây theo chuỗi luật, tránh dựng lại cho mỗi đơn hàng.The parser builds Lan's rule tree, keeping the parenthesized part under Or to preserve its meaning. The service caches the tree by rule text so each order does not rebuild it.
2Đơn sách 450.000 đồng của khách hạng vàng đến quầy thanh toán. Client đưa facts vào gốc And; cùng một cây có thể kiểm tra nhiều đơn vì dữ liệu nằm ngoài cây.A gold-tier customer checks out with 450,000 VND of books. The client passes facts to the root And; the same tree can check many orders because order data lives outside it.
3And kiểm tra ngưỡng tiền trước: 450000 >= 300000 là true. Nếu vế này sai, && sẽ dừng ngay vì không nhánh nào bên phải có thể cứu điều kiện AND.And checks the spending threshold first: 450000 >= 300000 is true. If it were false, && would stop because no right-hand result could make the AND pass.
4Đã đủ tiền, And gọi Or để kiểm tra nhóm khách được hưởng ưu đãi. Ngoặc trong luật có nghĩa chỉ cần ngành thời trang hoặc hạng vàng, không bắt buộc cả hai.With the total passing, And calls Or to check the qualifying group. The parentheses mean either fashion or gold tier is enough; both are not required.
5Or thử ngành hàng trước: books khác fashion nên lá Equals trả false. Or chưa kết luận thất bại vì nhánh hạng vàng vẫn có thể đúng.Or tries the category first: books differs from fashion, so Equals returns false. Or cannot reject the order yet because the gold-tier branch may still pass.
6Or gọi lá còn lại và nhận true vì khách có tier là gold. Nếu nhánh ngành hàng đã đúng, || sẽ bỏ qua lần gọi này để tránh làm việc thừa.Or calls the remaining leaf and gets true because the customer's tier is gold. Had the category branch passed, || would have skipped this call to avoid unnecessary work.
7Or trả true về And vì false OR true vẫn đúng. And chỉ ghép hai kết quả true AND true; nó không cần biết cách đọc ngành hàng hay hạng khách.Or returns true to And because false OR true is true. And only combines true AND true; it does not need to know how category or tier fields are read.
8Gốc And trả true cho client, nên đơn sách được dùng voucher nhờ hạng vàng. Bản Go chạy y hệt: promo.Parse trả cây And/Or/Equals và rule.Eval(promo.Facts{...}) trả true.The root And returns true to the client, so the book order qualifies through gold tier. Go runs the same way: promo.Parse returns the And/Or/Equals tree and rule.Eval(promo.Facts{...}) returns true.
9Luật khác dùng NOT, như ví dụ trong parser.go: tier == gold OR NOT new == yes. atom() gặp NOT nên tạo Not{Equals(new, yes)}; khi đơn không có new == yes, Equals trả false và Not đảo thành true.Another rule uses NOT, as in parser.go's example: tier == gold OR NOT new == yes. atom() sees NOT and builds Not{Equals(new, yes)}; when the order lacks new == yes, Equals returns false and Not flips it to true.