ast_expr2.c 59 KB

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