2009年12月14日
Eclipse 設置ANTLR package后
還需要在project上面右鍵點擊 然后選擇Add Antlr IDE support 才會在保存 .g 文件時
自動生成parser代碼!
2009年12月11日
AntlrWorks 運行的時候,需要JRE
但是,正常工作卻需要JDK
因為,它的Debug和Run部分需要調用 Javac.exe,這個東西JDK才有。
安裝好了之后,還需要到 File -> Preference 里設置編譯器路徑。
AntlrWorks只是調試grammar的時候比較方便,作為一個編輯器,還
不夠好用。
2009年12月7日
摘要: ANTLR 3
byR. Mark Volkmann, Partner/Software Engineer Object Computing, Inc. (OCI) 翻譯者:Morya
Preface
前言
ANTLR is a big topic, so this is a big article. The table of contents that follows contains...
閱讀全文
2009年10月23日
目的?
像我一樣,不得不分析一些格式不是很復雜,但也不簡單的log文件。
厭倦了寫正則表達式,更不想為了這個東西搞一個狀態機。(我也搞不來狀態機……)
安裝篇:
安裝simpleParse。
http://sourceforge.net/projects/simpleparse/files/
找到 SimpleParse-2.1.1a2.win32-py2.5.exe 或者 SimpleParse-2.1.1a2.win32-py2.6.exe
安裝。
使用篇:
1,要為需要被分析的文件寫一個文法(grammar)。
2,后面就簡單了。
ibm這里有一篇教程,
http://www.ibm.com/developerworks/library/l-simple.html?S_TACT=105AGX52&S_CMP=cn-a-l
也有翻譯成中文的
http://www.ibm.com/developerworks/cn/linux/sdk/python/charm-23/index.html
可惜,中文版的代碼格式亂掉了,需要代碼可以去英文版copy。
后面就沒啥好講的了。
2009年8月17日
Qt Creator 當前版本1.2.1 與 Qt4.5.2一起發布。
安裝方式:windows 直接下載 qt-sdk-win-opensource-2009.03.1.exe 就很好用。
安裝后有一個特別重要的東西需要調整,那就是代碼補全的Hot Key (默認是Ctrl+Space……)
我認為,Qt Creator 下面幾個特性最值得稱道:
1,Locator 定位器 使用快捷鍵 Ctrl+K
2,使用快捷鍵Ctrl+1, 2, 3, 4, 5在幾個mode里面快速切換
3,利用F4在cpp和header文件之間快速切換
4,使用Esc快速返回編輯模式
2009年8月16日
貌似,用了引用傳值,connect雖然沒有報錯,卻不會運行到那段代碼,改成不是引用就沒問題了。
2009年7月31日
C++ Primer 3rd Edition 說
fstream 已經包含了 iostream, 可是,明顯不是這么回事。
下面的代碼就編不過。(VC2005)
//#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::endl;
using std::fstream;
void test_fstream(){
fstream f;
f.open("c:\\in.txt", fstream::in);
if( f.fail() ){
cout << "Can't open file for input."<<endl;
}
else{
cout << "File opened." << endl;
}
f.close();
}
int main(){
test_fstream();
return 0;
}
2009年7月29日
2009年7月28日
捕獲異常,用引用還是用指針,我一直很糊涂。
學STL里面,有可能拋出異常的地方,用指針一直都無法捕獲,搞相當疑惑。
后來才知道,用那種格式需要對你調用函數會拋出哪種異常清楚才行。
下面是示例代碼:
1 #include <iostream>
2 #include <string>
3 #include <exception>
4
5 using std::cout;
6 using std::endl;
7 using std::string;
8 using std::exception;
9
10 class MyException : public exception{
11 public:
12 MyException();
13 };
14
15 MyException::MyException():exception("You know that"){}
16
17 void thr(){
18 throw new MyException();
19 }
20
21 void test_exception(){
22
23 string s;
24 try{
25 s.at(1);
26 }
27 catch(exception & e){
28 cout << "Caught exception." << e.what() << endl;
29 }
30
31 try{
32 thr();
33 }
34 catch(MyException* e){
35 cout << "Caught myException: " << e->what() << endl;
36 delete e;
37 e = NULL;
38 }
39 }
40
41 void main(){
42 test_exception();
43 }
44
異常是以指針方式拋出,就用指針形式來捕獲,用普通形式拋出,就需要用普通格式,為了減少復制,那么用引用就可以了。
2009年7月23日
下面的代碼可以搞定
void binary(int v){
using std::bitset;
using std::cout;
using std::endl;
bitset< 8*sizeof(int) > b = v;
cout << b.to_string() << endl;
bitset<8> b2 = v;
cout << b.to_string() << endl;
}