Click here to Skip to main content
15,884,986 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Retrieve HWND of a control that has focus Pin
_Flaviu13-Aug-18 0:09
_Flaviu13-Aug-18 0:09 
GeneralRe: Retrieve HWND of a control that has focus Pin
Randor 13-Aug-18 1:51
professional Randor 13-Aug-18 1:51 
GeneralRe: Retrieve HWND of a control that has focus Pin
leon de boer12-Aug-18 3:47
leon de boer12-Aug-18 3:47 
QuestionWhat is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien9-Aug-18 9:09
Maximilien9-Aug-18 9:09 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
David Crow9-Aug-18 9:47
David Crow9-Aug-18 9:47 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien9-Aug-18 12:06
Maximilien9-Aug-18 12:06 
GeneralRe: What is the magic incantation to select a row in a CListCtrl in report mode ? Pin
Maximilien21-Aug-18 5:11
Maximilien21-Aug-18 5:11 
Questionhow to use recursive descent algorithm to compute an arithmetical expression? Pin
tony_ming8-Aug-18 20:42
tony_ming8-Aug-18 20:42 
I want to use recursive descent algorithm to compute an arithmetical expression, but I can't get the right value,so please tell me how to write the code
here is my grammar
C++
E→E+T|E-T|T
T→T*F| T/F|F
F→(E)|i


the following is my code
C++
<pre>
#include<stdio.h>    
#include<string> 
 using namespace std;
 int pos = 0;
 string str = "1+2*3-4";
 double E();
 double T();
 double F();

int main() {
	double v = E();
	printf("%f", v);
	getchar();
	return 0;
}

double E() {
	double v = 0;
	char c = str.at(pos);
	if (c == '+') {
		pos++;
		v = E() + T();
	}
	else if (c == '-') {
		pos++;
		v = E() - T();
	}
	else {
		pos++;
		v = T();
	}
	return v;
}

 double T() {
	double v = 0;
	char c = str.at(pos);
	if (c == '*') {
		pos++;
		v = T() * F();
	}
	else if (c == '/') {
		pos++;
		v = T() / F();
	}
	else {
		pos++;
		v = F();
	}
	return v;
}

 double F() {
	char c = str.at(pos);
	if (c == '(') {
		pos++;
		double v = E();
		c = str.at(pos);
		if (c == ')') {
			pos++;
			return v;
		}
	}
	else {
		string s = "";
		while (true) {
			c = str.at(pos);
			if (c >= '0' && c <= '9') {
				s += c;
				pos++;
			}
			else {
				break;
			}
		}

		return atoi(s.c_str());
	}
	return 0;
}



modified 9-Aug-18 2:57am.

AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
Richard MacCutchan8-Aug-18 20:50
mveRichard MacCutchan8-Aug-18 20:50 
AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
Stefan_Lang8-Aug-18 22:07
Stefan_Lang8-Aug-18 22:07 
QuestionRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
David Crow9-Aug-18 4:55
David Crow9-Aug-18 4:55 
AnswerRe: how to use recursive descent algorithm to compute an arithmetical expression? Pin
CPallini9-Aug-18 10:38
mveCPallini9-Aug-18 10:38 
QuestionMovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5797-Aug-18 20:19
Sampath5797-Aug-18 20:19 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt7-Aug-18 21:52
professionalJochen Arndt7-Aug-18 21:52 
GeneralRe: MovePrev() throwing -2147217837 error code Pin
Sampath5797-Aug-18 22:23
Sampath5797-Aug-18 22:23 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt7-Aug-18 23:26
professionalJochen Arndt7-Aug-18 23:26 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 0:01
Sampath5798-Aug-18 0:01 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt8-Aug-18 0:29
professionalJochen Arndt8-Aug-18 0:29 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 3:19
Sampath5798-Aug-18 3:19 
GeneralRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Jochen Arndt8-Aug-18 3:21
professionalJochen Arndt8-Aug-18 3:21 
GeneralRe: MovePrev() throwing -2147217837 error code. Pin
Sampath57912-Aug-18 1:36
Sampath57912-Aug-18 1:36 
QuestionRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
David Crow8-Aug-18 4:45
David Crow8-Aug-18 4:45 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Sampath5798-Aug-18 5:16
Sampath5798-Aug-18 5:16 
QuestionRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
David Crow9-Aug-18 4:56
David Crow9-Aug-18 4:56 
AnswerRe: MovePrev() throwing 265926 error code (End Of RowsSet). Pin
Stefan_Lang8-Aug-18 21:44
Stefan_Lang8-Aug-18 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.