Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

rpn

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

like image 587
user1136639 Avatar asked Jan 08 '12 02:01

user1136639


People also ask

Which expressions are also regarded as Reverse Polish Notation RPN?

Postfix expressions also regarded as Reverse Polish Notations - Data Structure.

Is Reverse Polish Notation same as postfix?

Reverse Polish notation (RPN), also known as reverse Łukasiewicz notation, Polish postfix notation or simply postfix notation, is a mathematical notation in which operators follow their operands, in contrast to Polish notation (PN), in which operators precede their operands.

Why is reverse Polish notation RPN used to carry out the evaluation of expressions?

Reverse Polish notation (RPN) is a method for conveying mathematical expressions without the use of separators such as brackets and parentheses. In this notation, the operators follow their operands, hence removing the need for brackets to define evaluation priority.


1 Answers

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.

like image 104
Scott Hunter Avatar answered Nov 15 '22 13:11

Scott Hunter