免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 C/C++ 求解
最近访问板块 发新帖
查看: 1180 | 回复: 0
打印 上一主题 下一主题

[C] 求解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-14 13:54 |只看该作者 |倒序浏览
本帖最后由 yizhengming 于 2012-09-14 13:55 编辑

这是编译原理虎书的例子, 小弟对标记有1,2,3的行百思不得其解?(觉得3是打印单词的行号,和列号)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include "util.h"
  5. #include "errormsg.h"


  6. bool anyErrors= FALSE;

  7. static string fileName = "";

  8. static int lineNum = 1;

  9. int EM_tokPos=0;

  10. extern FILE *yyin;

  11. typedef struct intList {int i; struct intList *rest;} *IntList;

  12. static IntList intList(int i, IntList rest)
  13. {
  14.   IntList l= checked_malloc(sizeof *l);
  15.   l->i=i; l->rest=rest;
  16.   return l;
  17. }

  18. static IntList linePos=NULL;

  19. void EM_newline(void)
  20. {
  21.   lineNum++;
  22.   linePos = intList(EM_tokPos, linePos);
  23. }

  24. void EM_error(int pos, char *message,...)
  25. {
  26.   va_list ap;
  27.   IntList lines = linePos;
  28.   int num=lineNum;


  29.   anyErrors=TRUE;
  30.   while (lines && lines->i >= pos)                      1
  31.        {lines=lines->rest; num--;}                      2

  32.   if (fileName) fprintf(stderr,"%s:",fileName);
  33.   if (lines) fprintf(stderr,"%d.%d: ", num, pos-lines->i);   3
  34.   va_start(ap,message);
  35.   vfprintf(stderr, message, ap);
  36.   va_end(ap);
  37.   fprintf(stderr,"\n");
  38. }

  39. void EM_reset(string fname)
  40. {
  41. anyErrors=FALSE; fileName=fname; lineNum=1;
  42. linePos=intList(0,NULL);
  43. yyin = fopen(fname,"r");
  44. if (!yyin) {EM_error(0,"cannot open"); exit(1);}
  45. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP