Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.38/5 (4 votes)
See more:
Dear Sir

i operate this 3(4*2) it shows syntax error and how can i check the user input expression is in correct format.
if i replace ( with '*(' then if i have equation like 3((482/100)*2) create problem please tell me if anyone have solution of it
Posted

Depending on how you are evaluating your expressions - and you don't say so we have to guess - you will either need to rework your parser or actually implement your own. If you are relying on effectively compiling and running expressions in C# to solve this, then you are on a loser from teh start - you can't modify the compiler.

You could however take something like this: A Tiny Expression Evaluator[^] and tweak it to allow your (rather non-standard) input format.

Or just tell your users to add an operator...
 
Share this answer
 
Comments
thatraja 9-Oct-13 9:13am    
Nice utility(article), 5!
Replace only a sequence of a digit following '(' with "*("
This way 3((482/100)*2) will become 3*((482/100)*2)
[instead of 3*(*(482/100)*2)]

Best, H
 
Share this answer
 
Comments
rajbir singh thind 9-Oct-13 5:09am    
but if i have(3((482/100)*2) then it becomes *3*((482/100)*2) then
Herbisaurus 9-Oct-13 9:28am    
no, it doesn't, the most left '*' will not be inserted.
ONLY a sequence of a digit following a '(', and the only occurance in your string is "3(" will be replaced with "3*(" i.e. a '*' inserted in the middle of that digit and the '('.

if you need code for that let me know...
Before you parse the grammar, I suggest you to make it more regular, for instance making the multiplicative operator '*' mandatory.
Once you have a good grammar then you may find several options for building the actual parser (you may find ready-to-use one, use a tool, embed a script language in your application).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900