calc++-scanner.ll

来自「GNU的词法/语法分析器bison源码」· LL 代码 · 共 53 行

LL
53
字号
%{                                            /* -*- C++ -*- */# include <cstdlib># include <errno.h># include <limits.h># include <string># include "calc++-driver.hh"# include "calc++-parser.hh"%}%option noyywrap nounput batch debugid    [a-zA-Z][a-zA-Z_0-9]*int   [0-9]+blank [ \t]%{# define YY_USER_ACTION  yylloc->columns (yyleng);%}%%%{  yylloc->step ();%}{blank}+   yylloc->step ();[\n]+      yylloc->lines (yyleng); yylloc->step ();[-+*/]     return yytext[0];":="       return TOKEN_ASSIGN;{int}      {  errno = 0;  long n = strtol (yytext, NULL, 10);  if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))    driver.error (*yylloc, "integer is out of range");  yylval->ival = n;  return TOKEN_NUMBER;}{id}       yylval->sval = new std::string (yytext); return TOKEN_IDENTIFIER;.          driver.error (*yylloc, "invalid character");%%voidcalcxx_driver::scan_begin (){  yy_flex_debug = trace_scanning;  if (!(yyin = fopen (file.c_str (), "r")))    error (std::string ("cannot open ") + file);}voidcalcxx_driver::scan_end (){  fclose (yyin);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?