ast_expr2.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420
  1. /* A Bison parser, made by GNU Bison 2.0. */
  2. /* Skeleton parser for Yacc-like parsing with Bison,
  3. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. /* As a special exception, when this file is copied by Bison into a
  17. Bison output file, you may use that output file without restriction.
  18. This special exception was added by the Free Software Foundation
  19. in version 1.24 of Bison. */
  20. /* Written by Richard Stallman by simplifying the original so called
  21. ``semantic'' parser. */
  22. /* All symbols defined below should begin with yy or YY, to avoid
  23. infringing on user name space. This should be done even for local
  24. variables, as they might otherwise be expanded by user macros.
  25. There are some unavoidable exceptions within include files to
  26. define necessary library symbols; they are noted "INFRINGES ON
  27. USER NAME SPACE" below. */
  28. /* Identify Bison output. */
  29. #define YYBISON 1
  30. /* Skeleton name. */
  31. #define YYSKELETON_NAME "yacc.c"
  32. /* Pure parsers. */
  33. #define YYPURE 1
  34. /* Using locations. */
  35. #define YYLSP_NEEDED 1
  36. /* Substitute the variable and function names. */
  37. #define yyparse ast_yyparse
  38. #define yylex ast_yylex
  39. #define yyerror ast_yyerror
  40. #define yylval ast_yylval
  41. #define yychar ast_yychar
  42. #define yydebug ast_yydebug
  43. #define yynerrs ast_yynerrs
  44. #define yylloc ast_yylloc
  45. /* Tokens. */
  46. #ifndef YYTOKENTYPE
  47. # define YYTOKENTYPE
  48. /* Put the tokens into the symbol table, so that GDB and other debuggers
  49. know about them. */
  50. enum yytokentype {
  51. TOK_COLONCOLON = 258,
  52. TOK_COND = 259,
  53. TOK_OR = 260,
  54. TOK_AND = 261,
  55. TOK_NE = 262,
  56. TOK_LE = 263,
  57. TOK_GE = 264,
  58. TOK_LT = 265,
  59. TOK_GT = 266,
  60. TOK_EQ = 267,
  61. TOK_MINUS = 268,
  62. TOK_PLUS = 269,
  63. TOK_MOD = 270,
  64. TOK_DIV = 271,
  65. TOK_MULT = 272,
  66. TOK_COMPL = 273,
  67. TOK_EQTILDE = 274,
  68. TOK_COLON = 275,
  69. TOK_LP = 276,
  70. TOK_RP = 277,
  71. TOKEN = 278
  72. };
  73. #endif
  74. #define TOK_COLONCOLON 258
  75. #define TOK_COND 259
  76. #define TOK_OR 260
  77. #define TOK_AND 261
  78. #define TOK_NE 262
  79. #define TOK_LE 263
  80. #define TOK_GE 264
  81. #define TOK_LT 265
  82. #define TOK_GT 266
  83. #define TOK_EQ 267
  84. #define TOK_MINUS 268
  85. #define TOK_PLUS 269
  86. #define TOK_MOD 270
  87. #define TOK_DIV 271
  88. #define TOK_MULT 272
  89. #define TOK_COMPL 273
  90. #define TOK_EQTILDE 274
  91. #define TOK_COLON 275
  92. #define TOK_LP 276
  93. #define TOK_RP 277
  94. #define TOKEN 278
  95. /* Copy the first part of user declarations. */
  96. #line 1 "ast_expr2.y"
  97. /* Written by Pace Willisson (pace@blitz.com)
  98. * and placed in the public domain.
  99. *
  100. * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
  101. *
  102. * And then overhauled twice by Steve Murphy (murf@e-tools.com)
  103. * to add double-quoted strings, allow mult. spaces, improve
  104. * error messages, and then to fold in a flex scanner for the
  105. * yylex operation.
  106. *
  107. * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
  108. */
  109. #include <sys/types.h>
  110. #include <stdio.h>
  111. #include <stdlib.h>
  112. #include <string.h>
  113. #include <locale.h>
  114. #include <ctype.h>
  115. #if !defined(SOLARIS) && !defined(__CYGWIN__)
  116. #include <err.h>
  117. #else
  118. #define quad_t int64_t
  119. #endif
  120. #include <errno.h>
  121. #include <regex.h>
  122. #include <limits.h>
  123. #include <asterisk/ast_expr.h>
  124. #include <asterisk/logger.h>
  125. #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
  126. #define QUAD_MIN LONG_LONG_MIN
  127. #endif
  128. #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
  129. #define QUAD_MAX LONG_LONG_MAX
  130. #endif
  131. # if ! defined(QUAD_MIN)
  132. # define QUAD_MIN (-0x7fffffffffffffffLL-1)
  133. # endif
  134. # if ! defined(QUAD_MAX)
  135. # define QUAD_MAX (0x7fffffffffffffffLL)
  136. # endif
  137. #define YYPARSE_PARAM parseio
  138. #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
  139. #define YYERROR_VERBOSE 1
  140. enum valtype {
  141. AST_EXPR_integer, AST_EXPR_numeric_string, AST_EXPR_string
  142. } ;
  143. #ifdef STANDALONE
  144. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
  145. #endif
  146. struct val {
  147. enum valtype type;
  148. union {
  149. char *s;
  150. quad_t i;
  151. } u;
  152. } ;
  153. typedef void *yyscan_t;
  154. struct parse_io
  155. {
  156. char *string;
  157. struct val *val;
  158. yyscan_t scanner;
  159. };
  160. static int chk_div __P((quad_t, quad_t));
  161. static int chk_minus __P((quad_t, quad_t, quad_t));
  162. static int chk_plus __P((quad_t, quad_t, quad_t));
  163. static int chk_times __P((quad_t, quad_t, quad_t));
  164. static void free_value __P((struct val *));
  165. static int is_zero_or_null __P((struct val *));
  166. static int isstring __P((struct val *));
  167. static struct val *make_integer __P((quad_t));
  168. static struct val *make_str __P((const char *));
  169. static struct val *op_and __P((struct val *, struct val *));
  170. static struct val *op_colon __P((struct val *, struct val *));
  171. static struct val *op_eqtilde __P((struct val *, struct val *));
  172. static struct val *op_div __P((struct val *, struct val *));
  173. static struct val *op_eq __P((struct val *, struct val *));
  174. static struct val *op_ge __P((struct val *, struct val *));
  175. static struct val *op_gt __P((struct val *, struct val *));
  176. static struct val *op_le __P((struct val *, struct val *));
  177. static struct val *op_lt __P((struct val *, struct val *));
  178. static struct val *op_cond __P((struct val *, struct val *, struct val *));
  179. static struct val *op_minus __P((struct val *, struct val *));
  180. static struct val *op_negate __P((struct val *));
  181. static struct val *op_compl __P((struct val *));
  182. static struct val *op_ne __P((struct val *, struct val *));
  183. static struct val *op_or __P((struct val *, struct val *));
  184. static struct val *op_plus __P((struct val *, struct val *));
  185. static struct val *op_rem __P((struct val *, struct val *));
  186. static struct val *op_times __P((struct val *, struct val *));
  187. static quad_t to_integer __P((struct val *));
  188. static void to_string __P((struct val *));
  189. /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
  190. typedef struct yyltype
  191. {
  192. int first_line;
  193. int first_column;
  194. int last_line;
  195. int last_column;
  196. } yyltype;
  197. # define YYLTYPE yyltype
  198. # define YYLTYPE_IS_TRIVIAL 1
  199. /* we will get warning about no prototype for yylex! But we can't
  200. define it here, we have no definition yet for YYSTYPE. */
  201. int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
  202. /* I wanted to add args to the yyerror routine, so I could print out
  203. some useful info about the error. Not as easy as it looks, but it
  204. is possible. */
  205. #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
  206. #define DESTROY(x) { \
  207. if ((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) \
  208. free((x)->u.s); \
  209. (x)->u.s = 0; \
  210. free(x); \
  211. }
  212. /* Enabling traces. */
  213. #ifndef YYDEBUG
  214. # define YYDEBUG 0
  215. #endif
  216. /* Enabling verbose error messages. */
  217. #ifdef YYERROR_VERBOSE
  218. # undef YYERROR_VERBOSE
  219. # define YYERROR_VERBOSE 1
  220. #else
  221. # define YYERROR_VERBOSE 0
  222. #endif
  223. #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
  224. #line 142 "ast_expr2.y"
  225. typedef union YYSTYPE {
  226. struct val *val;
  227. } YYSTYPE;
  228. /* Line 190 of yacc.c. */
  229. #line 268 "ast_expr2.c"
  230. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  231. # define YYSTYPE_IS_DECLARED 1
  232. # define YYSTYPE_IS_TRIVIAL 1
  233. #endif
  234. #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
  235. typedef struct YYLTYPE
  236. {
  237. int first_line;
  238. int first_column;
  239. int last_line;
  240. int last_column;
  241. } YYLTYPE;
  242. # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
  243. # define YYLTYPE_IS_DECLARED 1
  244. # define YYLTYPE_IS_TRIVIAL 1
  245. #endif
  246. /* Copy the second part of user declarations. */
  247. #line 146 "ast_expr2.y"
  248. extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
  249. /* Line 213 of yacc.c. */
  250. #line 295 "ast_expr2.c"
  251. #if ! defined (yyoverflow) || YYERROR_VERBOSE
  252. # ifndef YYFREE
  253. # define YYFREE free
  254. # endif
  255. # ifndef YYMALLOC
  256. # define YYMALLOC malloc
  257. # endif
  258. /* The parser invokes alloca or malloc; define the necessary symbols. */
  259. # ifdef YYSTACK_USE_ALLOCA
  260. # if YYSTACK_USE_ALLOCA
  261. # ifdef __GNUC__
  262. # define YYSTACK_ALLOC __builtin_alloca
  263. # else
  264. # define YYSTACK_ALLOC alloca
  265. # endif
  266. # endif
  267. # endif
  268. # ifdef YYSTACK_ALLOC
  269. /* Pacify GCC's `empty if-body' warning. */
  270. # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
  271. # else
  272. # if defined (__STDC__) || defined (__cplusplus)
  273. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  274. # define YYSIZE_T size_t
  275. # endif
  276. # define YYSTACK_ALLOC YYMALLOC
  277. # define YYSTACK_FREE YYFREE
  278. # endif
  279. #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
  280. #if (! defined (yyoverflow) \
  281. && (! defined (__cplusplus) \
  282. || (defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
  283. && defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
  284. /* A type that is properly aligned for any stack member. */
  285. union yyalloc
  286. {
  287. short int yyss;
  288. YYSTYPE yyvs;
  289. YYLTYPE yyls;
  290. };
  291. /* The size of the maximum gap between one aligned stack and the next. */
  292. # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  293. /* The size of an array large to enough to hold all stacks, each with
  294. N elements. */
  295. # define YYSTACK_BYTES(N) \
  296. ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  297. + 2 * YYSTACK_GAP_MAXIMUM)
  298. /* Copy COUNT objects from FROM to TO. The source and destination do
  299. not overlap. */
  300. # ifndef YYCOPY
  301. # if defined (__GNUC__) && 1 < __GNUC__
  302. # define YYCOPY(To, From, Count) \
  303. __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  304. # else
  305. # define YYCOPY(To, From, Count) \
  306. do \
  307. { \
  308. register YYSIZE_T yyi; \
  309. for (yyi = 0; yyi < (Count); yyi++) \
  310. (To)[yyi] = (From)[yyi]; \
  311. } \
  312. while (0)
  313. # endif
  314. # endif
  315. /* Relocate STACK from its old location to the new one. The
  316. local variables YYSIZE and YYSTACKSIZE give the old and new number of
  317. elements in the stack, and YYPTR gives the new location of the
  318. stack. Advance YYPTR to a properly aligned location for the next
  319. stack. */
  320. # define YYSTACK_RELOCATE(Stack) \
  321. do \
  322. { \
  323. YYSIZE_T yynewbytes; \
  324. YYCOPY (&yyptr->Stack, Stack, yysize); \
  325. Stack = &yyptr->Stack; \
  326. yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  327. yyptr += yynewbytes / sizeof (*yyptr); \
  328. } \
  329. while (0)
  330. #endif
  331. #if defined (__STDC__) || defined (__cplusplus)
  332. typedef signed char yysigned_char;
  333. #else
  334. typedef short int yysigned_char;
  335. #endif
  336. /* YYFINAL -- State number of the termination state. */
  337. #define YYFINAL 10
  338. /* YYLAST -- Last index in YYTABLE. */
  339. #define YYLAST 140
  340. /* YYNTOKENS -- Number of terminals. */
  341. #define YYNTOKENS 24
  342. /* YYNNTS -- Number of nonterminals. */
  343. #define YYNNTS 3
  344. /* YYNRULES -- Number of rules. */
  345. #define YYNRULES 22
  346. /* YYNRULES -- Number of states. */
  347. #define YYNSTATES 46
  348. /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  349. #define YYUNDEFTOK 2
  350. #define YYMAXUTOK 278
  351. #define YYTRANSLATE(YYX) \
  352. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  353. /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  354. static const unsigned char yytranslate[] =
  355. {
  356. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  357. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  358. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  359. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  360. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  361. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  362. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  363. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  364. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  365. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  366. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  367. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  368. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  369. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  370. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  371. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  372. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  373. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  374. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  375. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  376. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  377. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  378. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  379. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  380. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  381. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  382. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  383. 15, 16, 17, 18, 19, 20, 21, 22, 23
  384. };
  385. #if YYDEBUG
  386. /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  387. YYRHS. */
  388. static const unsigned char yyprhs[] =
  389. {
  390. 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
  391. 31, 35, 39, 43, 47, 51, 54, 57, 61, 65,
  392. 69, 73, 77
  393. };
  394. /* YYRHS -- A `-1'-separated list of the rules' RHS. */
  395. static const yysigned_char yyrhs[] =
  396. {
  397. 25, 0, -1, 26, -1, 23, -1, 21, 26, 22,
  398. -1, 26, 5, 26, -1, 26, 6, 26, -1, 26,
  399. 12, 26, -1, 26, 11, 26, -1, 26, 10, 26,
  400. -1, 26, 9, 26, -1, 26, 8, 26, -1, 26,
  401. 7, 26, -1, 26, 14, 26, -1, 26, 13, 26,
  402. -1, 13, 26, -1, 18, 26, -1, 26, 17, 26,
  403. -1, 26, 16, 26, -1, 26, 15, 26, -1, 26,
  404. 20, 26, -1, 26, 19, 26, -1, 26, 4, 26,
  405. 3, 26, -1
  406. };
  407. /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  408. static const unsigned char yyrline[] =
  409. {
  410. 0, 165, 165, 175, 176, 180, 184, 188, 192, 196,
  411. 200, 204, 208, 212, 216, 220, 224, 228, 232, 236,
  412. 240, 244, 248
  413. };
  414. #endif
  415. #if YYDEBUG || YYERROR_VERBOSE
  416. /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  417. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  418. static const char *const yytname[] =
  419. {
  420. "$end", "error", "$undefined", "TOK_COLONCOLON", "TOK_COND", "TOK_OR",
  421. "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT", "TOK_GT", "TOK_EQ",
  422. "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV", "TOK_MULT", "TOK_COMPL",
  423. "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP", "TOKEN", "$accept",
  424. "start", "expr", 0
  425. };
  426. #endif
  427. # ifdef YYPRINT
  428. /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  429. token YYLEX-NUM. */
  430. static const unsigned short int yytoknum[] =
  431. {
  432. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  433. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  434. 275, 276, 277, 278
  435. };
  436. # endif
  437. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  438. static const unsigned char yyr1[] =
  439. {
  440. 0, 24, 25, 26, 26, 26, 26, 26, 26, 26,
  441. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  442. 26, 26, 26
  443. };
  444. /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  445. static const unsigned char yyr2[] =
  446. {
  447. 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
  448. 3, 3, 3, 3, 3, 2, 2, 3, 3, 3,
  449. 3, 3, 5
  450. };
  451. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  452. STATE-NUM when YYTABLE doesn't specify something else to do. Zero
  453. means the default is an error. */
  454. static const unsigned char yydefact[] =
  455. {
  456. 0, 0, 0, 0, 3, 0, 2, 15, 16, 0,
  457. 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  458. 0, 0, 0, 0, 0, 0, 0, 4, 0, 5,
  459. 6, 12, 11, 10, 9, 8, 7, 14, 13, 19,
  460. 18, 17, 21, 20, 0, 22
  461. };
  462. /* YYDEFGOTO[NTERM-NUM]. */
  463. static const yysigned_char yydefgoto[] =
  464. {
  465. -1, 5, 6
  466. };
  467. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  468. STATE-NUM. */
  469. #define YYPACT_NINF -13
  470. static const yysigned_char yypact[] =
  471. {
  472. 109, 109, 109, 109, -13, 6, 59, 106, 106, 22,
  473. -13, 109, 109, 109, 109, 109, 109, 109, 109, 109,
  474. 109, 109, 109, 109, 109, 109, 109, -13, 42, 90,
  475. 104, 120, 120, 120, 120, 120, 120, -12, -12, 106,
  476. 106, 106, -13, -13, 109, 75
  477. };
  478. /* YYPGOTO[NTERM-NUM]. */
  479. static const yysigned_char yypgoto[] =
  480. {
  481. -13, -13, -1
  482. };
  483. /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  484. positive, shift that token. If negative, reduce the rule which
  485. number is the opposite. If zero, do what YYDEFACT says.
  486. If YYTABLE_NINF, syntax error. */
  487. #define YYTABLE_NINF -1
  488. static const unsigned char yytable[] =
  489. {
  490. 7, 8, 9, 22, 23, 24, 10, 25, 26, 0,
  491. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  492. 38, 39, 40, 41, 42, 43, 11, 12, 13, 14,
  493. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  494. 0, 25, 26, 45, 27, 44, 11, 12, 13, 14,
  495. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  496. 0, 25, 26, 11, 12, 13, 14, 15, 16, 17,
  497. 18, 19, 20, 21, 22, 23, 24, 0, 25, 26,
  498. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  499. 22, 23, 24, 0, 25, 26, 13, 14, 15, 16,
  500. 17, 18, 19, 20, 21, 22, 23, 24, 0, 25,
  501. 26, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  502. 23, 24, 1, 25, 26, 25, 26, 2, 0, 0,
  503. 3, 0, 4, 20, 21, 22, 23, 24, 0, 25,
  504. 26
  505. };
  506. static const yysigned_char yycheck[] =
  507. {
  508. 1, 2, 3, 15, 16, 17, 0, 19, 20, -1,
  509. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  510. 21, 22, 23, 24, 25, 26, 4, 5, 6, 7,
  511. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  512. -1, 19, 20, 44, 22, 3, 4, 5, 6, 7,
  513. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  514. -1, 19, 20, 4, 5, 6, 7, 8, 9, 10,
  515. 11, 12, 13, 14, 15, 16, 17, -1, 19, 20,
  516. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  517. 15, 16, 17, -1, 19, 20, 6, 7, 8, 9,
  518. 10, 11, 12, 13, 14, 15, 16, 17, -1, 19,
  519. 20, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  520. 16, 17, 13, 19, 20, 19, 20, 18, -1, -1,
  521. 21, -1, 23, 13, 14, 15, 16, 17, -1, 19,
  522. 20
  523. };
  524. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  525. symbol of state STATE-NUM. */
  526. static const unsigned char yystos[] =
  527. {
  528. 0, 13, 18, 21, 23, 25, 26, 26, 26, 26,
  529. 0, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  530. 13, 14, 15, 16, 17, 19, 20, 22, 26, 26,
  531. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  532. 26, 26, 26, 26, 3, 26
  533. };
  534. #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
  535. # define YYSIZE_T __SIZE_TYPE__
  536. #endif
  537. #if ! defined (YYSIZE_T) && defined (size_t)
  538. # define YYSIZE_T size_t
  539. #endif
  540. #if ! defined (YYSIZE_T)
  541. # if defined (__STDC__) || defined (__cplusplus)
  542. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  543. # define YYSIZE_T size_t
  544. # endif
  545. #endif
  546. #if ! defined (YYSIZE_T)
  547. # define YYSIZE_T unsigned int
  548. #endif
  549. #define yyerrok (yyerrstatus = 0)
  550. #define yyclearin (yychar = YYEMPTY)
  551. #define YYEMPTY (-2)
  552. #define YYEOF 0
  553. #define YYACCEPT goto yyacceptlab
  554. #define YYABORT goto yyabortlab
  555. #define YYERROR goto yyerrorlab
  556. /* Like YYERROR except do call yyerror. This remains here temporarily
  557. to ease the transition to the new meaning of YYERROR, for GCC.
  558. Once GCC version 2 has supplanted version 1, this can go. */
  559. #define YYFAIL goto yyerrlab
  560. #define YYRECOVERING() (!!yyerrstatus)
  561. #define YYBACKUP(Token, Value) \
  562. do \
  563. if (yychar == YYEMPTY && yylen == 1) \
  564. { \
  565. yychar = (Token); \
  566. yylval = (Value); \
  567. yytoken = YYTRANSLATE (yychar); \
  568. YYPOPSTACK; \
  569. goto yybackup; \
  570. } \
  571. else \
  572. { \
  573. yyerror ("syntax error: cannot back up");\
  574. YYERROR; \
  575. } \
  576. while (0)
  577. #define YYTERROR 1
  578. #define YYERRCODE 256
  579. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  580. If N is 0, then set CURRENT to the empty location which ends
  581. the previous symbol: RHS[0] (always defined). */
  582. #define YYRHSLOC(Rhs, K) ((Rhs)[K])
  583. #ifndef YYLLOC_DEFAULT
  584. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  585. do \
  586. if (N) \
  587. { \
  588. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  589. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  590. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  591. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  592. } \
  593. else \
  594. { \
  595. (Current).first_line = (Current).last_line = \
  596. YYRHSLOC (Rhs, 0).last_line; \
  597. (Current).first_column = (Current).last_column = \
  598. YYRHSLOC (Rhs, 0).last_column; \
  599. } \
  600. while (0)
  601. #endif
  602. /* YY_LOCATION_PRINT -- Print the location on the stream.
  603. This macro was not mandated originally: define only if we know
  604. we won't break user code: when these are the locations we know. */
  605. #ifndef YY_LOCATION_PRINT
  606. # if YYLTYPE_IS_TRIVIAL
  607. # define YY_LOCATION_PRINT(File, Loc) \
  608. fprintf (File, "%d.%d-%d.%d", \
  609. (Loc).first_line, (Loc).first_column, \
  610. (Loc).last_line, (Loc).last_column)
  611. # else
  612. # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  613. # endif
  614. #endif
  615. /* YYLEX -- calling `yylex' with the right arguments. */
  616. #ifdef YYLEX_PARAM
  617. # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
  618. #else
  619. # define YYLEX yylex (&yylval, &yylloc)
  620. #endif
  621. /* Enable debugging if requested. */
  622. #if YYDEBUG
  623. # ifndef YYFPRINTF
  624. # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  625. # define YYFPRINTF fprintf
  626. # endif
  627. # define YYDPRINTF(Args) \
  628. do { \
  629. if (yydebug) \
  630. YYFPRINTF Args; \
  631. } while (0)
  632. # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  633. do { \
  634. if (yydebug) \
  635. { \
  636. YYFPRINTF (stderr, "%s ", Title); \
  637. yysymprint (stderr, \
  638. Type, Value, Location); \
  639. YYFPRINTF (stderr, "\n"); \
  640. } \
  641. } while (0)
  642. /*------------------------------------------------------------------.
  643. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  644. | TOP (included). |
  645. `------------------------------------------------------------------*/
  646. #if defined (__STDC__) || defined (__cplusplus)
  647. static void
  648. yy_stack_print (short int *bottom, short int *top)
  649. #else
  650. static void
  651. yy_stack_print (bottom, top)
  652. short int *bottom;
  653. short int *top;
  654. #endif
  655. {
  656. YYFPRINTF (stderr, "Stack now");
  657. for (/* Nothing. */; bottom <= top; ++bottom)
  658. YYFPRINTF (stderr, " %d", *bottom);
  659. YYFPRINTF (stderr, "\n");
  660. }
  661. # define YY_STACK_PRINT(Bottom, Top) \
  662. do { \
  663. if (yydebug) \
  664. yy_stack_print ((Bottom), (Top)); \
  665. } while (0)
  666. /*------------------------------------------------.
  667. | Report that the YYRULE is going to be reduced. |
  668. `------------------------------------------------*/
  669. #if defined (__STDC__) || defined (__cplusplus)
  670. static void
  671. yy_reduce_print (int yyrule)
  672. #else
  673. static void
  674. yy_reduce_print (yyrule)
  675. int yyrule;
  676. #endif
  677. {
  678. int yyi;
  679. unsigned int yylno = yyrline[yyrule];
  680. YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
  681. yyrule - 1, yylno);
  682. /* Print the symbols being reduced, and their result. */
  683. for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
  684. YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
  685. YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
  686. }
  687. # define YY_REDUCE_PRINT(Rule) \
  688. do { \
  689. if (yydebug) \
  690. yy_reduce_print (Rule); \
  691. } while (0)
  692. /* Nonzero means print parse trace. It is left uninitialized so that
  693. multiple parsers can coexist. */
  694. int yydebug;
  695. #else /* !YYDEBUG */
  696. # define YYDPRINTF(Args)
  697. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  698. # define YY_STACK_PRINT(Bottom, Top)
  699. # define YY_REDUCE_PRINT(Rule)
  700. #endif /* !YYDEBUG */
  701. /* YYINITDEPTH -- initial size of the parser's stacks. */
  702. #ifndef YYINITDEPTH
  703. # define YYINITDEPTH 200
  704. #endif
  705. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  706. if the built-in stack extension method is used).
  707. Do not make this value too large; the results are undefined if
  708. SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
  709. evaluated with infinite-precision integer arithmetic. */
  710. #ifndef YYMAXDEPTH
  711. # define YYMAXDEPTH 10000
  712. #endif
  713. #if YYERROR_VERBOSE
  714. # ifndef yystrlen
  715. # if defined (__GLIBC__) && defined (_STRING_H)
  716. # define yystrlen strlen
  717. # else
  718. /* Return the length of YYSTR. */
  719. static YYSIZE_T
  720. # if defined (__STDC__) || defined (__cplusplus)
  721. yystrlen (const char *yystr)
  722. # else
  723. yystrlen (yystr)
  724. const char *yystr;
  725. # endif
  726. {
  727. register const char *yys = yystr;
  728. while (*yys++ != '\0')
  729. continue;
  730. return yys - yystr - 1;
  731. }
  732. # endif
  733. # endif
  734. # ifndef yystpcpy
  735. # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
  736. # define yystpcpy stpcpy
  737. # else
  738. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  739. YYDEST. */
  740. static char *
  741. # if defined (__STDC__) || defined (__cplusplus)
  742. yystpcpy (char *yydest, const char *yysrc)
  743. # else
  744. yystpcpy (yydest, yysrc)
  745. char *yydest;
  746. const char *yysrc;
  747. # endif
  748. {
  749. register char *yyd = yydest;
  750. register const char *yys = yysrc;
  751. while ((*yyd++ = *yys++) != '\0')
  752. continue;
  753. return yyd - 1;
  754. }
  755. # endif
  756. # endif
  757. #endif /* !YYERROR_VERBOSE */
  758. #if YYDEBUG
  759. /*--------------------------------.
  760. | Print this symbol on YYOUTPUT. |
  761. `--------------------------------*/
  762. #if defined (__STDC__) || defined (__cplusplus)
  763. static void
  764. yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  765. #else
  766. static void
  767. yysymprint (yyoutput, yytype, yyvaluep, yylocationp)
  768. FILE *yyoutput;
  769. int yytype;
  770. YYSTYPE *yyvaluep;
  771. YYLTYPE *yylocationp;
  772. #endif
  773. {
  774. /* Pacify ``unused variable'' warnings. */
  775. (void) yyvaluep;
  776. (void) yylocationp;
  777. if (yytype < YYNTOKENS)
  778. YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  779. else
  780. YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  781. YY_LOCATION_PRINT (yyoutput, *yylocationp);
  782. fprintf (yyoutput, ": ");
  783. # ifdef YYPRINT
  784. if (yytype < YYNTOKENS)
  785. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  786. # endif
  787. switch (yytype)
  788. {
  789. default:
  790. break;
  791. }
  792. YYFPRINTF (yyoutput, ")");
  793. }
  794. #endif /* ! YYDEBUG */
  795. /*-----------------------------------------------.
  796. | Release the memory associated to this symbol. |
  797. `-----------------------------------------------*/
  798. #if defined (__STDC__) || defined (__cplusplus)
  799. static void
  800. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  801. #else
  802. static void
  803. yydestruct (yymsg, yytype, yyvaluep, yylocationp)
  804. const char *yymsg;
  805. int yytype;
  806. YYSTYPE *yyvaluep;
  807. YYLTYPE *yylocationp;
  808. #endif
  809. {
  810. /* Pacify ``unused variable'' warnings. */
  811. (void) yyvaluep;
  812. (void) yylocationp;
  813. if (!yymsg)
  814. yymsg = "Deleting";
  815. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  816. switch (yytype)
  817. {
  818. default:
  819. break;
  820. }
  821. }
  822. /* Prevent warnings from -Wmissing-prototypes. */
  823. #ifdef YYPARSE_PARAM
  824. # if defined (__STDC__) || defined (__cplusplus)
  825. int yyparse (void *YYPARSE_PARAM);
  826. # else
  827. int yyparse ();
  828. # endif
  829. #else /* ! YYPARSE_PARAM */
  830. #if defined (__STDC__) || defined (__cplusplus)
  831. int yyparse (void);
  832. #else
  833. int yyparse ();
  834. #endif
  835. #endif /* ! YYPARSE_PARAM */
  836. /*----------.
  837. | yyparse. |
  838. `----------*/
  839. #ifdef YYPARSE_PARAM
  840. # if defined (__STDC__) || defined (__cplusplus)
  841. int yyparse (void *YYPARSE_PARAM)
  842. # else
  843. int yyparse (YYPARSE_PARAM)
  844. void *YYPARSE_PARAM;
  845. # endif
  846. #else /* ! YYPARSE_PARAM */
  847. #if defined (__STDC__) || defined (__cplusplus)
  848. int
  849. yyparse (void)
  850. #else
  851. int
  852. yyparse ()
  853. #endif
  854. #endif
  855. {
  856. /* The look-ahead symbol. */
  857. int yychar;
  858. /* The semantic value of the look-ahead symbol. */
  859. YYSTYPE yylval;
  860. /* Number of syntax errors so far. */
  861. int yynerrs;
  862. /* Location data for the look-ahead symbol. */
  863. YYLTYPE yylloc;
  864. register int yystate;
  865. register int yyn;
  866. int yyresult;
  867. /* Number of tokens to shift before error messages enabled. */
  868. int yyerrstatus;
  869. /* Look-ahead token as an internal (translated) token number. */
  870. int yytoken = 0;
  871. /* Three stacks and their tools:
  872. `yyss': related to states,
  873. `yyvs': related to semantic values,
  874. `yyls': related to locations.
  875. Refer to the stacks thru separate pointers, to allow yyoverflow
  876. to reallocate them elsewhere. */
  877. /* The state stack. */
  878. short int yyssa[YYINITDEPTH];
  879. short int *yyss = yyssa;
  880. register short int *yyssp;
  881. /* The semantic value stack. */
  882. YYSTYPE yyvsa[YYINITDEPTH];
  883. YYSTYPE *yyvs = yyvsa;
  884. register YYSTYPE *yyvsp;
  885. /* The location stack. */
  886. YYLTYPE yylsa[YYINITDEPTH];
  887. YYLTYPE *yyls = yylsa;
  888. YYLTYPE *yylsp;
  889. /* The locations where the error started and ended. */
  890. YYLTYPE yyerror_range[2];
  891. #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
  892. YYSIZE_T yystacksize = YYINITDEPTH;
  893. /* The variables used to return semantic value and location from the
  894. action routines. */
  895. YYSTYPE yyval;
  896. YYLTYPE yyloc;
  897. /* When reducing, the number of symbols on the RHS of the reduced
  898. rule. */
  899. int yylen;
  900. YYDPRINTF ((stderr, "Starting parse\n"));
  901. yystate = 0;
  902. yyerrstatus = 0;
  903. yynerrs = 0;
  904. yychar = YYEMPTY; /* Cause a token to be read. */
  905. /* Initialize stack pointers.
  906. Waste one element of value and location stack
  907. so that they stay on the same level as the state stack.
  908. The wasted elements are never initialized. */
  909. yyssp = yyss;
  910. yyvsp = yyvs;
  911. yylsp = yyls;
  912. #if YYLTYPE_IS_TRIVIAL
  913. /* Initialize the default location before parsing starts. */
  914. yylloc.first_line = yylloc.last_line = 1;
  915. yylloc.first_column = yylloc.last_column = 0;
  916. #endif
  917. yyvsp[0] = yylval;
  918. yylsp[0] = yylloc;
  919. goto yysetstate;
  920. /*------------------------------------------------------------.
  921. | yynewstate -- Push a new state, which is found in yystate. |
  922. `------------------------------------------------------------*/
  923. yynewstate:
  924. /* In all cases, when you get here, the value and location stacks
  925. have just been pushed. so pushing a state here evens the stacks.
  926. */
  927. yyssp++;
  928. yysetstate:
  929. *yyssp = yystate;
  930. if (yyss + yystacksize - 1 <= yyssp)
  931. {
  932. /* Get the current used size of the three stacks, in elements. */
  933. YYSIZE_T yysize = yyssp - yyss + 1;
  934. #ifdef yyoverflow
  935. {
  936. /* Give user a chance to reallocate the stack. Use copies of
  937. these so that the &'s don't force the real ones into
  938. memory. */
  939. YYSTYPE *yyvs1 = yyvs;
  940. short int *yyss1 = yyss;
  941. YYLTYPE *yyls1 = yyls;
  942. /* Each stack pointer address is followed by the size of the
  943. data in use in that stack, in bytes. This used to be a
  944. conditional around just the two extra args, but that might
  945. be undefined if yyoverflow is a macro. */
  946. yyoverflow ("parser stack overflow",
  947. &yyss1, yysize * sizeof (*yyssp),
  948. &yyvs1, yysize * sizeof (*yyvsp),
  949. &yyls1, yysize * sizeof (*yylsp),
  950. &yystacksize);
  951. yyls = yyls1;
  952. yyss = yyss1;
  953. yyvs = yyvs1;
  954. }
  955. #else /* no yyoverflow */
  956. # ifndef YYSTACK_RELOCATE
  957. goto yyoverflowlab;
  958. # else
  959. /* Extend the stack our own way. */
  960. if (YYMAXDEPTH <= yystacksize)
  961. goto yyoverflowlab;
  962. yystacksize *= 2;
  963. if (YYMAXDEPTH < yystacksize)
  964. yystacksize = YYMAXDEPTH;
  965. {
  966. short int *yyss1 = yyss;
  967. union yyalloc *yyptr =
  968. (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  969. if (! yyptr)
  970. goto yyoverflowlab;
  971. YYSTACK_RELOCATE (yyss);
  972. YYSTACK_RELOCATE (yyvs);
  973. YYSTACK_RELOCATE (yyls);
  974. # undef YYSTACK_RELOCATE
  975. if (yyss1 != yyssa)
  976. YYSTACK_FREE (yyss1);
  977. }
  978. # endif
  979. #endif /* no yyoverflow */
  980. yyssp = yyss + yysize - 1;
  981. yyvsp = yyvs + yysize - 1;
  982. yylsp = yyls + yysize - 1;
  983. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  984. (unsigned long int) yystacksize));
  985. if (yyss + yystacksize - 1 <= yyssp)
  986. YYABORT;
  987. }
  988. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  989. goto yybackup;
  990. /*-----------.
  991. | yybackup. |
  992. `-----------*/
  993. yybackup:
  994. /* Do appropriate processing given the current state. */
  995. /* Read a look-ahead token if we need one and don't already have one. */
  996. /* yyresume: */
  997. /* First try to decide what to do without reference to look-ahead token. */
  998. yyn = yypact[yystate];
  999. if (yyn == YYPACT_NINF)
  1000. goto yydefault;
  1001. /* Not known => get a look-ahead token if don't already have one. */
  1002. /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
  1003. if (yychar == YYEMPTY)
  1004. {
  1005. YYDPRINTF ((stderr, "Reading a token: "));
  1006. yychar = YYLEX;
  1007. }
  1008. if (yychar <= YYEOF)
  1009. {
  1010. yychar = yytoken = YYEOF;
  1011. YYDPRINTF ((stderr, "Now at end of input.\n"));
  1012. }
  1013. else
  1014. {
  1015. yytoken = YYTRANSLATE (yychar);
  1016. YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1017. }
  1018. /* If the proper action on seeing token YYTOKEN is to reduce or to
  1019. detect an error, take that action. */
  1020. yyn += yytoken;
  1021. if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1022. goto yydefault;
  1023. yyn = yytable[yyn];
  1024. if (yyn <= 0)
  1025. {
  1026. if (yyn == 0 || yyn == YYTABLE_NINF)
  1027. goto yyerrlab;
  1028. yyn = -yyn;
  1029. goto yyreduce;
  1030. }
  1031. if (yyn == YYFINAL)
  1032. YYACCEPT;
  1033. /* Shift the look-ahead token. */
  1034. YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1035. /* Discard the token being shifted unless it is eof. */
  1036. if (yychar != YYEOF)
  1037. yychar = YYEMPTY;
  1038. *++yyvsp = yylval;
  1039. *++yylsp = yylloc;
  1040. /* Count tokens shifted since error; after three, turn off error
  1041. status. */
  1042. if (yyerrstatus)
  1043. yyerrstatus--;
  1044. yystate = yyn;
  1045. goto yynewstate;
  1046. /*-----------------------------------------------------------.
  1047. | yydefault -- do the default action for the current state. |
  1048. `-----------------------------------------------------------*/
  1049. yydefault:
  1050. yyn = yydefact[yystate];
  1051. if (yyn == 0)
  1052. goto yyerrlab;
  1053. goto yyreduce;
  1054. /*-----------------------------.
  1055. | yyreduce -- Do a reduction. |
  1056. `-----------------------------*/
  1057. yyreduce:
  1058. /* yyn is the number of a rule to reduce with. */
  1059. yylen = yyr2[yyn];
  1060. /* If YYLEN is nonzero, implement the default value of the action:
  1061. `$$ = $1'.
  1062. Otherwise, the following line sets YYVAL to garbage.
  1063. This behavior is undocumented and Bison
  1064. users should not rely upon it. Assigning to YYVAL
  1065. unconditionally makes the parser a bit smaller, and it avoids a
  1066. GCC warning that YYVAL may be used uninitialized. */
  1067. yyval = yyvsp[1-yylen];
  1068. /* Default location. */
  1069. YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
  1070. YY_REDUCE_PRINT (yyn);
  1071. switch (yyn)
  1072. {
  1073. case 2:
  1074. #line 165 "ast_expr2.y"
  1075. { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
  1076. ((struct parse_io *)parseio)->val->type = (yyvsp[0].val)->type;
  1077. if( (yyvsp[0].val)->type == AST_EXPR_integer )
  1078. ((struct parse_io *)parseio)->val->u.i = (yyvsp[0].val)->u.i;
  1079. else
  1080. ((struct parse_io *)parseio)->val->u.s = (yyvsp[0].val)->u.s;
  1081. free((yyvsp[0].val));
  1082. ;}
  1083. break;
  1084. case 3:
  1085. #line 175 "ast_expr2.y"
  1086. { (yyval.val)= (yyvsp[0].val);;}
  1087. break;
  1088. case 4:
  1089. #line 176 "ast_expr2.y"
  1090. { (yyval.val) = (yyvsp[-1].val);
  1091. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1092. (yyloc).first_line=0; (yyloc).last_line=0;
  1093. DESTROY((yyvsp[-2].val)); DESTROY((yyvsp[0].val)); ;}
  1094. break;
  1095. case 5:
  1096. #line 180 "ast_expr2.y"
  1097. { (yyval.val) = op_or ((yyvsp[-2].val), (yyvsp[0].val));
  1098. DESTROY((yyvsp[-1].val));
  1099. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1100. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1101. break;
  1102. case 6:
  1103. #line 184 "ast_expr2.y"
  1104. { (yyval.val) = op_and ((yyvsp[-2].val), (yyvsp[0].val));
  1105. DESTROY((yyvsp[-1].val));
  1106. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1107. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1108. break;
  1109. case 7:
  1110. #line 188 "ast_expr2.y"
  1111. { (yyval.val) = op_eq ((yyvsp[-2].val), (yyvsp[0].val));
  1112. DESTROY((yyvsp[-1].val));
  1113. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1114. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1115. break;
  1116. case 8:
  1117. #line 192 "ast_expr2.y"
  1118. { (yyval.val) = op_gt ((yyvsp[-2].val), (yyvsp[0].val));
  1119. DESTROY((yyvsp[-1].val));
  1120. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1121. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1122. break;
  1123. case 9:
  1124. #line 196 "ast_expr2.y"
  1125. { (yyval.val) = op_lt ((yyvsp[-2].val), (yyvsp[0].val));
  1126. DESTROY((yyvsp[-1].val));
  1127. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1128. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1129. break;
  1130. case 10:
  1131. #line 200 "ast_expr2.y"
  1132. { (yyval.val) = op_ge ((yyvsp[-2].val), (yyvsp[0].val));
  1133. DESTROY((yyvsp[-1].val));
  1134. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1135. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1136. break;
  1137. case 11:
  1138. #line 204 "ast_expr2.y"
  1139. { (yyval.val) = op_le ((yyvsp[-2].val), (yyvsp[0].val));
  1140. DESTROY((yyvsp[-1].val));
  1141. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1142. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1143. break;
  1144. case 12:
  1145. #line 208 "ast_expr2.y"
  1146. { (yyval.val) = op_ne ((yyvsp[-2].val), (yyvsp[0].val));
  1147. DESTROY((yyvsp[-1].val));
  1148. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1149. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1150. break;
  1151. case 13:
  1152. #line 212 "ast_expr2.y"
  1153. { (yyval.val) = op_plus ((yyvsp[-2].val), (yyvsp[0].val));
  1154. DESTROY((yyvsp[-1].val));
  1155. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1156. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1157. break;
  1158. case 14:
  1159. #line 216 "ast_expr2.y"
  1160. { (yyval.val) = op_minus ((yyvsp[-2].val), (yyvsp[0].val));
  1161. DESTROY((yyvsp[-1].val));
  1162. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1163. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1164. break;
  1165. case 15:
  1166. #line 220 "ast_expr2.y"
  1167. { (yyval.val) = op_negate ((yyvsp[0].val));
  1168. DESTROY((yyvsp[-1].val));
  1169. (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1170. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1171. break;
  1172. case 16:
  1173. #line 224 "ast_expr2.y"
  1174. { (yyval.val) = op_compl ((yyvsp[0].val));
  1175. DESTROY((yyvsp[-1].val));
  1176. (yyloc).first_column = (yylsp[-1]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1177. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1178. break;
  1179. case 17:
  1180. #line 228 "ast_expr2.y"
  1181. { (yyval.val) = op_times ((yyvsp[-2].val), (yyvsp[0].val));
  1182. DESTROY((yyvsp[-1].val));
  1183. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1184. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1185. break;
  1186. case 18:
  1187. #line 232 "ast_expr2.y"
  1188. { (yyval.val) = op_div ((yyvsp[-2].val), (yyvsp[0].val));
  1189. DESTROY((yyvsp[-1].val));
  1190. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1191. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1192. break;
  1193. case 19:
  1194. #line 236 "ast_expr2.y"
  1195. { (yyval.val) = op_rem ((yyvsp[-2].val), (yyvsp[0].val));
  1196. DESTROY((yyvsp[-1].val));
  1197. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1198. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1199. break;
  1200. case 20:
  1201. #line 240 "ast_expr2.y"
  1202. { (yyval.val) = op_colon ((yyvsp[-2].val), (yyvsp[0].val));
  1203. DESTROY((yyvsp[-1].val));
  1204. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1205. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1206. break;
  1207. case 21:
  1208. #line 244 "ast_expr2.y"
  1209. { (yyval.val) = op_eqtilde ((yyvsp[-2].val), (yyvsp[0].val));
  1210. DESTROY((yyvsp[-1].val));
  1211. (yyloc).first_column = (yylsp[-2]).first_column; (yyloc).last_column = (yylsp[0]).last_column;
  1212. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1213. break;
  1214. case 22:
  1215. #line 248 "ast_expr2.y"
  1216. { (yyval.val) = op_cond ((yyvsp[-4].val), (yyvsp[-2].val), (yyvsp[0].val));
  1217. DESTROY((yyvsp[-3].val));
  1218. DESTROY((yyvsp[-1].val));
  1219. (yyloc).first_column = (yylsp[-4]).first_column; (yyloc).last_column = (yylsp[-2]).last_column;
  1220. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1221. break;
  1222. }
  1223. /* Line 1037 of yacc.c. */
  1224. #line 1445 "ast_expr2.c"
  1225. yyvsp -= yylen;
  1226. yyssp -= yylen;
  1227. yylsp -= yylen;
  1228. YY_STACK_PRINT (yyss, yyssp);
  1229. *++yyvsp = yyval;
  1230. *++yylsp = yyloc;
  1231. /* Now `shift' the result of the reduction. Determine what state
  1232. that goes to, based on the state we popped back to and the rule
  1233. number reduced by. */
  1234. yyn = yyr1[yyn];
  1235. yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  1236. if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1237. yystate = yytable[yystate];
  1238. else
  1239. yystate = yydefgoto[yyn - YYNTOKENS];
  1240. goto yynewstate;
  1241. /*------------------------------------.
  1242. | yyerrlab -- here on detecting error |
  1243. `------------------------------------*/
  1244. yyerrlab:
  1245. /* If not already recovering from an error, report this error. */
  1246. if (!yyerrstatus)
  1247. {
  1248. ++yynerrs;
  1249. #if YYERROR_VERBOSE
  1250. yyn = yypact[yystate];
  1251. if (YYPACT_NINF < yyn && yyn < YYLAST)
  1252. {
  1253. YYSIZE_T yysize = 0;
  1254. int yytype = YYTRANSLATE (yychar);
  1255. const char* yyprefix;
  1256. char *yymsg;
  1257. int yyx;
  1258. /* Start YYX at -YYN if negative to avoid negative indexes in
  1259. YYCHECK. */
  1260. int yyxbegin = yyn < 0 ? -yyn : 0;
  1261. /* Stay within bounds of both yycheck and yytname. */
  1262. int yychecklim = YYLAST - yyn;
  1263. int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1264. int yycount = 0;
  1265. yyprefix = ", expecting ";
  1266. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1267. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1268. {
  1269. yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
  1270. yycount += 1;
  1271. if (yycount == 5)
  1272. {
  1273. yysize = 0;
  1274. break;
  1275. }
  1276. }
  1277. yysize += (sizeof ("syntax error, unexpected ")
  1278. + yystrlen (yytname[yytype]));
  1279. yymsg = (char *) YYSTACK_ALLOC (yysize);
  1280. if (yymsg != 0)
  1281. {
  1282. char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
  1283. yyp = yystpcpy (yyp, yytname[yytype]);
  1284. if (yycount < 5)
  1285. {
  1286. yyprefix = ", expecting ";
  1287. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1288. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1289. {
  1290. yyp = yystpcpy (yyp, yyprefix);
  1291. yyp = yystpcpy (yyp, yytname[yyx]);
  1292. yyprefix = " or ";
  1293. }
  1294. }
  1295. yyerror (yymsg);
  1296. YYSTACK_FREE (yymsg);
  1297. }
  1298. else
  1299. yyerror ("syntax error; also virtual memory exhausted");
  1300. }
  1301. else
  1302. #endif /* YYERROR_VERBOSE */
  1303. yyerror ("syntax error");
  1304. }
  1305. yyerror_range[0] = yylloc;
  1306. if (yyerrstatus == 3)
  1307. {
  1308. /* If just tried and failed to reuse look-ahead token after an
  1309. error, discard it. */
  1310. if (yychar <= YYEOF)
  1311. {
  1312. /* If at end of input, pop the error token,
  1313. then the rest of the stack, then return failure. */
  1314. if (yychar == YYEOF)
  1315. for (;;)
  1316. {
  1317. yyerror_range[0] = *yylsp;
  1318. YYPOPSTACK;
  1319. if (yyssp == yyss)
  1320. YYABORT;
  1321. yydestruct ("Error: popping",
  1322. yystos[*yyssp], yyvsp, yylsp);
  1323. }
  1324. }
  1325. else
  1326. {
  1327. yydestruct ("Error: discarding", yytoken, &yylval, &yylloc);
  1328. yychar = YYEMPTY;
  1329. }
  1330. }
  1331. /* Else will try to reuse look-ahead token after shifting the error
  1332. token. */
  1333. goto yyerrlab1;
  1334. /*---------------------------------------------------.
  1335. | yyerrorlab -- error raised explicitly by YYERROR. |
  1336. `---------------------------------------------------*/
  1337. yyerrorlab:
  1338. #ifdef __GNUC__
  1339. /* Pacify GCC when the user code never invokes YYERROR and the label
  1340. yyerrorlab therefore never appears in user code. */
  1341. if (0)
  1342. goto yyerrorlab;
  1343. #endif
  1344. yyerror_range[0] = yylsp[1-yylen];
  1345. yylsp -= yylen;
  1346. yyvsp -= yylen;
  1347. yyssp -= yylen;
  1348. yystate = *yyssp;
  1349. goto yyerrlab1;
  1350. /*-------------------------------------------------------------.
  1351. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  1352. `-------------------------------------------------------------*/
  1353. yyerrlab1:
  1354. yyerrstatus = 3; /* Each real token shifted decrements this. */
  1355. for (;;)
  1356. {
  1357. yyn = yypact[yystate];
  1358. if (yyn != YYPACT_NINF)
  1359. {
  1360. yyn += YYTERROR;
  1361. if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  1362. {
  1363. yyn = yytable[yyn];
  1364. if (0 < yyn)
  1365. break;
  1366. }
  1367. }
  1368. /* Pop the current state because it cannot handle the error token. */
  1369. if (yyssp == yyss)
  1370. YYABORT;
  1371. yyerror_range[0] = *yylsp;
  1372. yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp);
  1373. YYPOPSTACK;
  1374. yystate = *yyssp;
  1375. YY_STACK_PRINT (yyss, yyssp);
  1376. }
  1377. if (yyn == YYFINAL)
  1378. YYACCEPT;
  1379. *++yyvsp = yylval;
  1380. yyerror_range[1] = yylloc;
  1381. /* Using YYLLOC is tempting, but would change the location of
  1382. the look-ahead. YYLOC is available though. */
  1383. YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
  1384. *++yylsp = yyloc;
  1385. /* Shift the error token. */
  1386. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  1387. yystate = yyn;
  1388. goto yynewstate;
  1389. /*-------------------------------------.
  1390. | yyacceptlab -- YYACCEPT comes here. |
  1391. `-------------------------------------*/
  1392. yyacceptlab:
  1393. yyresult = 0;
  1394. goto yyreturn;
  1395. /*-----------------------------------.
  1396. | yyabortlab -- YYABORT comes here. |
  1397. `-----------------------------------*/
  1398. yyabortlab:
  1399. yydestruct ("Error: discarding lookahead",
  1400. yytoken, &yylval, &yylloc);
  1401. yychar = YYEMPTY;
  1402. yyresult = 1;
  1403. goto yyreturn;
  1404. #ifndef yyoverflow
  1405. /*----------------------------------------------.
  1406. | yyoverflowlab -- parser overflow comes here. |
  1407. `----------------------------------------------*/
  1408. yyoverflowlab:
  1409. yyerror ("parser stack overflow");
  1410. yyresult = 2;
  1411. /* Fall through. */
  1412. #endif
  1413. yyreturn:
  1414. #ifndef yyoverflow
  1415. if (yyss != yyssa)
  1416. YYSTACK_FREE (yyss);
  1417. #endif
  1418. return yyresult;
  1419. }
  1420. #line 255 "ast_expr2.y"
  1421. static struct val *
  1422. make_integer (quad_t i)
  1423. {
  1424. struct val *vp;
  1425. vp = (struct val *) malloc (sizeof (*vp));
  1426. if (vp == NULL) {
  1427. ast_log(LOG_WARNING, "malloc() failed\n");
  1428. return(NULL);
  1429. }
  1430. vp->type = AST_EXPR_integer;
  1431. vp->u.i = i;
  1432. return vp;
  1433. }
  1434. static struct val *
  1435. make_str (const char *s)
  1436. {
  1437. struct val *vp;
  1438. size_t i;
  1439. int isint;
  1440. vp = (struct val *) malloc (sizeof (*vp));
  1441. if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
  1442. ast_log(LOG_WARNING,"malloc() failed\n");
  1443. return(NULL);
  1444. }
  1445. for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
  1446. isint && i < strlen(s);
  1447. i++)
  1448. {
  1449. if(!isdigit(s[i]))
  1450. isint = 0;
  1451. }
  1452. if (isint)
  1453. vp->type = AST_EXPR_numeric_string;
  1454. else
  1455. vp->type = AST_EXPR_string;
  1456. return vp;
  1457. }
  1458. static void
  1459. free_value (struct val *vp)
  1460. {
  1461. if (vp==NULL) {
  1462. return;
  1463. }
  1464. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  1465. free (vp->u.s);
  1466. free(vp);
  1467. }
  1468. static quad_t
  1469. to_integer (struct val *vp)
  1470. {
  1471. quad_t i;
  1472. if (vp == NULL) {
  1473. ast_log(LOG_WARNING,"vp==NULL in to_integer()\n");
  1474. return(0);
  1475. }
  1476. if (vp->type == AST_EXPR_integer)
  1477. return 1;
  1478. if (vp->type == AST_EXPR_string)
  1479. return 0;
  1480. /* vp->type == AST_EXPR_numeric_string, make it numeric */
  1481. errno = 0;
  1482. i = strtoll(vp->u.s, (char**)NULL, 10);
  1483. if (errno != 0) {
  1484. ast_log(LOG_WARNING,"Conversion of %s to integer under/overflowed!\n", vp->u.s);
  1485. free(vp->u.s);
  1486. vp->u.s = 0;
  1487. return(0);
  1488. }
  1489. free (vp->u.s);
  1490. vp->u.i = i;
  1491. vp->type = AST_EXPR_integer;
  1492. return 1;
  1493. }
  1494. static void
  1495. strip_quotes(struct val *vp)
  1496. {
  1497. if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
  1498. return;
  1499. if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
  1500. {
  1501. char *f, *t;
  1502. f = vp->u.s;
  1503. t = vp->u.s;
  1504. while( *f )
  1505. {
  1506. if( *f && *f != '"' )
  1507. *t++ = *f++;
  1508. else
  1509. f++;
  1510. }
  1511. *t = *f;
  1512. }
  1513. }
  1514. static void
  1515. to_string (struct val *vp)
  1516. {
  1517. char *tmp;
  1518. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  1519. return;
  1520. tmp = malloc ((size_t)25);
  1521. if (tmp == NULL) {
  1522. ast_log(LOG_WARNING,"malloc() failed\n");
  1523. return;
  1524. }
  1525. sprintf(tmp, "%ld", (long int) vp->u.i);
  1526. vp->type = AST_EXPR_string;
  1527. vp->u.s = tmp;
  1528. }
  1529. static int
  1530. isstring (struct val *vp)
  1531. {
  1532. /* only TRUE if this string is not a valid integer */
  1533. return (vp->type == AST_EXPR_string);
  1534. }
  1535. static int
  1536. is_zero_or_null (struct val *vp)
  1537. {
  1538. if (vp->type == AST_EXPR_integer) {
  1539. return (vp->u.i == 0);
  1540. } else {
  1541. return (*vp->u.s == 0 || (to_integer (vp) && vp->u.i == 0));
  1542. }
  1543. /* NOTREACHED */
  1544. }
  1545. #ifdef STANDALONE
  1546. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
  1547. {
  1548. va_list vars;
  1549. va_start(vars,fmt);
  1550. printf("LOG: lev:%d file:%s line:%d func: %s ",
  1551. level, file, line, function);
  1552. vprintf(fmt, vars);
  1553. fflush(stdout);
  1554. va_end(vars);
  1555. }
  1556. int main(int argc,char **argv) {
  1557. char s[4096];
  1558. if (ast_expr(argv[1], s, sizeof(s)))
  1559. printf("=====%s======\n",s);
  1560. else
  1561. printf("No result\n");
  1562. }
  1563. #endif
  1564. #undef ast_yyerror
  1565. #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
  1566. /* I put the ast_yyerror func in the flex input file,
  1567. because it refers to the buffer state. Best to
  1568. let it access the BUFFER stuff there and not trying
  1569. define all the structs, macros etc. in this file! */
  1570. static struct val *
  1571. op_or (struct val *a, struct val *b)
  1572. {
  1573. if (is_zero_or_null (a)) {
  1574. free_value (a);
  1575. return (b);
  1576. } else {
  1577. free_value (b);
  1578. return (a);
  1579. }
  1580. }
  1581. static struct val *
  1582. op_and (struct val *a, struct val *b)
  1583. {
  1584. if (is_zero_or_null (a) || is_zero_or_null (b)) {
  1585. free_value (a);
  1586. free_value (b);
  1587. return (make_integer ((quad_t)0));
  1588. } else {
  1589. free_value (b);
  1590. return (a);
  1591. }
  1592. }
  1593. static struct val *
  1594. op_eq (struct val *a, struct val *b)
  1595. {
  1596. struct val *r;
  1597. if (isstring (a) || isstring (b)) {
  1598. to_string (a);
  1599. to_string (b);
  1600. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) == 0));
  1601. } else {
  1602. #ifdef DEBUG_FOR_CONVERSIONS
  1603. char buffer[2000];
  1604. sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
  1605. #endif
  1606. (void)to_integer(a);
  1607. (void)to_integer(b);
  1608. #ifdef DEBUG_FOR_CONVERSIONS
  1609. ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
  1610. #endif
  1611. r = make_integer ((quad_t)(a->u.i == b->u.i));
  1612. }
  1613. free_value (a);
  1614. free_value (b);
  1615. return r;
  1616. }
  1617. static struct val *
  1618. op_gt (struct val *a, struct val *b)
  1619. {
  1620. struct val *r;
  1621. if (isstring (a) || isstring (b)) {
  1622. to_string (a);
  1623. to_string (b);
  1624. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) > 0));
  1625. } else {
  1626. (void)to_integer(a);
  1627. (void)to_integer(b);
  1628. r = make_integer ((quad_t)(a->u.i > b->u.i));
  1629. }
  1630. free_value (a);
  1631. free_value (b);
  1632. return r;
  1633. }
  1634. static struct val *
  1635. op_lt (struct val *a, struct val *b)
  1636. {
  1637. struct val *r;
  1638. if (isstring (a) || isstring (b)) {
  1639. to_string (a);
  1640. to_string (b);
  1641. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) < 0));
  1642. } else {
  1643. (void)to_integer(a);
  1644. (void)to_integer(b);
  1645. r = make_integer ((quad_t)(a->u.i < b->u.i));
  1646. }
  1647. free_value (a);
  1648. free_value (b);
  1649. return r;
  1650. }
  1651. static struct val *
  1652. op_ge (struct val *a, struct val *b)
  1653. {
  1654. struct val *r;
  1655. if (isstring (a) || isstring (b)) {
  1656. to_string (a);
  1657. to_string (b);
  1658. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) >= 0));
  1659. } else {
  1660. (void)to_integer(a);
  1661. (void)to_integer(b);
  1662. r = make_integer ((quad_t)(a->u.i >= b->u.i));
  1663. }
  1664. free_value (a);
  1665. free_value (b);
  1666. return r;
  1667. }
  1668. static struct val *
  1669. op_le (struct val *a, struct val *b)
  1670. {
  1671. struct val *r;
  1672. if (isstring (a) || isstring (b)) {
  1673. to_string (a);
  1674. to_string (b);
  1675. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) <= 0));
  1676. } else {
  1677. (void)to_integer(a);
  1678. (void)to_integer(b);
  1679. r = make_integer ((quad_t)(a->u.i <= b->u.i));
  1680. }
  1681. free_value (a);
  1682. free_value (b);
  1683. return r;
  1684. }
  1685. static struct val *
  1686. op_cond (struct val *a, struct val *b, struct val *c)
  1687. {
  1688. struct val *r;
  1689. if( isstring(a) )
  1690. {
  1691. if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
  1692. {
  1693. free_value(a);
  1694. free_value(c);
  1695. r = b;
  1696. }
  1697. else
  1698. {
  1699. free_value(a);
  1700. free_value(b);
  1701. r = c;
  1702. }
  1703. }
  1704. else
  1705. {
  1706. (void)to_integer(a);
  1707. if( a->u.i )
  1708. {
  1709. free_value(a);
  1710. free_value(c);
  1711. r = b;
  1712. }
  1713. else
  1714. {
  1715. free_value(a);
  1716. free_value(b);
  1717. r = c;
  1718. }
  1719. }
  1720. return r;
  1721. }
  1722. static struct val *
  1723. op_ne (struct val *a, struct val *b)
  1724. {
  1725. struct val *r;
  1726. if (isstring (a) || isstring (b)) {
  1727. to_string (a);
  1728. to_string (b);
  1729. r = make_integer ((quad_t)(strcoll (a->u.s, b->u.s) != 0));
  1730. } else {
  1731. (void)to_integer(a);
  1732. (void)to_integer(b);
  1733. r = make_integer ((quad_t)(a->u.i != b->u.i));
  1734. }
  1735. free_value (a);
  1736. free_value (b);
  1737. return r;
  1738. }
  1739. static int
  1740. chk_plus (quad_t a, quad_t b, quad_t r)
  1741. {
  1742. /* sum of two positive numbers must be positive */
  1743. if (a > 0 && b > 0 && r <= 0)
  1744. return 1;
  1745. /* sum of two negative numbers must be negative */
  1746. if (a < 0 && b < 0 && r >= 0)
  1747. return 1;
  1748. /* all other cases are OK */
  1749. return 0;
  1750. }
  1751. static struct val *
  1752. op_plus (struct val *a, struct val *b)
  1753. {
  1754. struct val *r;
  1755. if (!to_integer (a)) {
  1756. ast_log(LOG_WARNING,"non-numeric argument\n");
  1757. if (!to_integer (b)) {
  1758. free_value(a);
  1759. free_value(b);
  1760. return make_integer(0);
  1761. } else {
  1762. free_value(a);
  1763. return (b);
  1764. }
  1765. } else if (!to_integer(b)) {
  1766. free_value(b);
  1767. return (a);
  1768. }
  1769. r = make_integer (/*(quad_t)*/(a->u.i + b->u.i));
  1770. if (chk_plus (a->u.i, b->u.i, r->u.i)) {
  1771. ast_log(LOG_WARNING,"overflow\n");
  1772. }
  1773. free_value (a);
  1774. free_value (b);
  1775. return r;
  1776. }
  1777. static int
  1778. chk_minus (quad_t a, quad_t b, quad_t r)
  1779. {
  1780. /* special case subtraction of QUAD_MIN */
  1781. if (b == QUAD_MIN) {
  1782. if (a >= 0)
  1783. return 1;
  1784. else
  1785. return 0;
  1786. }
  1787. /* this is allowed for b != QUAD_MIN */
  1788. return chk_plus (a, -b, r);
  1789. }
  1790. static struct val *
  1791. op_minus (struct val *a, struct val *b)
  1792. {
  1793. struct val *r;
  1794. if (!to_integer (a)) {
  1795. ast_log(LOG_WARNING, "non-numeric argument\n");
  1796. if (!to_integer (b)) {
  1797. free_value(a);
  1798. free_value(b);
  1799. return make_integer(0);
  1800. } else {
  1801. r = make_integer(0 - b->u.i);
  1802. free_value(a);
  1803. free_value(b);
  1804. return (r);
  1805. }
  1806. } else if (!to_integer(b)) {
  1807. ast_log(LOG_WARNING, "non-numeric argument\n");
  1808. free_value(b);
  1809. return (a);
  1810. }
  1811. r = make_integer (/*(quad_t)*/(a->u.i - b->u.i));
  1812. if (chk_minus (a->u.i, b->u.i, r->u.i)) {
  1813. ast_log(LOG_WARNING, "overflow\n");
  1814. }
  1815. free_value (a);
  1816. free_value (b);
  1817. return r;
  1818. }
  1819. static struct val *
  1820. op_negate (struct val *a)
  1821. {
  1822. struct val *r;
  1823. if (!to_integer (a) ) {
  1824. free_value(a);
  1825. ast_log(LOG_WARNING, "non-numeric argument\n");
  1826. return make_integer(0);
  1827. }
  1828. r = make_integer (/*(quad_t)*/(- a->u.i));
  1829. if (chk_minus (0, a->u.i, r->u.i)) {
  1830. ast_log(LOG_WARNING, "overflow\n");
  1831. }
  1832. free_value (a);
  1833. return r;
  1834. }
  1835. static struct val *
  1836. op_compl (struct val *a)
  1837. {
  1838. int v1 = 1;
  1839. struct val *r;
  1840. if( !a )
  1841. {
  1842. v1 = 0;
  1843. }
  1844. else
  1845. {
  1846. switch( a->type )
  1847. {
  1848. case AST_EXPR_integer:
  1849. if( a->u.i == 0 )
  1850. v1 = 0;
  1851. break;
  1852. case AST_EXPR_string:
  1853. if( a->u.s == 0 )
  1854. v1 = 0;
  1855. else
  1856. {
  1857. if( a->u.s[0] == 0 )
  1858. v1 = 0;
  1859. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  1860. v1 = 0;
  1861. }
  1862. break;
  1863. case AST_EXPR_numeric_string:
  1864. if( a->u.s == 0 )
  1865. v1 = 0;
  1866. else
  1867. {
  1868. if( a->u.s[0] == 0 )
  1869. v1 = 0;
  1870. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  1871. v1 = 0;
  1872. }
  1873. break;
  1874. }
  1875. }
  1876. r = make_integer (!v1);
  1877. free_value (a);
  1878. return r;
  1879. }
  1880. static int
  1881. chk_times (quad_t a, quad_t b, quad_t r)
  1882. {
  1883. /* special case: first operand is 0, no overflow possible */
  1884. if (a == 0)
  1885. return 0;
  1886. /* cerify that result of division matches second operand */
  1887. if (r / a != b)
  1888. return 1;
  1889. return 0;
  1890. }
  1891. static struct val *
  1892. op_times (struct val *a, struct val *b)
  1893. {
  1894. struct val *r;
  1895. if (!to_integer (a) || !to_integer (b)) {
  1896. free_value(a);
  1897. free_value(b);
  1898. ast_log(LOG_WARNING, "non-numeric argument\n");
  1899. return(make_integer(0));
  1900. }
  1901. r = make_integer (/*(quad_t)*/(a->u.i * b->u.i));
  1902. if (chk_times (a->u.i, b->u.i, r->u.i)) {
  1903. ast_log(LOG_WARNING, "overflow\n");
  1904. }
  1905. free_value (a);
  1906. free_value (b);
  1907. return (r);
  1908. }
  1909. static int
  1910. chk_div (quad_t a, quad_t b)
  1911. {
  1912. /* div by zero has been taken care of before */
  1913. /* only QUAD_MIN / -1 causes overflow */
  1914. if (a == QUAD_MIN && b == -1)
  1915. return 1;
  1916. /* everything else is OK */
  1917. return 0;
  1918. }
  1919. static struct val *
  1920. op_div (struct val *a, struct val *b)
  1921. {
  1922. struct val *r;
  1923. if (!to_integer (a)) {
  1924. free_value(a);
  1925. free_value(b);
  1926. ast_log(LOG_WARNING, "non-numeric argument\n");
  1927. return make_integer(0);
  1928. } else if (!to_integer (b)) {
  1929. free_value(a);
  1930. free_value(b);
  1931. ast_log(LOG_WARNING, "non-numeric argument\n");
  1932. return make_integer(INT_MAX);
  1933. }
  1934. if (b->u.i == 0) {
  1935. ast_log(LOG_WARNING, "division by zero\n");
  1936. free_value(a);
  1937. free_value(b);
  1938. return make_integer(INT_MAX);
  1939. }
  1940. r = make_integer (/*(quad_t)*/(a->u.i / b->u.i));
  1941. if (chk_div (a->u.i, b->u.i)) {
  1942. ast_log(LOG_WARNING, "overflow\n");
  1943. }
  1944. free_value (a);
  1945. free_value (b);
  1946. return r;
  1947. }
  1948. static struct val *
  1949. op_rem (struct val *a, struct val *b)
  1950. {
  1951. struct val *r;
  1952. if (!to_integer (a) || !to_integer (b)) {
  1953. ast_log(LOG_WARNING, "non-numeric argument\n");
  1954. free_value(a);
  1955. free_value(b);
  1956. return make_integer(0);
  1957. }
  1958. if (b->u.i == 0) {
  1959. ast_log(LOG_WARNING, "div by zero\n");
  1960. free_value(a);
  1961. return(b);
  1962. }
  1963. r = make_integer (/*(quad_t)*/(a->u.i % b->u.i));
  1964. /* chk_rem necessary ??? */
  1965. free_value (a);
  1966. free_value (b);
  1967. return r;
  1968. }
  1969. static struct val *
  1970. op_colon (struct val *a, struct val *b)
  1971. {
  1972. regex_t rp;
  1973. regmatch_t rm[2];
  1974. char errbuf[256];
  1975. int eval;
  1976. struct val *v;
  1977. /* coerce to both arguments to strings */
  1978. to_string(a);
  1979. to_string(b);
  1980. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  1981. strip_quotes(a);
  1982. strip_quotes(b);
  1983. /* compile regular expression */
  1984. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  1985. regerror (eval, &rp, errbuf, sizeof(errbuf));
  1986. ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
  1987. free_value(a);
  1988. free_value(b);
  1989. return make_str("");
  1990. }
  1991. /* compare string against pattern */
  1992. /* remember that patterns are anchored to the beginning of the line */
  1993. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
  1994. if (rm[1].rm_so >= 0) {
  1995. *(a->u.s + rm[1].rm_eo) = '\0';
  1996. v = make_str (a->u.s + rm[1].rm_so);
  1997. } else {
  1998. v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
  1999. }
  2000. } else {
  2001. if (rp.re_nsub == 0) {
  2002. v = make_integer ((quad_t)0);
  2003. } else {
  2004. v = make_str ("");
  2005. }
  2006. }
  2007. /* free arguments and pattern buffer */
  2008. free_value (a);
  2009. free_value (b);
  2010. regfree (&rp);
  2011. return v;
  2012. }
  2013. static struct val *
  2014. op_eqtilde (struct val *a, struct val *b)
  2015. {
  2016. regex_t rp;
  2017. regmatch_t rm[2];
  2018. char errbuf[256];
  2019. int eval;
  2020. struct val *v;
  2021. /* coerce to both arguments to strings */
  2022. to_string(a);
  2023. to_string(b);
  2024. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  2025. strip_quotes(a);
  2026. strip_quotes(b);
  2027. /* compile regular expression */
  2028. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  2029. regerror (eval, &rp, errbuf, sizeof(errbuf));
  2030. ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
  2031. free_value(a);
  2032. free_value(b);
  2033. return make_str("");
  2034. }
  2035. /* compare string against pattern */
  2036. /* remember that patterns are anchored to the beginning of the line */
  2037. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
  2038. if (rm[1].rm_so >= 0) {
  2039. *(a->u.s + rm[1].rm_eo) = '\0';
  2040. v = make_str (a->u.s + rm[1].rm_so);
  2041. } else {
  2042. v = make_integer ((quad_t)(rm[0].rm_eo - rm[0].rm_so));
  2043. }
  2044. } else {
  2045. if (rp.re_nsub == 0) {
  2046. v = make_integer ((quad_t)0);
  2047. } else {
  2048. v = make_str ("");
  2049. }
  2050. }
  2051. /* free arguments and pattern buffer */
  2052. free_value (a);
  2053. free_value (b);
  2054. regfree (&rp);
  2055. return v;
  2056. }