] Private Sub Command7_Click (Index As an Integer)
M1=Val (Text1. Text) 'computing symbols before take the number 1
Suanfa=Command7 (Index). Caption
Text1. Text=""
End Sub
Private Sub Command6_Click ()
M2=Val (Text1. Text) 'equal access 2
The Select Case suanfa
The Case "+"
Text1. Text=m1 + m2
Case ", "
Text1. Text=m1, m2
Case '*'
Text1. Text=* m1 m2
Case "/"
If (m2=0) Then
Text1. Text="divisor cannot be zero."
The Else
Text1. Text=m1/m2
End the If
This is my homework, and can only be implemented once add and subtract, at present, how to connect the plus even minus?
End the Select
End Sub
[/code]
CodePudding user response:
"Compiler principle" reference of lexical analysis and the finite state automata,Refer to the following, although C:
//a string
//1 _22_333, 4444 __55555 _666666
//need to parse for
//1
//22
//333
//_
//4444
//55555
//666666
# include & lt; stdio.h>
Char [] s="_22_333, 1, 4444 __55555, _666666";
Char c, * p, * p;
Int st.
Void main () {
St=0;
P=s;
While (1) {
C=* p;
If (0==c) {
The switch (st) {
Case 1: printf (" _ \ n "); break;
Case 2: printf (" % s \ n ", (p1); break;
}
break;//
}
The switch (st) {
Case 0:
If (' _ '==c) {st=0; }
Else if (', ')==c {st=1; }
The else {p1=p; St=2; }
break;
Case 1:
If (' _ '==c) {st=1; }
Else if (', ')==c {printf (" _ \ n "); St=1; }
The else {p1=p; St=2; }
break;
Case 2:
If (' _ '==c) {* p=0; Printf (" % s \ n ", (p1); * p=c; St=0; }
Else if (', ')==c {* p=0; Printf (" % s \ n ", (p1); * p=c; St=1; }
The else {st=2; }
break;
}
p++;
}
}
//1
//22
//333
//_
//4444
//55555
//666666
CodePudding user response:
Thank the teacher answer,,, but still I didn't understand,,CodePudding user response:
Only one character scan expression... Scanning to the character, record the position, and remove the character before the text with the mid, and then converted to digital, as the Numbers 1 to participate in the operation, and then remove the sign of operation, and then continue to scan the next operator or end expression, use mids, as number two, with just the operation of symbolic operation, the result as the number 1, and then continue to scan to the end of the expression...The whole process is like this... However, as a subject for beginners, is a bit difficult to... To be honest...
CodePudding user response:
The