-2

I need validate a formula to calculate the grade of discipline:

All identifiers (A1, A2,A3,...) has been based on tests, homeworks, etc. created by teachers. Below an example of a common formula:

( (A1+A2+A3) / 3) * (B2+B3)

On this case, I'm just need validate the formula structure, like:

  • Non closed parenthesis (done);
  • Empty parenthesis groups '()' (done);
  • Duplicated operators like '(A1++A2)';
  • Duplicated distinct operators like '(A1 -* A2)';

All identifiers at formula like A1,A1, etc has been informed by final user, and 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++)
4

1 回答 1

2

regular expressions are regular grammars and you need a context-free grammar to parse this kind of stuff (or validate). otherwise, you only apply heuristics...

于 2013-04-25T13:59:32.600 回答