基本上,它应该给出原子令牌数量的合理近似值 。存在于C源文件中。 对于那些在c.l.c中阅读的人:在程序本身中是否有任何明显的错误或 糟糕的编码风格?我是否错过任何 角落案例---对于任何有效的C99计划,该程序是否会生成错误数量的 令牌? 对于那些阅读clm的人:Andreas,这是给你的。 (: 我只是张贴它以防万一有人有任何意见 沿着gee,C is nifty!或gee ,C不能做什么 任何东西!  请在回复中正确设置跟进:comp.lang.c 可能并不关心实用语言比较;)和 comp.lang.misc绝对不需要长期迂腐辩论 是否# define是一个或两个令牌。[1] ;) -Arthur [1] - 我在我的程序中将其视为一个标记,即使 看起来技术上它不是令牌。在任何意义上的 字,标准说。 Request for comments on the following program: http://www.contrib.andrew.cmu.edu/~a...kshop/tokens.c It''s a token counter for the C programming language, followingthe outline kind-of-described here: http://www.kochandreas.com/home/lang...sts/TOKENS.HTMBasically, it''s supposed to give a reasonable approximation ofthe number of "atomic tokens" present in a C source file. To those reading in c.l.c: Are there any glaring mistakes orpoor coding styles in the program itself? And did I miss anycorner cases --- does the program produce a wrong number oftokens for any valid C99 program? To those reading in c.l.m: Andreas, this is for you. (:I''m just posting it generally in case anyone has any commentsalong the lines of "gee, C is nifty!" or "gee, C can''t doanything!" Please set follow-ups appropriately in your reply: comp.lang.cprobably doesn''t care about Practical Language Comparison ;) andcomp.lang.misc definitely doesn''t want long pedantic debates aboutwhether #define is one token or two.[1] ;) -Arthur [1] - I''m counting it as one token in my program, even thoughit looks like technically it''s not a "token" in any sense of theword, Standard-ly speaking.推荐答案 在comp.lang.misc Arthur J. O'Dwyer< aj*@nospam.andrew.cmu.edu>写道:In comp.lang.misc Arthur J. O''Dwyer <aj*@nospam.andrew.cmu.edu> wrote: comp.lang.misc绝对不想长期迂腐辩论 #define是一个还是两个。[1] ;) comp.lang.misc definitely doesn''t want long pedantic debates about whether #define is one token or two.[1] ;) 为什么不呢?他们/是/两个代币: #define xy Nils - Nils M Holm< nm*@despammed.com> - http://www.t3x.org/nmh/ 我在comp.lang.c中读到这个,后续设置。 " Arthur J. O''Dwyer" < aj*@nospam.andrew.cmu.edu>写道:I''m reading this in comp.lang.c, followup set. "Arthur J. O''Dwyer" <aj*@nospam.andrew.cmu.edu> writes:请求对以下程序发表评论: http://www.contrib.andrew.cmu.edu/~a...kshop/tokens.c 它''用于C编程语言的令牌计数器,遵循这里描述的概述: http://www.kochandreas.com/home/lang...sts/TOKENS.HTM 基本上,它应该是给出原子令牌数量的合理近似值。出现在C源文件中。 对于那些在c.l.c中阅读的人:程序本身是否存在明显的错误或编码风格差?我是否错过了任何有关C99程序的错误数量的令牌? Request for comments on the following program: http://www.contrib.andrew.cmu.edu/~a...kshop/tokens.c It''s a token counter for the C programming language, following the outline kind-of-described here: http://www.kochandreas.com/home/lang...sts/TOKENS.HTM Basically, it''s supposed to give a reasonable approximation of the number of "atomic tokens" present in a C source file. To those reading in c.l.c: Are there any glaring mistakes or poor coding styles in the program itself? And did I miss any corner cases --- does the program produce a wrong number of tokens for any valid C99 program? 我我刚刚快速浏览了你的代码,所以请用 来评价我的评论。 我更喜欢`int main(void)''over` int main()'',特别是因为你不要为所有其他函数使用前C89风格的定义。 当`getchar( )''返回'EOF'',你应该检查这是由于 错误还是由于文件结束条件造成的。 目标显然是计算预处理令牌,对吧?在那个 的情况下,你似乎在太详细的层面上解析数字。预处理 - 数字用更一般的术语定义,详见6.4.8(C99 标准)。 Martin - , - 。 Martin Dickopp,德国德累斯顿,=, - _-。 =。 /, - ) http://www.zero -based.org/ ((_ /)oo(\_)) \` - ''` - ''(。)` - '' ` - 。 Debian,GNU操作系统的一种变体。 \ _ / I have just quickly skimmed your code, so please take my comments with agrain of salt. I prefer `int main (void)'' over `int main ()'', especially since youdon''t use pre-C89-style definitions for all other functions. When `getchar ()'' returns `EOF'', you should check if this is due to anerror or due to end-of-file condition. The goal is apparently to count preprocessing-tokens, right? In thatcase, you seem to parse numbers on a too detailed level. Preprocessing-numbers are defined in much more general terms, see 6.4.8 (of the C99standard) for details. Martin--,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =./ ,- ) http://www.zero-based.org/ ((_/)o o(\_))\ `-'' `-''(. .)`-''`-. Debian, a variant of the GNU operating system. \_/ Arthur J. O''Dwyer写道:Arthur J. O''Dwyer wrote:请求对以下程序发表评论: http://www.contrib.andrew.cmu.edu /〜a...kshop/tokens.c [...]对于那些在clc中阅读的人:程序本身是否有明显的错误或编码风格不佳?我是否错过了任何角落案例---该程序是否为任何有效的C99程序生成了错误数量的令牌? 它没有正确处理有向图:以下产生错误: int main()< %%> 我认为对于具有几个 翻译阶段的语言,例如C,这个任务并没有很好地定义。你必须决定是否计算令牌或预处理令牌。为了计算令牌,你需要指定输入已经过预处理,或者你自己实现了大部分预处理器。以下程序有* b $ b 35预处理令牌,但只有11个令牌: #define str(x)#x int main(){puts( str) int main(){puts (" Hello,world。"); 返回0; }));} 你的程序给出34。为此(计算#define作为单个 令牌),所以它似乎在计算预处理令牌。但是, 一些有效的预处理令牌,例如某些预处理 数字,被拒绝: #define str(x) #x int main(){str(3p +); } 我认为上面的所有程序都严格遵守。 comp.lang.misc绝对不想长时间迂腐辩论 #define是一个还是两个。[1] ;) [...] [1] - 我在我的程序中将其视为一个标记,即使它看起来像技术上它不是一个标记。在任何意义上说,标准说话。 Request for comments on the following program: http://www.contrib.andrew.cmu.edu/~a...kshop/tokens.c[...] To those reading in c.l.c: Are there any glaring mistakes or poor coding styles in the program itself? And did I miss any corner cases --- does the program produce a wrong number of tokens for any valid C99 program?It doesn''t handle digraphs correctly: the following produces an error: int main()<%%> I think the task isn''t well defined for a language with severaltranslation phases, like C, however. You have to decide whether tocount tokens or preprocessing tokens. In order to count tokens youeither need to specify that the input is already preprocessed, orimplement most of a preprocessor yourself. The following program has35 preprocessing tokens, but only 11 tokens: #define str(x) # xint main() { puts(str(int main() { puts("Hello, world.");return 0;}));} Your program gives "34" for this (counting "#define" as a singletoken), so it seems to be counting preprocessing tokens. However,some valid preprocessing tokens, such as certain preprocessingnumbers, are rejected: #define str(x) # xint main() { str(3p+); } I think all the programs above are strictly conforming. comp.lang.misc definitely doesn''t want long pedantic debates about whether #define is one token or two.[1] ;)[...] [1] - I''m counting it as one token in my program, even though it looks like technically it''s not a "token" in any sense of the word, Standard-ly speaking. "#"是一个标点符号,它是一个标记符号,并且是定义标记符号。是一个标识符, 也是一个标记。 Jeremy。 "#" is a punctuator, which is a token, and "define" is an identifier,also a token. Jeremy. 这篇关于[RFC] C令牌计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 05:15