我编写了 lex 程序来计算在 linux 中使用 gedit 的令牌数。但它没有运行。我在这方面是新的。我也无法找出代码中的问题。
这是程序代码:
count=0
digit [0-9]
letter [A-Z][a-z]
%%
{letter} | ({letter}|{digit})*
count++
%%
int main()
{
yylex()
printf("no. of identifier=%d",count);
}
错误消息是:
scanner.l:9: error: expected declaration specifiers before ‘yylex’
scanner.l:10: error: expected ‘{’ at end of input