开始flex

今天用flex写了老半天,发现总是告诉我premature EOF错误。

查了查google,还是没发现,不过有人遇到说是因为后面得%}写反了,可惜我没有。

 

最后发现是%}有一个自动缩进,看来我得emacs的flex-mode没有写好啊,这让人很伤感。查这么久错误就是因为习惯性得全局indent。

看来简单得从cc-mode里面派生flex-mode并不是那么靠谱。

 

附送简单的一个测试代码:


 1 /* 
2 * Sample Scanner:
3 * Description: Count the number of characters and the number of lines
4 * from standard input
5 * Usage: (1) $ flex sample.lex
6 * (2) $ gcc lex.yy.c -lfl
7 * (3) $ ./a.out
8 * stdin> whatever you like
9 * stdin> Ctrl-D
10 */
13
14 int num_lines = 0, num_chars = 0;
15
16 %%
17 \n ++num_lines; ++num_chars;
18 . ++num_chars;
19 %%
20
21 main()
22 {
23 yylex();
24 printf("# of lines = %d, # of chars = %d\n", num_lines, num_chars);
25 }

posted on 2012-01-15 22:38  Richard Wong  阅读(562)  评论(0)    收藏  举报