根据Python语法编写Matlab语法

时间:2019-07-08 13:37:00

标签: python matlab grammar

我正在尝试编写Matlab语法,并且从Python的语法中得到启发。

但是我对此有一些疑问:

1。

b.rule(M_EXPR).is(FACTOR, b.zeroOrMore(b.firstOf("*", "//", "/", "%", "@"), FACTOR)).skipIfOneChild();//M for multiplicative operator
b.rule(A_EXPR).is(M_EXPR, b.zeroOrMore(b.firstOf("+", "-"), M_EXPR)).skipIfOneChild();//A for additive operator

b.rule(SHIFT_EXPR).is(A_EXPR, b.zeroOrMore(b.firstOf("<<", ">>"), A_EXPR)).skipIfOneChild();
b.rule(AND_EXPR).is(SHIFT_EXPR, b.zeroOrMore("&", SHIFT_EXPR)).skipIfOneChild();
b.rule(XOR_EXPR).is(AND_EXPR, b.zeroOrMore("^", AND_EXPR)).skipIfOneChild();
b.rule(OR_EXPR).is(XOR_EXPR, b.zeroOrMore("|", XOR_EXPR)).skipIfOneChild(); //bitwise operations : voir https://www.tutorialspoint.com/python/bitwise_operators_example.htm


b.rule(COMPARISON).is(OR_EXPR, b.zeroOrMore(COMP_OPERATOR, OR_EXPR)).skipIfOneChild();
b.rule(COMP_OPERATOR).is(b.firstOf(
  "<",
  ">",
  "==",
  ">=",
  "<=",
  "!=",
  "<>",
  b.sequence("is", b.optional("not")),
  b.sequence(b.optional("not"), "in"))); //is and is not compare object identities (true or false if the same object)

b.rule(OR_TEST).is(AND_TEST, b.zeroOrMore("or", AND_TEST)).skipIfOneChild();
b.rule(AND_TEST).is(NOT_TEST, b.zeroOrMore("and", NOT_TEST)).skipIfOneChild();
b.rule(NOT_TEST).is(b.firstOf(COMPARISON, b.sequence("not", NOT_TEST))).skipIfOneChild(); //boolean operations

您可以在此处看到布尔运算链接到按位运算。但是Matlab中的按位运算被定义为函数(https://fr.mathworks.com/help/matlab/bit-wise-operations.html)。您对我在语法定义中可以使用它们有什么想法?

编辑:这是我为第一个所做的。我还不知道是否行得通。

    b.rule(M_EXPR).is(FACTOR, b.zeroOrMore(b.firstOf("*", "//", "/", "%", "@"), FACTOR)).skipIfOneChild();//M for multiplicative operator
    b.rule(A_EXPR).is(M_EXPR, b.zeroOrMore(b.firstOf("+", "-"), M_EXPR)).skipIfOneChild();//A for additive operator

    b.rule(COMPARISON).is(A_EXPR, b.zeroOrMore(COMP_OPERATOR, A_EXPR)).skipIfOneChild();
    b.rule(COMP_OPERATOR).is(b.firstOf(
            "<",
            ">",
            "==",
            ">=",
            "<=",
            "~="));

    b.rule(OR_TEST).is(AND_TEST, b.zeroOrMore(OR, AND_TEST)).skipIfOneChild();
    b.rule(AND_TEST).is(NOT_TEST, b.zeroOrMore(AND, NOT_TEST)).skipIfOneChild();
    b.rule(NOT_TEST).is(b.firstOf(COMPARISON, b.sequence(TILDE, NOT_TEST))).skipIfOneChild();  //boolean operations

希望您能帮助我:)

0 个答案:

没有答案