Can RPN (Reverse Polish Notation) or Postfix Notation be derived by Regular Expression

1.6k views Asked by At

I was wondering if I can define a Regular Expression to check whether a given input matches the RPN expression , i.e. whether the given input is valuid or not?

I am not very familiar with Regex unfortunately, so I was wondering if it is possible to define a regular expression to validate the input for postfix.

Many thanks Taz

1

There are 1 answers

1
Scott Hunter On

Formally, no; RPN would require a context-free grammar, which regular expressions cannot express. However, it might be possible to do so with a "regular expression" package or library, since they can contain features that are outside of the formal definition of regular expressions.