Qucs-core
0.0.19
|
00001 /* -*-c-*- */ 00002 00003 %{ 00004 /* 00005 * scan_citi.l - scanner for CITIfiles 00006 * 00007 * Copyright (C) 2006 Stefan Jahn <stefan@lkcc.org> 00008 * 00009 * This is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2, or (at your option) 00012 * any later version. 00013 * 00014 * This software is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this package; see the file COPYING. If not, write to 00021 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00022 * Boston, MA 02110-1301, USA. 00023 * 00024 * $Id$ 00025 * 00026 */ 00027 00028 #if defined(__clang__) 00029 #pragma clang diagnostic push 00030 #pragma clang diagnostic ignored "-Wdeprecated-register" 00031 #endif 00032 00033 #if HAVE_CONFIG_H 00034 # include <config.h> 00035 #endif 00036 00037 #include <stdio.h> 00038 #include <stdlib.h> 00039 #include <string.h> 00040 #include <ctype.h> 00041 00042 #ifdef __MINGW32__ 00043 #include <io.h> 00044 #endif 00045 00046 #ifdef HAVE_UNISTD_H 00047 #include <unistd.h> 00048 #endif 00049 00050 #include "logging.h" 00051 #include "complex.h" 00052 #include "object.h" 00053 #include "vector.h" 00054 #include "dataset.h" 00055 #include "check_citi.h" 00056 #include "tokens_citi.h" 00057 00058 using namespace qucs; 00059 00060 %} 00061 00062 WS [ \t\n\r] 00063 ID [a-zA-Z_][a-zA-Z0-9_\.]* 00064 DIGIT [0-9] 00065 EXPONENT [Ee][+-]?{DIGIT}+ 00066 INT [+-]?{DIGIT}+ 00067 FLOAT1 [+-]?{DIGIT}+{EXPONENT} 00068 FLOAT2 [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})? 00069 SPACE [ \t] 00070 EOL \r?\n 00071 00072 %x COMMENTS FLOATS LISTS DATAS VALUES 00073 %option yylineno noyywrap nounput noinput prefix="citi_" 00074 00075 %% 00076 00077 <INITIAL,FLOATS,LISTS>{EOL}+ { /* detect end of line */ return Eol; } 00078 00079 <*>{SPACE} /* skip spaces */ 00080 00081 <INITIAL,DATAS>{INT} { /* identify integer */ 00082 citi_lval.d = strtol (citi_text, NULL, 10); 00083 return Integer; 00084 } 00085 00086 <INITIAL>[a-zA-Z]"."{DIGIT}+"."{DIGIT}+ { 00087 return Version; 00088 } 00089 00090 <INITIAL,DATAS>("RI"|"MAG"|"MAGANGLE"|"DBANGLE") { 00091 citi_lval.ident = strdup (citi_text); 00092 return VarType; 00093 } 00094 00095 <INITIAL>^"CITIFILE" { return CITIFILE; } 00096 <INITIAL>^"VAR" { return VAR; } 00097 <INITIAL>^"DATA" { BEGIN(DATAS); return DATA; } 00098 <INITIAL>^"NAME" { return NAME; } 00099 <INITIAL>^"BEGIN" { BEGIN(FLOATS); return Begin; } 00100 <INITIAL>^"CONSTANT" { BEGIN(VALUES); return CONSTANT; } 00101 <INITIAL>^"COMMENT" { BEGIN(COMMENTS); } 00102 00103 <INITIAL>^"SEG_LIST_BEGIN" { BEGIN(LISTS); return SegListBegin; } 00104 <INITIAL>^"VAR_LIST_BEGIN" { BEGIN(LISTS); return VarListBegin; } 00105 <LISTS>^"SEG_LIST_END" { BEGIN(INITIAL); return SegListEnd; } 00106 <LISTS>^"VAR_LIST_END" { BEGIN(INITIAL); return VarListEnd; } 00107 <LISTS>^"SEG" { return SEG; } 00108 00109 <INITIAL,DATAS,VALUES>{ID} { /* identify identifier */ 00110 citi_lval.ident = strdup (citi_text); 00111 return Identifier; 00112 } 00113 00114 <FLOATS,LISTS,VALUES>({FLOAT1}|{FLOAT2}|{INT}) { /* identify float */ 00115 citi_lval.f = strtod (citi_text, NULL); 00116 return Float; 00117 } 00118 00119 <VALUES>{EOL}+ { BEGIN(INITIAL); return Eol; } 00120 00121 <DATAS>"," { /* pass the ',' to the parser */ return ','; } 00122 <DATAS>"[" { /* pass the '[' to the parser */ return '['; } 00123 <DATAS>"]" { /* pass the ']' to the parser */ BEGIN(INITIAL); return ']'; } 00124 <DATAS>{EOL}+ { BEGIN(INITIAL); return Eol; } 00125 00126 <FLOATS>"," { /* pass the ',' to the parser */ return ','; } 00127 00128 <FLOATS>^"END" { BEGIN(INITIAL); return End; } 00129 00130 <INITIAL>^"#" { /* leave these characters */ 00131 BEGIN(COMMENTS); 00132 } 00133 00134 <COMMENTS>. { /* skip any character in here */ } 00135 <COMMENTS>{EOL}+ { BEGIN(INITIAL); /* skipping ends here */ } 00136 00137 <*>. { /* any other character in invalid */ 00138 logprint (LOG_ERROR, 00139 "line %d: syntax error, unrecognized character: `%s'\n", 00140 citi_lineno, citi_text); 00141 return InvalidCharacter; 00142 } 00143 00144 %%