- 论坛徽章:
- 2
|
我有一个很简单的lex程序,来自<<编译原理>>,清华版的
- $ cat -n my.lex
- 1 %{
- 2 #include<stdio.h>
- 3 #include"code.h"
- 4 #include"symbol.h"
- 5 #include"y.tab.h"
- 6 extern int level;
- 7 int cc=0;
- 8 %}
- 9 IDENT [a-zA-Z][a-zA-Z0-9]*
- 10 NUMBER [0-9][0-9]*
- 11 %%
- 12 " " {cc++;}
- 13 "\t" {tablize();}
- 14 "\n" {cc=0;line_copy();}
- 15 "<" {cc++;return LT;}
- 16 ">" {cc++;return GR;}
- 17 "=" {cc++;return EQ;}
- 18 "#" {cc++;return NE;}
- 19 "," {cc++;return colon;}
- 20 "." {cc++;return Period;}
- 21 "(" {cc++;return Lparen;}
- 22 ")" {cc++;return Rparen;}
- 23 "<=" {cc+=2;return LE;}
- 24 ">=" {cc+=2;return GE;}
- 25 ":=" {cc+=2;return ASGN;}
- 26 ";" {cc++;return Semicolon;}
- 27 {NUMBER}{
- 28 int n;
- 29 cc+=yyleng;
- 30 sscanf(yytext,"%d",&n);
- 31 yylval.number=n;
- 32 return NUMBER;
- 33 }
- 34 {IDENT}{
- 35 Symbol *s;
- 36 cc+=yyleng;
- 37 if((s=lookup(yytext))==0)
- 38 s=install(yytext,VARIABLE,level,0);
- 39 if(s->type==C)
- 40 yylval.number=s->adr;
- 41 else
- 42 yylval.sym=s;
- 43 return s->type;
- 44 }
- 45 %%
- 46 yywrap(){----
- 47 };
- $ lex my.lex
- my.lex:27: 不能识别的规则
- my.lex:27: 不能识别的规则
- my.lex:33: 不能识别的规则
- my.lex:33: 不能识别的规则
- my.lex:34: 不能识别的规则
- my.lex:34: 不能识别的规则
- my.lex:44: 不能识别的规则
- my.lex:44: 不能识别的规则
复制代码
我的程序哪里有错误呢,应该怎么改?
|
|