亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tokens.txt

?? Using the UnderC Tokenizer Class It s often necessary to parse complex text files, where standard
?? TXT
字號:
Using the UnderC Tokenizer Class

It's often necessary to parse complex text files, where standard i/o
is too clumsy.  C programmers fall back on strtok(), but this can be
tricky to use properly.  Besides, you are still responsible for keeping
strtok() fed with new input, and I don't like the schlepp. 

Tokenizer is a text-parsing input stream, modelled after the (undocumented)
VCL TParser class, and based on the UnderC tokenizing preprocessor front-end.

For example, consider a test.txt file containing this text:
one "hello" 'dolly' 10 2.3 *

;> #include <uc/tokens.h>
;> Tokenizer tok;
;> tok.open("test.txt");
(bool) true
;> tok.next();
(TokenType) 1 T_TOKEN
;> tok.get_str();
(char*) "one"

The next() method grabs the next token in the stream, and returns
a code identifying the token type.  The token itself is available
using get_str().  next() will eventually return T_END (zero) when
there are no more tokens available.

This is what happens when next() and get_str() are repeatedly called;
(I've used #define to save typing as usual)

;> #define F tok.next(); tok.get_str()
;> F
(TokenType) 7 T_STRING
(char*) "hello"
;> F
(TokenType) 7 T_STRING
(char*) "dolly"
;> F
(TokenType) 3 T_DOUBLE
(char*) "10"
;> F
(TokenType) 3 T_DOUBLE
(char*) "2.3"
;> F
(TokenType) 42 <undef>
(char*) "*"
;> F
(TokenType) 0 T_END
(char*) ""
;>

Anything which is not classified will be a non-whitespace character; generally
people are not interested in whitespace (tho it would not be difficult to
make Tokenizer optionally respect whitespace). 

get_str() returns the token buffer, which will be overwritten each time next()
is called - so never store the returned char pointer.  Either use a string, or
call get_str() with an explicit char* argument.

;> char buff[80];
;> tok.get_str(buff);
(char*) "hello"

The idea behind separating token fetching into next() and get_str() is to
make quite sure that you have the appropriate format available for conversion.

;> tok.get_str();
(char*) "10"
;> tok.get_number();
(double) 10.0

Processing String Buffers and Searching Forward

Tokenizer can work on a given string buffer; here is an example which takes a 
comma-separated list of items, and extracts them as individual strings:

int get_comma_list(Tokenizer& tok, string s, string vals[], int sz)
{
  Tokenizer ts;
  ts.set_str(s.c_str());
  int i = 0;
  while (ts.next()) {
     vals[i++] = ts.get_str();
     if (i == sz) break;
     ts.next(); // skip ','
  }
  return i;
}

This depends on your items being recognizable tokens, of course, but it does the
tricky part of ignoring commas inside strings.  I've often found such operations
useful when parsing configuration files.  You can of course use 'char** vals' instead
of 'string vals[]' but you will need to do a strdup() on the char pointer returned
by get_str().

It is very useful to be able to quickly move to the first occurance of a string
inside a file; this is done with the go_to() method. Here is a function which finds
a given section/key in a INI file:

bool find_key(Tokenizer& tok, string section, string key)
{
  string sect = "[" + section + "]";
  tok.go_to(sect.c_str());
  while (tok.next()) {
    if (key == tok.get_str()) {
          tok.next();  // skip '='
          return true;
    } else tok.discard_line();
  }
  return false;
}

For each key that doesn't match, I use discard_line() to force the next line to
be input.  getline() does the same thing, except copies the rest of the line
into a buffer. So to pick up the value of the key (which may contain special 
characters, like a file path) I can do this:

  find_key(tok,"Files","Directory");
  tok.getline(buff,sizeof(buff)); 

There is also getch() which fetches characters one at a time - this is one Tokenizer
method which respects whitespace.  This function will extract all block comments
from a C file:

void grab_comments(const char* file)
{
  Tokenizer tok(file);
  while (tok.go_to("/*")) {
    cout << tok.line() << ": ";
    do {
       cout << tok.getch();
    } while (! tok.next_is("*/"));
    cout << endl;
  }
}

next_is() is used to look ahead on the same line.

Making Tokenizer Respect C Strings.

Please note that by default Tokenizer classifies text in both single and double quotes
as T_STRING, and all kinds of numbers as T_DOUBLE.  If you want to make the usual
C-like distinctions, then use the C_MODE flag:

;> tok.rewind();
;> tok.set_flags(C_MODE);
;> F
(TokenType) 1 T_TOKEN
(char*) "one"
;> F
(TokenType) 7 T_STRING
(char*) "hello"
;> F
(TokenType) 6 T_CHAR
(char*) "dolly"
;> F
(TokenType) 2 T_INT
(char*) "10"
;> F
(TokenType) 3 T_DOUBLE
(char*) "2.3"
;> F
(TokenType) 42 <undef>
(char*) "*"
;> F
(TokenType) 0 T_END
(char*) "
"

Flags

C_NUMBER: integers begining with zero are interpreted as octal, and 0x... indicates
          the start of a hexadecimal number, as usual.  get_int() will automatically
          convert any hexadecimals.
C_STRING: a distinction is made between single and double quotes; any escape characters
          inside strings are respected.
C_IDEN:   words may contain '_' and numbers, like C identifiers.
STRIP_LINEFEEDS:  explicitly remove linefeeds when reading text.

These flags will affect other operations as well.  The next_float() method
moves along in the stream until it finds a valid T_NUMBER:

double Tokenizer::next_float()
{
 TokenType t;
 do {
  t = next();
  if (t == T_NUMBER) return get_float();
 } while (t != T_END);
 return 0.0;
}

If set_flags(C_NUMBER) is previously called, then it will _only_ pick up explicit
floating-point numbers (i.e. which have a fractional or an exponent part). This
function will return the sum of all the floating point numbers found in a stream

double avg_value(Tokenizer& tok)
{
  double sum = 0.0;  
  tok.set_flags(C_NUMBER);
  while (! tok.eof()) sum += tok.next_float();
  return sum;
}

It will not include any integers in this summation, which is useful when wanting
a quick statistic on a data file.

Here is a more complex file format, which represents a digitized underground mine
plan.  A typical MLS file will contain thousands of these segments:

...
face;
myid	4365992;
date	1995/10;
node	3,4366224;
node	1,4360216;
points	(22341.1,-2118.5,2237.7),(22342.4,-2120.1,2238.7),(22344.2,-2122.2,2240)
	,(22345.9,-2124.4,2241.2),(22347.8,-2126.4,2242.5),(22349.8,-2128.1,2243.7)
	,(22352,-2130.1,2245.1),(22354,-2132.2,2246.5),(22356.1,-2134,2247.8)
	,(22358.3,-2136.1,2249.2),(22360.4,-2138,2250.5),(22362.7,-2140.1,2252)
	,(22362.9,-2140.1,2252);
endface;
...  

I inherited this file format from a previous project, and it isn't ideal.
Extracting points from the comma-separated list is more laborious than it ought
to be.  But it's straightforward to access these points using Tokenizer.  For example,
this code works out the average of the x,y and z coordinates within a file:

 double xsum = 0.0, ysum = 0.0, zsum = 0.0;
 while (tok.go_to("points")) {
  char ch;
  do {
    xsum += tok.next_float();
    ysum += tok.next_float();
    zsum += tok.next_float();
    ch = (char)tok.next();                 
    if (ch == ')') ch = (char)tok.next();
    knt++;
  } while (ch != ';');
 }

I had some serious 7 Meg files in this format, and this code took just over a 
second to parse these numbers.  It's interesting to observe that the program took
only 35% more time using UnderC, than with the Microsoft compiler.

Error Handling

Generally, exception handling produces clean code where the 'exceptional' cases are
handled differently from business-as-usual.  But libraries imported into UnderC
cannot meaningfully throw exceptions, so supporting this style requires some 
helper functions.

char buff[80];

void error_expecting(const char* msg)
{
  throw TokenException(buff);
}

void must_be(Tokenizer& tok, char ch)
{
  TokenType t = tok.next();
  if ((char)t != ch) {
    sprintf(buff,"expecting '%c'\n",ch);
    error_expecting(buff);
  }
}

char* must_be_string(Tokenizer& tok)
{
  TokenType t = tok.next();
  if ((char)t != T_STRING) {
    error_expecting("string");
  }
  return tok.get_str();
}

You can then write code which concisely describes what tokens are expected
at each point.  Here is part of an XML parser.

 // pick up element attributes, if any
  while (t != '/' && t != '>') {
    if (t != T_TOKEN) error_expecting("word");
    name = tok.get_str();
    must_be(tok,'=');
    val  = must_be_string(tok);
    cout << "attrib " << name << '=' << val << endl;
    t = tok.next();
  }

This parser is found in lib/examples/xml.cpp, and does a lot for something
that's only 125 lines!



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
岛国一区二区三区| 色成年激情久久综合| 成人免费观看视频| 欧美亚洲国产一区二区三区 | 亚洲第一会所有码转帖| 免费观看久久久4p| 99国内精品久久| 日韩欧美你懂的| 亚洲免费电影在线| 国产一区二区三区免费播放| 粉嫩aⅴ一区二区三区四区五区| 日韩不卡一区二区三区| 欧美日韩免费观看一区二区三区| 丝袜亚洲另类欧美| 综合在线观看色| 久久九九99视频| 亚洲成va人在线观看| 久久99国产精品久久99 | 亚洲欧洲精品一区二区三区不卡| 亚洲bt欧美bt精品| jlzzjlzz亚洲女人18| 欧美大片一区二区三区| 亚洲成人在线网站| 色综合中文字幕国产 | 精品伦理精品一区| 五月天婷婷综合| 97久久超碰精品国产| 国产视频视频一区| 麻豆国产精品视频| 欧美久久免费观看| 亚洲一区二区欧美日韩| 91国产免费看| 国产精品久久久一区麻豆最新章节| 精品一区二区成人精品| 51午夜精品国产| 亚洲一区二区欧美| 色综合久久综合网欧美综合网| 国产欧美日本一区二区三区| 国产一区在线看| 欧美sm美女调教| 久久精品国产999大香线蕉| 欧美一区二区三区四区五区 | 日本一区二区动态图| 狠狠色狠狠色综合| 亚洲精品一线二线三线无人区| 久久国内精品自在自线400部| 欧美精品亚洲二区| 男女男精品视频| 欧美成人性福生活免费看| 老司机免费视频一区二区三区| 精品国产一区二区三区久久影院| 精品一区二区三区在线视频| 久久伊99综合婷婷久久伊| 国产伦精品一区二区三区免费| 久久久久久久久99精品| 国产河南妇女毛片精品久久久 | 久久er精品视频| 精品国产一区二区三区久久影院 | 亚洲高清免费观看高清完整版在线观看| 99精品久久久久久| 亚洲午夜影视影院在线观看| 欧美精品第1页| 久久成人免费电影| 国产精品私人影院| 欧美日韩一级黄| 久久国产精品色婷婷| 国产精品丝袜久久久久久app| 色综合天天综合给合国产| 五月婷婷久久综合| 国产日韩av一区| 欧美中文一区二区三区| 麻豆成人免费电影| 国产精品国产三级国产普通话三级| 在线一区二区视频| 久久9热精品视频| 国产精品成人一区二区艾草 | 美女在线一区二区| 国产精品久久久久一区二区三区共 | 日韩欧美中文字幕公布| 国产成人av电影在线| 亚洲午夜精品网| 国产午夜精品一区二区 | 中文字幕日本乱码精品影院| 欧美日韩成人综合在线一区二区| 国产一区二区不卡老阿姨| 亚洲美女区一区| 久久精品免视看| 欧美精品自拍偷拍动漫精品| 大桥未久av一区二区三区中文| 午夜精品福利一区二区三区av| 日本一区二区三区久久久久久久久不| 欧美视频一二三区| 成人高清在线视频| 国产在线视频不卡二| 亚洲第一二三四区| 国产精品国产三级国产aⅴ原创 | 亚洲欧洲一区二区在线播放| 中文无字幕一区二区三区| 欧美色图12p| 不卡一卡二卡三乱码免费网站| 男女性色大片免费观看一区二区| 亚洲柠檬福利资源导航| 国产日韩精品一区二区三区在线| 538在线一区二区精品国产| 色婷婷国产精品| 成人午夜免费av| 国产在线不卡一卡二卡三卡四卡| 亚洲成人黄色小说| 亚洲美腿欧美偷拍| 国产网站一区二区| 精品国免费一区二区三区| 666欧美在线视频| 欧美日韩情趣电影| 欧美视频一区在线| 97久久久精品综合88久久| 床上的激情91.| 国产成人av一区| 精品无人区卡一卡二卡三乱码免费卡| 日本美女视频一区二区| 视频一区二区三区入口| 亚洲一区二区综合| 午夜伊人狠狠久久| 日本三级韩国三级欧美三级| 亚洲午夜在线视频| 日本亚洲一区二区| 久久精品国产色蜜蜜麻豆| 久久99精品久久只有精品| 理论电影国产精品| 国产一区二区三区免费| 国产suv精品一区二区三区 | 日韩电影在线免费观看| 午夜国产精品一区| 日本不卡不码高清免费观看| 久久精品二区亚洲w码| 韩国精品一区二区| 成人激情开心网| 色综合久久久久| 欧美日韩色综合| 日韩欧美一二区| 久久精品无码一区二区三区| 国产精品乱人伦一区二区| 国产精品高潮呻吟| 亚洲午夜免费福利视频| 日韩av电影免费观看高清完整版 | 国产91露脸合集magnet| 91老司机福利 在线| 欧美色图在线观看| 精品国产免费久久| 国产精品久久久久久久久动漫| 亚洲狼人国产精品| 免费人成精品欧美精品| 国产一区二区中文字幕| av午夜一区麻豆| 欧美欧美欧美欧美| 久久精品视频免费观看| 亚洲老司机在线| 久久99蜜桃精品| 91丨九色丨蝌蚪富婆spa| 538prom精品视频线放| 中文字幕乱码一区二区免费| 一区二区三区波多野结衣在线观看| 婷婷国产v国产偷v亚洲高清| 精品一区二区免费在线观看| 97se亚洲国产综合自在线不卡| 欧美浪妇xxxx高跟鞋交| 亚洲国产精品精华液2区45| 亚洲永久免费av| 国产一区不卡视频| 欧美日韩一区二区三区视频| 久久亚洲精品小早川怜子| 亚洲乱码国产乱码精品精的特点| 久久国产精品色| 在线视频观看一区| 久久精品夜色噜噜亚洲a∨| 亚洲一区二区三区国产| 成人激情视频网站| 久久亚洲综合av| 日韩福利视频网| 91久久精品网| 国产欧美一区二区精品仙草咪| 午夜影院在线观看欧美| 色婷婷亚洲一区二区三区| 久久综合九色欧美综合狠狠| 亚洲成人1区2区| 92国产精品观看| 国产视频一区不卡| 久久99日本精品| 欧美电影在线免费观看| 亚洲你懂的在线视频| 成人久久18免费网站麻豆| 26uuu欧美日本| 蜜桃免费网站一区二区三区| 欧美日韩性生活| 亚洲午夜精品在线| 欧洲av在线精品| 中文字幕一区二区三| 成人听书哪个软件好| 欧美极品美女视频| 国产.欧美.日韩| 欧美国产精品一区二区三区|