|
I like to write lines of code that are very short and very simple to understand. Is there a way that I can communicate this in a shorter more compact form?
CEdit *idcinput = (CEdit *) GetDlgItem(IDC_INPUT);
char cinput[255];
idcinput->GetWindowText(cinput, 255);
CString sinput = cinput;
Thank you,
Eric Sepich
|
|
|
|
|
don't use C string when using MFC.
replace with
CEdit *idcinput = (CEdit *) GetDlgItem(IDC_INPUT);
CString sinput;
idcinput->GetWindowText(sinput );
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
esepich wrote:
I like to write lines of code that are very short and very simple to understand
If you made the edit control a member variable, then your code could be accomplished with:
CString sinput;<br />
m_EditCtrl.GetWindowText(&sinput);
|
|
|
|
|
Or declare a CString member variable of the IDC_INPUT in ClassWizard
and call
UpdateData(TRUE);
m_strYourdata; //your data already being updated and m_strYourdata is ready to be used.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
CString sData;
GetDlgItemText( IDC_INPUT, sData );
|
|
|
|
|
I'm about to attempt to write my own parser/compiler which would have to translate a certain language into specific machine codes or whatever. The thing is though i don't have any experience on this, but i'd just like to learn how to write parser code already. Like.. something that can check syntax and keywords and all that, but i would just make a mess, so if anyone can point me to a tutorial or example where they show how to do this in a structured way i'd very much appreciate it
thx
Kuniva
--------------------------------------------
|
|
|
|
|
Ah, this is brings back fond memories... One of my MS theses (circa 1984) was a virtual computer that included a parser for a (very simple) high level language. The compiler generated assembly language code which was run thru the virtual machine's interpreter.
Anyway, to answer your question, here are the basic steps you'd need to take:
- Define the grammar for your language
- Write a lexical analyzer that spits out language tokens
- Write a parser that creates a parse tree from a stream of tokens
- Write a code generator that translates a parse tree into machine instructions
- Optional: write an optimizer to optimize the machine instructions
I strongly recommend looking at a decent book on the subject. I used the Dragon Book[^] eons ago.
Writing a compiler is a labor of love and imho, a necessary part of learning and appreciating Computer Science. (Learning assembly language is like learning geometry - we do it because it teaches us how to think).
Good luck and have fun!
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi Bhavnani wrote:
I used the Dragon Book[^] eons ago
Aaah! the Dragon Book does bring back memories !!!
This[^] might also be useful...
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Are you taking a class on compiler construction at a college?
Check out these books on compiler construction.
The Dragon Book by Aho
Crafting a Compiler by Fisher and LaBlance
Kuphryn
|
|
|
|
|
Nope not yet, it's only my first year, we are learning Oberon now but.. blech :P
Kuniva
--------------------------------------------
|
|
|
|
|
|
|
I quite like Modern Compiler Design[^].
Most courses and texts cover simple parsing algorithms such as LL(1), LL(k) and LALR(1). These algorithms are powerful, but you really have to structure your grammar carefully to make them work - you tend to have to compromise your language, designing it around the parsing algorithm.
Famously, Bjarne Stroustrup did not do this, with the end result that C++ cannot be parsed by an LALR(1) algorithm (you must typically feed back into the lexer).
Generalised LR parsing algorithms are beginning to perform nearly as well as LALR parsers generated by yacc or bison . If you just want to parse your language and be done with it, consider the Elkhound[^] parser generator.
|
|
|
|
|
I'm using the system() command to call a batch file - This is done from a dialog box based program and the system() command is used within a loop - Each iteration causes the command.com window to get focus and control (the window pops up in front of whatever program I'm working with) - How can I minimize the window each time it is called, and if necessary, leave the focus with whatevery window has it ?
|
|
|
|
|
Try START /MIN application
|
|
|
|
|
I'll try this asap - Thanks
|
|
|
|
|
Use CreateProcess() instead of system(). This gives you far more control.
Here is some code I use in ED.
BOOL
Execute_OS_Program( char* pszCommandLine, char* pszWorkingDir, const int Run_Opts, int* const pnErrorCode )
{
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
DWORD dwCreationFlags = 0x00;
bool stat;
ZeroMemory( &siStartInfo, sizeof( STARTUPINFO ) );
siStartInfo.cb = sizeof( STARTUPINFO );
siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_SHOWNORMAL;
dwCreationFlags = CREATE_NEW_CONSOLE;
ZeroMemory( &piProcInfo, sizeof( PROCESS_INFORMATION ) );
stat = CreateProcess( NULL,
(char*)pszCommandLine,
NULL,
NULL,
FALSE,
dwCreationFlags,
NULL,
pszWorkingDir,
&siStartInfo,
&piProcInfo
) != FALSE;
if ( stat )
{
CloseHandle( piProcInfo.hThread );
*pnErrorCode = 0;
if ( Run_Opts & SE_WAIT )
WaitForSingleObject( piProcInfo.hProcess, INFINITE );
}
else
*pnErrorCode = GetLastError();
return stat;
}
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks - I'll take a look at this method today
|
|
|
|
|
Hello.
I have library foo.lib, which has class foo with a static member variable (see below), constuctor of class foo refers to the static member during initialization. I am using this library in my program, which has global variable of type foo.
The problem is that global_foo is initialized before foo::s_a is, so global_foo.m_var is not equall to 1 as I want it to be. How can I avoid this situation? Is there a way to force global initializations to be in a certain order?
Thank you.
P.S. I found on the net that solution could be mentioned in
Schwarz, "Initializing Static Variables in C++ Libraries", C++ Report. Vol1 No2, Feb. 89, pp1-4.
But I can not find this article online, and I do not have access to the C++ Gems book, which should have it.
--- foo.h
class foo
{
static int s_a;
int m_var;
foo(){m_var=s_a;}
}
--- foo.cpp
#include "foo.h"
int foo::s_a=1;
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Regards,
Alexander.
|
|
|
|
|
Move the ctor body to foo.cpp .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I can not move ctor. The situation is that static member should be defined in the lib file, while derivatives of the main class will be decleared as global objects in the main program.
Regards,
Alexander.
|
|
|
|
|
Ummm... try the following approach:
--- foo.h
class foo
{
static int& s_a();
int m_var;
foo(){m_var=s_a();}
}
--- foo.cpp
#include "foo.h"
int& foo::s_a()
{
static int s_a_var=1;
return s_a_var;
}
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot, this method works fine. Though it looks more like a trick, rather then a way to do such things Anyway it does work.
Regards,
Alexander.
|
|
|
|
|
The technique can be deemed a trick, but it is a very common one, since it helps to solve a long standing problem that some call the static initialization order fiasco[^]. Also, it is routinely used in some implementations of the Singleton pattern.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the link, nice to have it in favorites And it does work!
Regards,
Alexander.
|
|
|
|