Last active
January 1, 2016 15:09
-
-
Save LeslieZhu/8162183 to your computer and use it in GitHub Desktop.
一个Flex例子,用于生成显示行号的词法分析程序。flex linno.lex; gcc lex.yy.c -o lineno; cat file.txt | ./lineno;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%option noyywrap | |
%{ | |
/* a Lex program that adds line numbers | |
to lines of text, printing the new text | |
to the standard output | |
*/ | |
#include <stdio.h> | |
int lineno = 1; | |
%} | |
line .*\n | |
%% | |
{line} {printf("%5d %s", lineno++,yytext);} | |
%% | |
int main() | |
{ | |
yylex(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment