注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
写AST, follow up是如何处理 viriable
// A Boolean Formula (aka Boolean Expression) is a logical statement that evaluates to either "true" or "false". You are given a static representation, more specifically a simplified Abstract Syntax Tree (AST) representing our version of boolean formulas.
// For example, the following formula: "true OR false" // Represented by the following AST: // OR // /
// true false
// The example formula would evaluate to "true".
// Use obfuscated names and write the code on one line. You can assume for now that the AST is well-formed and valid.
// Your task is to implement an evaluator that can compute the result of a given boolean formula.
import java.util.*;
public class Solution { public stat(
BinaryOp.AND,
new Boolean(true),
new Number(0)
);
Formula example4 = new RelationalOp(
RelationalOp.LESS_THAN,
new Number(1),
new Boolean(true)
);
System.out.println("example1 " + evaluateFormula(example)); // true
System.out.println("example2 " + evaluateFormula(example2)); // true
System.out.println("example3 " + evaluateFormula(example3) + " expected false");
System.out.println("example4 " + evaluateFormula(example4) + " expected false");
} } |