diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-07-29 18:07:24 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-07-29 18:07:24 -0700 |
commit | f1d010bed8760aa87f9c72eded97d4d9b98cc620 (patch) | |
tree | 439628ed03b3b68404b7198883f993d1ef2b6753 /examples/manual/expr.lex |
Import flex_2.6.1.orig.tar.gz
[dgit import orig flex_2.6.1.orig.tar.gz]
Diffstat (limited to 'examples/manual/expr.lex')
-rw-r--r-- | examples/manual/expr.lex | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/manual/expr.lex b/examples/manual/expr.lex new file mode 100644 index 0000000..9adfcaa --- /dev/null +++ b/examples/manual/expr.lex @@ -0,0 +1,35 @@ +/* + * expr.lex : Scanner for a simple + * expression parser. + */ + +%{ +#include "y.tab.h" + +%} + +%% + +[0-9]+ { yylval.val = atol(yytext); + return(NUMBER); + } +[0-9]+\.[0-9]+ { + sscanf(yytext,"%f",&yylval.val); + return(NUMBER); + } +"+" return(PLUS); +"-" return(MINUS); +"*" return(MULT); +"/" return(DIV); +"^" return(EXPON); +"(" return(LB); +")" return(RB); +\n return(EOL); +[\t ]* /* throw away whitespace */ +. { yyerror("Illegal character"); + return(EOL); + } +%% + + + |