📄 fcl-scanner.ll
字号:
%{ /* -*- C++ -*- */# include <cstdlib># include <errno.h># include <limits.h># include <string># include "fcl-driver.hh"# include "fcl-parser.hh"/* Work around an incompatibility in flex (at least versions 2.5.31 through 2.5.33): it generates code that does not conform to C89. See Debian bug 333231 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */# undef yywrap# define yywrap() 1/* By default yylex returns int, we use token_type. Unfortunately yyterminate by default returns 0, which is not of token_type. */#define yyterminate() return token::END%}%start comment%option noyywrap nounput batch debug%{ typedef yy::fcl_parser::token token;%}%{# define YY_USER_ACTION yylloc->columns (yyleng);%}digit [0-9]letter [a-zA-Z_]identifier {letter}({letter}|{digit})*integer_literal {digit}+decimal_literal {integer_literal}.{integer_literal}*start_comment "(*"id [a-zA-Z][a-zA-Z_0-9]*int [0-9]+blank [ \t]%%%{ yylloc->step ();%}{start_comment} BEGIN(comment);<comment>[^*\n]* /* eat anything that's not a '*' */;<comment>"*"+[^*)\n]* /* eat up '*'s not followed by ')'s */;<comment>\n /* nothing to be done */;<comment>"*"+")" BEGIN(INITIAL);FUNCTION_BLOCK { return token::FUNCTION_BLOCK; }END_FUNCTION_BLOCK { return token::END_FUNCTION_BLOCK; }VAR_OUTPUT { return token::VAR_OUTPUT; }VAR_INPUT { return token::VAR_INPUT; }END_VAR { return token::END_VAR; }FUZZIFY { return token::FUZZIFY; }END_FUZZIFY { return token::END_FUZZIFY; }DEFUZZIFY { return token::DEFUZZIFY; }END_DEFUZZIFY { return token::END_DEFUZZIFY; }TERM { return token::TERM; }REAL { return token::REAL; }RULEBLOCK { return token::RULEBLOCK; }END_RULEBLOCK { return token::END_RULEBLOCK; }RANGE { return token::RANGE; }AND { return token::AND; }OR { return token::OR; }MAX { return token::MAX; }MIN { return token::MIN; }ACT { return token::ACT; }PROD { return token::PROD; }ASUM { return token::ASUM; }BSUM { return token::BSUM; }BDIF { return token::BDIF; }NSUM { return token::NSUM; }ACCU { return token::ACCU; }RULE { return token::RULE; }IF { return token::IF; }THEN { return token::THEN; }IS { return token::IS; }METHOD { return token::METHOD; }COG { return token::COG; }COGS { return token::COGS; }COA { return token::COA; }LM { return token::LM; }RM { return token::RM; }{id} { yylval->sval = new std::string (yytext); return token::IDENTIFIER; } /* Convert ints to the actual type of tokens. */[-+*/] return yy::fcl_parser::token_type (yytext[0]);{blank}+ yylloc->step ();[\n]+ yylloc->lines (yyleng); yylloc->step ();":" { return token::COLON; }";" { return token::SEMI; }"," { return token::COMMA; }"(" { return token::LPAREN; }")" { return token::RPAREN; }":=" { return token::ASSIGN; }".." { return token::DPOINT; }{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; }. { driver.error (*yylloc, "invalid character"); }%%voidfcl_driver::scan_begin (){ yy_flex_debug = trace_scanning; if (!(yyin = fopen (file.c_str (), "r"))) error (std::string ("cannot open ") + file);}voidfcl_driver::scan_end (){ fclose (yyin);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -