Warning, /maui/brun/src/mathengine/scanner.ll is written in an unsupported language. File is not indexed.
0001 /* 0002 * This file is part of Kalk 0003 * 0004 * Copyright (C) 2020 Han Young <hanyoung@protonmail.com> 0005 * 0006 * $BEGIN_LICENSE:GPL3+$ 0007 * 0008 * This program is free software: you can redistribute it and/or modify 0009 * it under the terms of the GNU General Public License as published by 0010 * the Free Software Foundation, either version 3 of the License, or 0011 * (at your option) any later version. 0012 * 0013 * This program is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 * GNU General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU General Public License 0019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 * 0021 * $END_LICENSE$ 0022 */ 0023 %{ /* -*- C++ -*- */ 0024 # include <cerrno> 0025 # include <climits> 0026 # include <cstdlib> 0027 # include <cstring> // strerror 0028 # include <string> 0029 # include <knumber.h> 0030 # include <QString> 0031 # include "driver.hh" 0032 # include "parser.hh" 0033 %} 0034 0035 %{ 0036 #if defined __clang__ 0037 # define CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) 0038 #endif 0039 0040 // Clang and ICC like to pretend they are GCC. 0041 #if defined __GNUC__ && !defined __clang__ && !defined __ICC 0042 # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 0043 #endif 0044 0045 // Pacify warnings in yy_init_buffer (observed with Flex 2.6.4) 0046 // and GCC 6.4.0, 7.3.0 with -O3. 0047 #if defined GCC_VERSION && 600 <= GCC_VERSION 0048 # pragma GCC diagnostic ignored "-Wnull-dereference" 0049 #endif 0050 0051 // This example uses Flex's C back end, yet compiles it as C++. 0052 // So expect warnings about C style casts and NULL. 0053 #if defined CLANG_VERSION && 500 <= CLANG_VERSION 0054 # pragma clang diagnostic ignored "-Wold-style-cast" 0055 # pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" 0056 #elif defined GCC_VERSION && 407 <= GCC_VERSION 0057 # pragma GCC diagnostic ignored "-Wold-style-cast" 0058 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" 0059 #endif 0060 0061 #define FLEX_VERSION (YY_FLEX_MAJOR_VERSION * 100 + YY_FLEX_MINOR_VERSION) 0062 0063 // Old versions of Flex (2.5.35) generate an incomplete documentation comment. 0064 // 0065 // In file included from src/scan-code-c.c:3: 0066 // src/scan-code.c:2198:21: error: empty paragraph passed to '@param' command 0067 // [-Werror,-Wdocumentation] 0068 // * @param line_number 0069 // ~~~~~~~~~~~~~~~~~^ 0070 // 1 error generated. 0071 #if FLEX_VERSION < 206 && defined CLANG_VERSION 0072 # pragma clang diagnostic ignored "-Wdocumentation" 0073 #endif 0074 0075 // Old versions of Flex (2.5.35) use 'register'. Warnings introduced in 0076 // GCC 7 and Clang 6. 0077 #if FLEX_VERSION < 206 0078 # if defined CLANG_VERSION && 600 <= CLANG_VERSION 0079 # pragma clang diagnostic ignored "-Wdeprecated-register" 0080 # elif defined GCC_VERSION && 700 <= GCC_VERSION 0081 # pragma GCC diagnostic ignored "-Wregister" 0082 # endif 0083 #endif 0084 0085 #if FLEX_VERSION < 206 0086 # if defined CLANG_VERSION 0087 # pragma clang diagnostic ignored "-Wconversion" 0088 # pragma clang diagnostic ignored "-Wdocumentation" 0089 # pragma clang diagnostic ignored "-Wshorten-64-to-32" 0090 # pragma clang diagnostic ignored "-Wsign-conversion" 0091 # elif defined GCC_VERSION 0092 # pragma GCC diagnostic ignored "-Wconversion" 0093 # pragma GCC diagnostic ignored "-Wsign-conversion" 0094 # endif 0095 #endif 0096 %} 0097 0098 %option noyywrap nounput noinput batch 0099 0100 %{ 0101 // A number symbol corresponding to the value in S. 0102 yy::parser::symbol_type 0103 make_NUMBER (const std::string &s, const yy::parser::location_type& loc); 0104 %} 0105 0106 knumber [0-9]+|([0-9]+)?("."|",")[0-9]+ 0107 0108 %{ 0109 // Code run each time a pattern is matched. 0110 # define YY_USER_ACTION loc.columns (yyleng); 0111 %} 0112 %% 0113 %{ 0114 // A handy shortcut to the location held by the driver. 0115 yy::location& loc = drv.location; 0116 // Code run each time yylex is called. 0117 loc.step (); 0118 %} 0119 0120 "-" return yy::parser::make_MINUS (loc); 0121 "+" return yy::parser::make_PLUS (loc); 0122 "×" return yy::parser::make_STAR (loc); 0123 "÷" return yy::parser::make_SLASH (loc); 0124 "(" return yy::parser::make_LPAREN (loc); 0125 ")" return yy::parser::make_RPAREN (loc); 0126 "^" return yy::parser::make_POWER (loc); 0127 "sin" return yy::parser::make_SIN (loc); 0128 "cos" return yy::parser::make_COS (loc); 0129 "tan" return yy::parser::make_TAN (loc); 0130 "log" return yy::parser::make_LOG (loc); 0131 "log10" return yy::parser::make_LOG10 (loc); 0132 "log2" return yy::parser::make_LOG2 (loc); 0133 "√" return yy::parser::make_SQUAREROOT (loc); 0134 "π" return yy::parser::make_NUMBER (KNumber::Pi(), loc); 0135 "e" return yy::parser::make_NUMBER (KNumber::Euler(), loc); 0136 "%" return yy::parser::make_PERCENTAGE (loc); 0137 "=" loc.step (); 0138 "asin" return yy::parser::make_ASIN (loc); 0139 "acos" return yy::parser::make_ACOS (loc); 0140 "atan" return yy::parser::make_ATAN (loc); 0141 "abs" return yy::parser::make_ABS (loc); 0142 0143 {knumber} return make_NUMBER (yytext, loc); 0144 <<EOF>> return yy::parser::symbol_type (0, loc); 0145 %% 0146 0147 yy::parser::symbol_type 0148 make_NUMBER (const std::string &s, const yy::parser::location_type& loc) 0149 { 0150 errno = 0; 0151 KNumber n = KNumber(QString::fromStdString(s)); 0152 return yy::parser::make_NUMBER ((KNumber) n, loc); 0153 } 0154 0155 void 0156 driver::scan_begin (std::string s) 0157 { 0158 yy_switch_to_buffer(yy_scan_string(s.c_str())); 0159 }