Parsing Grammar


  • 1
    M

    After doing some research on this problem, I realized that using parsing grammar would be good way to go. It might lead to some more readable code. Here is what I got. Hope it will clarify some ambiguity in this problem. Please let me know if you find any mistake.

    Num => \s+ StrippedNum \s+
    StrippedNum => Double ('e' | 'E') Int | Double
    Double => Int '.' UnsignedInt | Int '.' | '.' UnsignedInt | ('+' | '-') '.' UnsignedInt | Int
    Int => ('+' | '-') UnsignedInt | UnsignedInt  
    UnsignedInt => [0-9]+;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.