String conversion to a mathematical expression [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I've written an application that converts a string into a mathematical expression for evaluation. This is done by converting the string into postfix and then by constructing an expression tree and solving it.
Now I want to know though, what is the most efficient way to do conversion into postfix?
Sample expression -
(2+(3*4+(4/(3*(4+6))))) or (3+4) or 3+4

I would suggest you consult Sedgewick's Algorithms, 4th ed. The code from the book for converting arithmetic expressions into postfix form is available from the website.

I suppose this question is about the algorithm, BUT - If I would have to something like that I would use something like BOOST::Python to just exec the string as python code and get the result. I like to avoid writing code, If I can..

Related

regex worst possible complexity [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm aware regular expressions, as a concept, represent a single Regular Language, which can be processed via a DFA/NFA with O(n) ~O(2^m) complexity, being n the size of the string and m the size of the regex. Most stack-overflow discussions about the subject quote this awesome article that proves it.
However, regex implemented in modern languages deal with more than regular languages. For instance, it's possible to recognize palindromes with regex, a context-free grammar problem that, when solved via a push-down automata(PDA), is known to have a O(n³) complexity.
I would like to know were exactly in the Extended Chomsky Hierarchy modern (perl or python re, for example) regex implementations fit, or, at least, their worst possible complexity.

regualr expression letters and word match [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
apologies for what is probably a really simple question but I am a complete noob when it come to using regular expressions.
I am trying to create an expression that matches some set criteria together, and although I can find the code to validate these things separately I'm struggling to understand how you put it all together.
What I am looking for is an expression that validates an entered code:
It will always a start with either OR or TR and then you will have 6 digits after that e.g. TR002563
Any help would be greatly appreciated.
Try this regex:
/^(?:O|T)R[0-9]{6}$/
You can use this regex:
/^[OT]R[0-9]{6}$/

Interpret single line basic scripting code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I've a very big file containing the following data structure, it's a very basic scripting language and I can't get to find a way to interpret or get complete structures for it.
Here's what the structure looks like:
# GAME MAP
00-01: Content={3555}
00-00: Content={1000, 1001, 1002 String="Some text.", 1003, 1004}
01-00: Content={1006, 1005 Amount=5}
02-00: Refresh, Content={1001, 1555 Content={1200, 1001 String="Text"}}
The structure is as follows:
BYTE-BYTE: Data, Content={OBJECT DATA}
OBJECT DATA Can contain other OBJECT DATA which is defined with "Content={}" as seen above, any ideas what can I do to interpret this? Doesn't matter the language I just need to see a way for it. (C# or C++ preferably).
Parenthesized (nested) structure need a grammar to be parsed, a regular expression is not sufficient. (Theorically if you know in advance the max depth you could solve your problem with a regex but it would be quite complicated). Antlr or javaCC (Java) allow you to write parser that can do it.

Format a C++ string with template [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the best way to transform a string with a special template, like a sed unix transform.
i must to do this with QT c++ :
original string : 00048500854006F85FF4B0
before c++ transform : 48500854006F85FF4B
Eliminate all the 0 in the start and the end of my string (not in the middle).
maybe a solution with sprintf ?
thank you very much for your help.
It's possible to do using regular expression:
QString("00048500854006F85FF4B0").remove(QRegExp("(^(0)+)|((0)+$)"));
You can always use the power of sed by calling system ("sed 's/foo/bar/' file"); or by using the Qt QProcess. In that case see this and this

Convert string to mathematical evaluation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Okay, so what I want to do is to use a string as input (for instance "16*12+25"), convert it to a mathematical evaluation that the computer can comprehend and return the evaluated value. I could probably write this myself, but it would most likely take quite a while and in the end, it still wouldn't end up as good as I'd like it to unless I want to put even more time into it.
So my question is, is there any script, library or api that you know can do this for C++? I have found some for both java, python and .NET. But I am not working with any of these languages and I would like to remain within C++ for as long (hopefully throughout the entire project) as possible. Do you have any good ideas or links?
I found what I was looking for! The downloadable source is C++ and a CodeBlocks project. You can find it here: http://www.speqmath.com/tutorials/expression_parser_cpp/index.html
A far more sophisticated expression parser recommended by Jared: http://www.partow.net/programming/exprtk/index.html
There is nothing built into C++ for this; all the expression parsing code belongs in the compiler. You will need to use some external library. A quick Google search brings up muParser which looks pretty reasonable.