asp.net mvc - Tokenizing a expression string in C# -


i have calculation formula string of form

 string formula = w_tb + min(d_3,a_x) * pow(x,2) 

in above example w_tb, d_3, a_x, x variables. able find list of variables in formula splitting strings using operands delimiter.

but in order assign values variables (value database), first approach replace variable name value of variable database. result in replacing substring of expression string value. eg : if variable x replaced value 1,2 in expression string a_x replaced a_1,2 not required result.

i have list of variables , and complete list of delimiters(operators).

what trying achieve?

i trying following list expression string

list<string>() {"w_tb","+","min","(","d_3",",","a_x",")","*","pow","(","x",",","2",")"} 

is there way achieve task.

i have tried solution mentioned in this answer. tokenizer having string.

what trying called parsing, used compilers.

you can define simple grammar expression , let parser-generator generate parser code you. allows define syntax errors , gives full token list 1 want. example in antlr. have http://www.antlr.org/


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -