java - Validate arithmetical formula -


i need validate formula calculate grade of discipline:

all identifiers (a1, a2,a3,...) has been based on tests, homeworks, etc. created teachers. below example of common formula:

( (a1+a2+a3) / 3) * (b2+b3) 

on case, i'm need validate formula structure, like:

  • non closed parenthesis (done);
  • empty parenthesis groups '()' (done);
  • duplicated operators '(a1++a2)';
  • duplicated distinct operators '(a1 -* a2)';

all identifiers @ formula a1,a1, etc has been informed final user, , doesn't validated.

sample of valid formula:

(((a1+a2+a3)/3)*2) + (((b1+b2+b3)/3)*3) 

sample of invalid formula:

+ (((a1+a2+a3)/3)*2) + (((b1+b2+b3)/3) / 3++) 

regular expressions regular grammars , need context-free grammar parse kind of stuff (or validate). otherwise, apply heuristics...


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -