Parsing boolean expression without left hand recursion

前端 未结 1 1329
抹茶落季
抹茶落季 2021-02-16 00:06

I\'m trying to match this

f(some_thing) == \'something else\'
  • f(some_thing) is a function call, which is an expression
1条回答
  •  情书的邮戳
    2021-02-16 00:24

    Something like this ought to do it:

    expression
     = bool_expression
    
    bool_expression
     = add_expression "==" bool_expression
     / add_expression "!=" bool_expression
     / add_expression
    
    add_expression
     = mult_expression "+" add_expression
     / mult_expression "-" add_expression
     / mult_expression
    
    mult_expression
     = atom "*" mult_expression
     / atom "/" mult_expression
     / atom
    
    atom
     = function_call 
     / string
     / real_number
     / integer
     / identifier
    
    function_call
     = identifier "(" (expression ("," expression)*)? ")"
    
    string
     = "'" [^']* "'"
    
    identifier
     = [a-zA-Z_]+
    
    integer
     = [0-9]+
    
    real_number
     = integer "." integer?
     / "." integer
    

    0 讨论(0)
提交回复
热议问题