Menu
  • HOME
  • TAGS

Parsing with MPC library in C returns only first number

c,parsing,rpn

The bnf you are using is the problem : Look at your example (2 2 +) and your entry rule: rpn : '(' <exp> ')' | <number>; 1 - rpn left part is not matched by input : 2 != ( 2 - then number is matched 3 - end...

Pattern is not splitting as desired, fails to split by +

java,regex,rpn

You can use this regex: ((?:\d+(?:\.\d+)?(?:\s+\d+(?:\.\d+)?)*)?\s*[-+*/$£]) RegEx Demo In Java it would be: Pattern pattern = Pattern.compile ( "((?:\\d+(?:\\.\\d+)?(?:\\s+\\d+(?:\\.\\d+)?)*)?\\s*[-+*/$£])" ); ...

Spaces between elements in RPN expression java

java,stringbuilder,rpn

Just change the code that you have commented out, right after Character.isDigit(op) to: int j = i + 1; int oldI = i;//this is so you save the old value for (; j < in.length(); j++) { if (!Character.isDigit(in.charAt(j))) { break; } i++; } out.append(in.substring(oldI, j)); out.append(' '); ...

How to fix this bug in a math expression evaluator

f#,pattern-matching,eval,rpn

Before answering your specific question, did you notice you have another bug? Try eval "2-4" you get 2.0 instead of -2.0. That's probably because along these lines: match op with | Plus -> Num(v + u) | Minus -> Num(v - u) | Star -> Num(v * u) | Slash...

strtok() function with space delimeter

c,strtok,rpn

It's not strtok that reads to the first space, it's scanf: scanf("%s", expression); As soon as scanf sees a space, a TAB, or any other delimiter, it stops reading, and returns the word up to the space. That is why it works when you use a non-blank delimiter. Replace with...

Reverse Polish Notation for array elements. (example: array_name[i,j])

c#,regex,algorithm,stack,rpn

Solved the issue. Here is the algorithm. class InfixToPostfixConverter { private readonly Stack<string> _stack; private readonly string[] _input; private readonly Dictionary<string, int> _priorities; private readonly List<string> _poliz; public InfixToPostfixConverter(string input) { _input = input.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); _stack = new Stack<string>(); _poliz = new List<string>(); _priorities = new Dictionary<string, int>...

C++ Program stuck in a loop

c++,function,loops,rpn

for (p = inform;p++ ; *p) will continue until the next value of p is nullptr, and each round will dereference p and discard the result - you probably meant this the other way around. Similar is this case: for(i=j=0, p = inform;p++,j++;j<len) which will continue running until j++ becomes...