ast_expr2.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476
  1. /* A Bison parser, made by GNU Bison 2.3. */
  2. /* Skeleton implementation for Bison's Yacc-like parsers in C
  3. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  4. Free Software Foundation, Inc.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. /* As a special exception, you may create a larger work that contains
  18. part or all of the Bison parser skeleton and distribute that work
  19. under terms of your choice, so long as that work isn't itself a
  20. parser generator using the skeleton or a modified version thereof
  21. as a parser skeleton. Alternatively, if you modify or redistribute
  22. the parser skeleton itself, you may (at your option) remove this
  23. special exception, which will cause the skeleton and the resulting
  24. Bison output files to be licensed under the GNU General Public
  25. License without this special exception.
  26. This special exception was added by the Free Software Foundation in
  27. version 2.2 of Bison. */
  28. /* C LALR(1) parser skeleton written by Richard Stallman, by
  29. simplifying the original so-called "semantic" parser. */
  30. /* All symbols defined below should begin with yy or YY, to avoid
  31. infringing on user name space. This should be done even for local
  32. variables, as they might otherwise be expanded by user macros.
  33. There are some unavoidable exceptions within include files to
  34. define necessary library symbols; they are noted "INFRINGES ON
  35. USER NAME SPACE" below. */
  36. /* Identify Bison output. */
  37. #define YYBISON 1
  38. /* Bison version. */
  39. #define YYBISON_VERSION "2.3"
  40. /* Skeleton name. */
  41. #define YYSKELETON_NAME "yacc.c"
  42. /* Pure parsers. */
  43. #define YYPURE 1
  44. /* Using locations. */
  45. #define YYLSP_NEEDED 1
  46. /* Substitute the variable and function names. */
  47. #define yyparse ast_yyparse
  48. #define yylex ast_yylex
  49. #define yyerror ast_yyerror
  50. #define yylval ast_yylval
  51. #define yychar ast_yychar
  52. #define yydebug ast_yydebug
  53. #define yynerrs ast_yynerrs
  54. #define yylloc ast_yylloc
  55. /* Tokens. */
  56. #ifndef YYTOKENTYPE
  57. # define YYTOKENTYPE
  58. /* Put the tokens into the symbol table, so that GDB and other debuggers
  59. know about them. */
  60. enum yytokentype {
  61. TOK_COMMA = 258,
  62. TOK_COLONCOLON = 259,
  63. TOK_COND = 260,
  64. TOK_OR = 261,
  65. TOK_AND = 262,
  66. TOK_NE = 263,
  67. TOK_LE = 264,
  68. TOK_GE = 265,
  69. TOK_LT = 266,
  70. TOK_GT = 267,
  71. TOK_EQ = 268,
  72. TOK_MINUS = 269,
  73. TOK_PLUS = 270,
  74. TOK_MOD = 271,
  75. TOK_DIV = 272,
  76. TOK_MULT = 273,
  77. TOK_COMPL = 274,
  78. TOK_EQTILDE = 275,
  79. TOK_COLON = 276,
  80. TOK_LP = 277,
  81. TOK_RP = 278,
  82. TOKEN = 279
  83. };
  84. #endif
  85. /* Tokens. */
  86. #define TOK_COMMA 258
  87. #define TOK_COLONCOLON 259
  88. #define TOK_COND 260
  89. #define TOK_OR 261
  90. #define TOK_AND 262
  91. #define TOK_NE 263
  92. #define TOK_LE 264
  93. #define TOK_GE 265
  94. #define TOK_LT 266
  95. #define TOK_GT 267
  96. #define TOK_EQ 268
  97. #define TOK_MINUS 269
  98. #define TOK_PLUS 270
  99. #define TOK_MOD 271
  100. #define TOK_DIV 272
  101. #define TOK_MULT 273
  102. #define TOK_COMPL 274
  103. #define TOK_EQTILDE 275
  104. #define TOK_COLON 276
  105. #define TOK_LP 277
  106. #define TOK_RP 278
  107. #define TOKEN 279
  108. /* Copy the first part of user declarations. */
  109. #line 1 "ast_expr2.y"
  110. /* Written by Pace Willisson (pace@blitz.com)
  111. * and placed in the public domain.
  112. *
  113. * Largely rewritten by J.T. Conklin (jtc@wimsey.com)
  114. *
  115. * And then overhauled twice by Steve Murphy (murf@digium.com)
  116. * to add double-quoted strings, allow mult. spaces, improve
  117. * error messages, and then to fold in a flex scanner for the
  118. * yylex operation.
  119. *
  120. * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
  121. */
  122. #include "asterisk.h"
  123. #include <sys/types.h>
  124. #include <stdio.h>
  125. #if !defined(STANDALONE) && !defined(STANDALONE2) \
  126. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  127. #else
  128. #ifndef __USE_ISOC99
  129. #define __USE_ISOC99 1
  130. #endif
  131. #endif
  132. #ifdef __USE_ISOC99
  133. #define FP___PRINTF "%.18Lg"
  134. #define FP___TYPE long double
  135. #else
  136. #define FP___PRINTF "%.16g"
  137. #define FP___TYPE double
  138. #endif
  139. #ifdef HAVE_COSL
  140. #define FUNC_COS cosl
  141. #elif defined(HAVE_COS)
  142. #define FUNC_COS (long double)cos
  143. #endif
  144. #ifdef HAVE_SINL
  145. #define FUNC_SIN sinl
  146. #elif defined(HAVE_SIN)
  147. #define FUNC_SIN (long double)sin
  148. #endif
  149. #ifdef HAVE_TANL
  150. #define FUNC_TAN tanl
  151. #elif defined(HAVE_TAN)
  152. #define FUNC_TAN (long double)tan
  153. #endif
  154. #ifdef HAVE_ACOSL
  155. #define FUNC_ACOS acosl
  156. #elif defined(HAVE_ACOS)
  157. #define FUNC_ACOS (long double)acos
  158. #endif
  159. #ifdef HAVE_ASINL
  160. #define FUNC_ASIN asinl
  161. #elif defined(HAVE_ASIN)
  162. #define FUNC_ASIN (long double)asin
  163. #endif
  164. #ifdef HAVE_ATANL
  165. #define FUNC_ATAN atanl
  166. #elif defined(HAVE_ATAN)
  167. #define FUNC_ATAN (long double)atan
  168. #endif
  169. #ifdef HAVE_ATAN2L
  170. #define FUNC_ATAN2 atan2l
  171. #elif defined(HAVE_ATAN2)
  172. #define FUNC_ATAN2 (long double)atan2
  173. #endif
  174. #ifdef HAVE_POWL
  175. #define FUNC_POW powl
  176. #elif defined(HAVE_POW)
  177. #define FUNC_POW (long double)pow
  178. #endif
  179. #ifdef HAVE_SQRTL
  180. #define FUNC_SQRT sqrtl
  181. #elif defined(HAVE_SQRT)
  182. #define FUNC_SQRT (long double)sqrt
  183. #endif
  184. #ifdef HAVE_RINTL
  185. #define FUNC_RINT rintl
  186. #elif defined(HAVE_RINT)
  187. #define FUNC_RINT (long double)rint
  188. #endif
  189. #ifdef HAVE_EXPL
  190. #define FUNC_EXP expl
  191. #elif defined(HAVE_EXP)
  192. #define FUNC_EXP (long double)exp
  193. #endif
  194. #ifdef HAVE_LOGL
  195. #define FUNC_LOG logl
  196. #elif defined(HAVE_LOG)
  197. #define FUNC_LOG (long double)log
  198. #endif
  199. #ifdef HAVE_REMAINDERL
  200. #define FUNC_REMAINDER remainderl
  201. #elif defined(HAVE_REMAINDER)
  202. #define FUNC_REMAINDER (long double)remainder
  203. #endif
  204. #ifdef HAVE_FMODL
  205. #define FUNC_FMOD fmodl
  206. #elif defined(HAVE_FMOD)
  207. #define FUNC_FMOD (long double)fmod
  208. #endif
  209. #ifdef HAVE_STRTOLD
  210. #define FUNC_STRTOD strtold
  211. #elif defined(HAVE_STRTOD)
  212. #define FUNC_STRTOD (long double)strtod
  213. #endif
  214. #ifdef HAVE_FLOORL
  215. #define FUNC_FLOOR floorl
  216. #elif defined(HAVE_FLOOR)
  217. #define FUNC_FLOOR (long double)floor
  218. #endif
  219. #ifdef HAVE_CEILL
  220. #define FUNC_CEIL ceill
  221. #elif defined(HAVE_CEIL)
  222. #define FUNC_CEIL (long double)ceil
  223. #endif
  224. #ifdef HAVE_ROUNDL
  225. #define FUNC_ROUND roundl
  226. #elif defined(HAVE_ROUND)
  227. #define FUNC_ROUND (long double)round
  228. #endif
  229. #ifdef HAVE_TRUNCL
  230. #define FUNC_TRUNC truncl
  231. #elif defined(HAVE_TRUNC)
  232. #define FUNC_TRUNC (long double)trunc
  233. #endif
  234. /*! \note
  235. * Oddly enough, some platforms have some ISO C99 functions, but not others, so
  236. * we define the missing functions in terms of their mathematical identities.
  237. */
  238. #ifdef HAVE_EXP2L
  239. #define FUNC_EXP2 exp2l
  240. #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
  241. #define FUNC_EXP2(x) expl((x) * logl(2.0))
  242. #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
  243. #define FUNC_EXP2(x) (long double)exp((x) * log(2.0))
  244. #endif
  245. #ifdef HAVE_EXP10L
  246. #define FUNC_EXP10 exp10l
  247. #elif (defined(HAVE_EXPL) && defined(HAVE_LOGL))
  248. #define FUNC_EXP10(x) expl((x) * logl(10.0))
  249. #elif (defined(HAVE_EXP) && defined(HAVE_LOG))
  250. #define FUNC_EXP10(x) (long double)exp((x) * log(10.0))
  251. #endif
  252. #ifdef HAVE_LOG2L
  253. #define FUNC_LOG2 log2l
  254. #elif defined(HAVE_LOGL)
  255. #define FUNC_LOG2(x) (logl(x) / logl(2.0))
  256. #elif defined(HAVE_LOG10L)
  257. #define FUNC_LOG2(x) (log10l(x) / log10l(2.0))
  258. #elif defined(HAVE_LOG2)
  259. #define FUNC_LOG2 (long double)log2
  260. #elif defined(HAVE_LOG)
  261. #define FUNC_LOG2(x) ((long double)log(x) / log(2.0))
  262. #endif
  263. #ifdef HAVE_LOG10L
  264. #define FUNC_LOG10 log10l
  265. #elif defined(HAVE_LOGL)
  266. #define FUNC_LOG10(x) (logl(x) / logl(10.0))
  267. #elif defined(HAVE_LOG2L)
  268. #define FUNC_LOG10(x) (log2l(x) / log2l(10.0))
  269. #elif defined(HAVE_LOG10)
  270. #define FUNC_LOG10(x) (long double)log10(x)
  271. #elif defined(HAVE_LOG)
  272. #define FUNC_LOG10(x) ((long double)log(x) / log(10.0))
  273. #endif
  274. #include <stdlib.h>
  275. #ifndef _GNU_SOURCE
  276. #define _GNU_SOURCE
  277. #endif
  278. #include <string.h>
  279. #include <math.h>
  280. #include <locale.h>
  281. #include <unistd.h>
  282. #include <ctype.h>
  283. #if !defined(SOLARIS) && !defined(__CYGWIN__)
  284. /* #include <err.h> */
  285. #else
  286. #define quad_t int64_t
  287. #endif
  288. #include <errno.h>
  289. #include <regex.h>
  290. #include <limits.h>
  291. #include "asterisk/ast_expr.h"
  292. #include "asterisk/logger.h"
  293. #if !defined(STANDALONE) && !defined(STANDALONE2)
  294. #include "asterisk/pbx.h"
  295. #endif
  296. #if defined(LONG_LONG_MIN) && !defined(QUAD_MIN)
  297. #define QUAD_MIN LONG_LONG_MIN
  298. #endif
  299. #if defined(LONG_LONG_MAX) && !defined(QUAD_MAX)
  300. #define QUAD_MAX LONG_LONG_MAX
  301. #endif
  302. # if ! defined(QUAD_MIN)
  303. # define QUAD_MIN (-0x7fffffffffffffffLL-1)
  304. # endif
  305. # if ! defined(QUAD_MAX)
  306. # define QUAD_MAX (0x7fffffffffffffffLL)
  307. # endif
  308. #define YYENABLE_NLS 0
  309. #define YYPARSE_PARAM parseio
  310. #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner
  311. #define YYERROR_VERBOSE 1
  312. extern char extra_error_message[4095];
  313. extern int extra_error_message_supplied;
  314. enum valtype {
  315. AST_EXPR_number, AST_EXPR_numeric_string, AST_EXPR_string
  316. } ;
  317. #if defined(STANDALONE) || defined(STANDALONE2)
  318. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
  319. #endif
  320. struct val {
  321. enum valtype type;
  322. union {
  323. char *s;
  324. FP___TYPE i; /* either long double, or just double, on a bad day */
  325. } u;
  326. } ;
  327. enum node_type {
  328. AST_EXPR_NODE_COMMA, AST_EXPR_NODE_STRING, AST_EXPR_NODE_VAL
  329. } ;
  330. struct expr_node
  331. {
  332. enum node_type type;
  333. struct val *val;
  334. struct expr_node *left;
  335. struct expr_node *right;
  336. };
  337. typedef void *yyscan_t;
  338. struct parse_io
  339. {
  340. char *string;
  341. struct val *val;
  342. yyscan_t scanner;
  343. struct ast_channel *chan;
  344. };
  345. static int chk_div __P((FP___TYPE, FP___TYPE));
  346. static int chk_minus __P((FP___TYPE, FP___TYPE, FP___TYPE));
  347. static int chk_plus __P((FP___TYPE, FP___TYPE, FP___TYPE));
  348. static int chk_times __P((FP___TYPE, FP___TYPE, FP___TYPE));
  349. static void free_value __P((struct val *));
  350. static int is_zero_or_null __P((struct val *));
  351. static int isstring __P((struct val *));
  352. static struct val *make_number __P((FP___TYPE));
  353. static struct val *make_str __P((const char *));
  354. static struct val *op_and __P((struct val *, struct val *));
  355. static struct val *op_colon __P((struct val *, struct val *));
  356. static struct val *op_eqtilde __P((struct val *, struct val *));
  357. static struct val *op_div __P((struct val *, struct val *));
  358. static struct val *op_eq __P((struct val *, struct val *));
  359. static struct val *op_ge __P((struct val *, struct val *));
  360. static struct val *op_gt __P((struct val *, struct val *));
  361. static struct val *op_le __P((struct val *, struct val *));
  362. static struct val *op_lt __P((struct val *, struct val *));
  363. static struct val *op_cond __P((struct val *, struct val *, struct val *));
  364. static struct val *op_minus __P((struct val *, struct val *));
  365. static struct val *op_negate __P((struct val *));
  366. static struct val *op_compl __P((struct val *));
  367. static struct val *op_ne __P((struct val *, struct val *));
  368. static struct val *op_or __P((struct val *, struct val *));
  369. static struct val *op_plus __P((struct val *, struct val *));
  370. static struct val *op_rem __P((struct val *, struct val *));
  371. static struct val *op_times __P((struct val *, struct val *));
  372. static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan);
  373. static int to_number __P((struct val *));
  374. static void to_string __P((struct val *));
  375. static struct expr_node *alloc_expr_node(enum node_type);
  376. static void destroy_arglist(struct expr_node *arglist);
  377. /* uh, if I want to predeclare yylex with a YYLTYPE, I have to predeclare the yyltype... sigh */
  378. typedef struct yyltype
  379. {
  380. int first_line;
  381. int first_column;
  382. int last_line;
  383. int last_column;
  384. } yyltype;
  385. # define YYLTYPE yyltype
  386. # define YYLTYPE_IS_TRIVIAL 1
  387. /* we will get warning about no prototype for yylex! But we can't
  388. define it here, we have no definition yet for YYSTYPE. */
  389. int ast_yyerror(const char *,YYLTYPE *, struct parse_io *);
  390. /* I wanted to add args to the yyerror routine, so I could print out
  391. some useful info about the error. Not as easy as it looks, but it
  392. is possible. */
  393. #define ast_yyerror(x) ast_yyerror(x,&yyloc,parseio)
  394. #define DESTROY(x) {if((x)->type == AST_EXPR_numeric_string || (x)->type == AST_EXPR_string) free((x)->u.s); (x)->u.s = 0; free(x);}
  395. /* Enabling traces. */
  396. #ifndef YYDEBUG
  397. # define YYDEBUG 0
  398. #endif
  399. /* Enabling verbose error messages. */
  400. #ifdef YYERROR_VERBOSE
  401. # undef YYERROR_VERBOSE
  402. # define YYERROR_VERBOSE 1
  403. #else
  404. # define YYERROR_VERBOSE 0
  405. #endif
  406. /* Enabling the token table. */
  407. #ifndef YYTOKEN_TABLE
  408. # define YYTOKEN_TABLE 0
  409. #endif
  410. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  411. typedef union YYSTYPE
  412. #line 344 "ast_expr2.y"
  413. {
  414. struct val *val;
  415. struct expr_node *arglist;
  416. }
  417. /* Line 187 of yacc.c. */
  418. #line 493 "ast_expr2.c"
  419. YYSTYPE;
  420. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  421. # define YYSTYPE_IS_DECLARED 1
  422. # define YYSTYPE_IS_TRIVIAL 1
  423. #endif
  424. #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  425. typedef struct YYLTYPE
  426. {
  427. int first_line;
  428. int first_column;
  429. int last_line;
  430. int last_column;
  431. } YYLTYPE;
  432. # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
  433. # define YYLTYPE_IS_DECLARED 1
  434. # define YYLTYPE_IS_TRIVIAL 1
  435. #endif
  436. /* Copy the second part of user declarations. */
  437. #line 349 "ast_expr2.y"
  438. extern int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t));
  439. /* Line 216 of yacc.c. */
  440. #line 521 "ast_expr2.c"
  441. #ifdef short
  442. # undef short
  443. #endif
  444. #ifdef YYTYPE_UINT8
  445. typedef YYTYPE_UINT8 yytype_uint8;
  446. #else
  447. typedef unsigned char yytype_uint8;
  448. #endif
  449. #ifdef YYTYPE_INT8
  450. typedef YYTYPE_INT8 yytype_int8;
  451. #elif (defined __STDC__ || defined __C99__FUNC__ \
  452. || defined __cplusplus || defined _MSC_VER)
  453. typedef signed char yytype_int8;
  454. #else
  455. typedef short int yytype_int8;
  456. #endif
  457. #ifdef YYTYPE_UINT16
  458. typedef YYTYPE_UINT16 yytype_uint16;
  459. #else
  460. typedef unsigned short int yytype_uint16;
  461. #endif
  462. #ifdef YYTYPE_INT16
  463. typedef YYTYPE_INT16 yytype_int16;
  464. #else
  465. typedef short int yytype_int16;
  466. #endif
  467. #ifndef YYSIZE_T
  468. # ifdef __SIZE_TYPE__
  469. # define YYSIZE_T __SIZE_TYPE__
  470. # elif defined size_t
  471. # define YYSIZE_T size_t
  472. # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  473. || defined __cplusplus || defined _MSC_VER)
  474. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  475. # define YYSIZE_T size_t
  476. # else
  477. # define YYSIZE_T unsigned int
  478. # endif
  479. #endif
  480. #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  481. #ifndef YY_
  482. # if YYENABLE_NLS
  483. # if ENABLE_NLS
  484. # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  485. # define YY_(msgid) dgettext ("bison-runtime", msgid)
  486. # endif
  487. # endif
  488. # ifndef YY_
  489. # define YY_(msgid) msgid
  490. # endif
  491. #endif
  492. /* Suppress unused-variable warnings by "using" E. */
  493. #if ! defined lint || defined __GNUC__
  494. # define YYUSE(e) ((void) (e))
  495. #else
  496. # define YYUSE(e) /* empty */
  497. #endif
  498. /* Identity function, used to suppress warnings about constant conditions. */
  499. #ifndef lint
  500. # define YYID(n) (n)
  501. #else
  502. #if (defined __STDC__ || defined __C99__FUNC__ \
  503. || defined __cplusplus || defined _MSC_VER)
  504. static int
  505. YYID (int i)
  506. #else
  507. static int
  508. YYID (i)
  509. int i;
  510. #endif
  511. {
  512. return i;
  513. }
  514. #endif
  515. #if ! defined yyoverflow || YYERROR_VERBOSE
  516. /* The parser invokes alloca or malloc; define the necessary symbols. */
  517. # ifdef YYSTACK_USE_ALLOCA
  518. # if YYSTACK_USE_ALLOCA
  519. # ifdef __GNUC__
  520. # define YYSTACK_ALLOC __builtin_alloca
  521. # elif defined __BUILTIN_VA_ARG_INCR
  522. # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  523. # elif defined _AIX
  524. # define YYSTACK_ALLOC __alloca
  525. # elif defined _MSC_VER
  526. # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  527. # define alloca _alloca
  528. # else
  529. # define YYSTACK_ALLOC alloca
  530. # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  531. || defined __cplusplus || defined _MSC_VER)
  532. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  533. # ifndef _STDLIB_H
  534. # define _STDLIB_H 1
  535. # endif
  536. # endif
  537. # endif
  538. # endif
  539. # endif
  540. # ifdef YYSTACK_ALLOC
  541. /* Pacify GCC's `empty if-body' warning. */
  542. # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  543. # ifndef YYSTACK_ALLOC_MAXIMUM
  544. /* The OS might guarantee only one guard page at the bottom of the stack,
  545. and a page size can be as small as 4096 bytes. So we cannot safely
  546. invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
  547. to allow for a few compiler-allocated temporary stack slots. */
  548. # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  549. # endif
  550. # else
  551. # define YYSTACK_ALLOC YYMALLOC
  552. # define YYSTACK_FREE YYFREE
  553. # ifndef YYSTACK_ALLOC_MAXIMUM
  554. # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  555. # endif
  556. # if (defined __cplusplus && ! defined _STDLIB_H \
  557. && ! ((defined YYMALLOC || defined malloc) \
  558. && (defined YYFREE || defined free)))
  559. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  560. # ifndef _STDLIB_H
  561. # define _STDLIB_H 1
  562. # endif
  563. # endif
  564. # ifndef YYMALLOC
  565. # define YYMALLOC malloc
  566. # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  567. || defined __cplusplus || defined _MSC_VER)
  568. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  569. # endif
  570. # endif
  571. # ifndef YYFREE
  572. # define YYFREE free
  573. # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  574. || defined __cplusplus || defined _MSC_VER)
  575. void free (void *); /* INFRINGES ON USER NAME SPACE */
  576. # endif
  577. # endif
  578. # endif
  579. #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  580. #if (! defined yyoverflow \
  581. && (! defined __cplusplus \
  582. || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  583. && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  584. /* A type that is properly aligned for any stack member. */
  585. union yyalloc
  586. {
  587. yytype_int16 yyss;
  588. YYSTYPE yyvs;
  589. YYLTYPE yyls;
  590. };
  591. /* The size of the maximum gap between one aligned stack and the next. */
  592. # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  593. /* The size of an array large to enough to hold all stacks, each with
  594. N elements. */
  595. # define YYSTACK_BYTES(N) \
  596. ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  597. + 2 * YYSTACK_GAP_MAXIMUM)
  598. /* Copy COUNT objects from FROM to TO. The source and destination do
  599. not overlap. */
  600. # ifndef YYCOPY
  601. # if defined __GNUC__ && 1 < __GNUC__
  602. # define YYCOPY(To, From, Count) \
  603. __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  604. # else
  605. # define YYCOPY(To, From, Count) \
  606. do \
  607. { \
  608. YYSIZE_T yyi; \
  609. for (yyi = 0; yyi < (Count); yyi++) \
  610. (To)[yyi] = (From)[yyi]; \
  611. } \
  612. while (YYID (0))
  613. # endif
  614. # endif
  615. /* Relocate STACK from its old location to the new one. The
  616. local variables YYSIZE and YYSTACKSIZE give the old and new number of
  617. elements in the stack, and YYPTR gives the new location of the
  618. stack. Advance YYPTR to a properly aligned location for the next
  619. stack. */
  620. # define YYSTACK_RELOCATE(Stack) \
  621. do \
  622. { \
  623. YYSIZE_T yynewbytes; \
  624. YYCOPY (&yyptr->Stack, Stack, yysize); \
  625. Stack = &yyptr->Stack; \
  626. yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  627. yyptr += yynewbytes / sizeof (*yyptr); \
  628. } \
  629. while (YYID (0))
  630. #endif
  631. /* YYFINAL -- State number of the termination state. */
  632. #define YYFINAL 11
  633. /* YYLAST -- Last index in YYTABLE. */
  634. #define YYLAST 150
  635. /* YYNTOKENS -- Number of terminals. */
  636. #define YYNTOKENS 25
  637. /* YYNNTS -- Number of nonterminals. */
  638. #define YYNNTS 4
  639. /* YYNRULES -- Number of rules. */
  640. #define YYNRULES 27
  641. /* YYNRULES -- Number of states. */
  642. #define YYNSTATES 52
  643. /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  644. #define YYUNDEFTOK 2
  645. #define YYMAXUTOK 279
  646. #define YYTRANSLATE(YYX) \
  647. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  648. /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  649. static const yytype_uint8 yytranslate[] =
  650. {
  651. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  652. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  653. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  654. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  655. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  656. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  657. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  658. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  659. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  660. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  661. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  662. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  663. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  664. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  665. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  666. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  667. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  668. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  669. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  670. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  671. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  672. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  673. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  674. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  675. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  676. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  677. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  678. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
  679. };
  680. #if YYDEBUG
  681. /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  682. YYRHS. */
  683. static const yytype_uint8 yyprhs[] =
  684. {
  685. 0, 0, 3, 5, 6, 8, 12, 15, 20, 22,
  686. 26, 30, 34, 38, 42, 46, 50, 54, 58, 62,
  687. 66, 69, 72, 76, 80, 84, 88, 92
  688. };
  689. /* YYRHS -- A `-1'-separated list of the rules' RHS. */
  690. static const yytype_int8 yyrhs[] =
  691. {
  692. 26, 0, -1, 28, -1, -1, 28, -1, 27, 3,
  693. 28, -1, 27, 3, -1, 24, 22, 27, 23, -1,
  694. 24, -1, 22, 28, 23, -1, 28, 6, 28, -1,
  695. 28, 7, 28, -1, 28, 13, 28, -1, 28, 12,
  696. 28, -1, 28, 11, 28, -1, 28, 10, 28, -1,
  697. 28, 9, 28, -1, 28, 8, 28, -1, 28, 15,
  698. 28, -1, 28, 14, 28, -1, 14, 28, -1, 19,
  699. 28, -1, 28, 18, 28, -1, 28, 17, 28, -1,
  700. 28, 16, 28, -1, 28, 21, 28, -1, 28, 20,
  701. 28, -1, 28, 5, 28, 4, 28, -1
  702. };
  703. /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  704. static const yytype_uint16 yyrline[] =
  705. {
  706. 0, 375, 375, 383, 390, 391, 397, 406, 412, 413,
  707. 417, 421, 425, 429, 433, 437, 441, 445, 449, 453,
  708. 457, 461, 465, 469, 473, 477, 481, 485
  709. };
  710. #endif
  711. #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
  712. /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  713. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  714. static const char *const yytname[] =
  715. {
  716. "$end", "error", "$undefined", "TOK_COMMA", "TOK_COLONCOLON",
  717. "TOK_COND", "TOK_OR", "TOK_AND", "TOK_NE", "TOK_LE", "TOK_GE", "TOK_LT",
  718. "TOK_GT", "TOK_EQ", "TOK_MINUS", "TOK_PLUS", "TOK_MOD", "TOK_DIV",
  719. "TOK_MULT", "TOK_COMPL", "TOK_EQTILDE", "TOK_COLON", "TOK_LP", "TOK_RP",
  720. "TOKEN", "$accept", "start", "arglist", "expr", 0
  721. };
  722. #endif
  723. # ifdef YYPRINT
  724. /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  725. token YYLEX-NUM. */
  726. static const yytype_uint16 yytoknum[] =
  727. {
  728. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  729. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  730. 275, 276, 277, 278, 279
  731. };
  732. # endif
  733. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  734. static const yytype_uint8 yyr1[] =
  735. {
  736. 0, 25, 26, 26, 27, 27, 27, 28, 28, 28,
  737. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  738. 28, 28, 28, 28, 28, 28, 28, 28
  739. };
  740. /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  741. static const yytype_uint8 yyr2[] =
  742. {
  743. 0, 2, 1, 0, 1, 3, 2, 4, 1, 3,
  744. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  745. 2, 2, 3, 3, 3, 3, 3, 5
  746. };
  747. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  748. STATE-NUM when YYTABLE doesn't specify something else to do. Zero
  749. means the default is an error. */
  750. static const yytype_uint8 yydefact[] =
  751. {
  752. 3, 0, 0, 0, 8, 0, 2, 20, 21, 0,
  753. 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  754. 0, 0, 0, 0, 0, 0, 0, 0, 9, 0,
  755. 4, 0, 10, 11, 17, 16, 15, 14, 13, 12,
  756. 19, 18, 24, 23, 22, 26, 25, 6, 7, 0,
  757. 5, 27
  758. };
  759. /* YYDEFGOTO[NTERM-NUM]. */
  760. static const yytype_int8 yydefgoto[] =
  761. {
  762. -1, 5, 29, 6
  763. };
  764. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  765. STATE-NUM. */
  766. #define YYPACT_NINF -18
  767. static const yytype_int16 yypact[] =
  768. {
  769. 112, 112, 112, 112, -16, 5, 62, -17, -17, 24,
  770. 112, -18, 112, 112, 112, 112, 112, 112, 112, 112,
  771. 112, 112, 112, 112, 112, 112, 112, 112, -18, 4,
  772. 62, 45, 93, 107, 123, 123, 123, 123, 123, 123,
  773. 129, 129, -17, -17, -17, -18, -18, 112, -18, 112,
  774. 62, 78
  775. };
  776. /* YYPGOTO[NTERM-NUM]. */
  777. static const yytype_int8 yypgoto[] =
  778. {
  779. -18, -18, -18, -1
  780. };
  781. /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  782. positive, shift that token. If negative, reduce the rule which
  783. number is the opposite. If zero, do what YYDEFACT says.
  784. If YYTABLE_NINF, syntax error. */
  785. #define YYTABLE_NINF -1
  786. static const yytype_uint8 yytable[] =
  787. {
  788. 7, 8, 9, 26, 27, 11, 10, 47, 0, 30,
  789. 0, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  790. 40, 41, 42, 43, 44, 45, 46, 48, 0, 12,
  791. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  792. 23, 24, 25, 0, 26, 27, 50, 28, 51, 49,
  793. 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  794. 22, 23, 24, 25, 0, 26, 27, 12, 13, 14,
  795. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  796. 25, 0, 26, 27, 13, 14, 15, 16, 17, 18,
  797. 19, 20, 21, 22, 23, 24, 25, 0, 26, 27,
  798. 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  799. 24, 25, 0, 26, 27, 15, 16, 17, 18, 19,
  800. 20, 21, 22, 23, 24, 25, 1, 26, 27, 0,
  801. 0, 2, 0, 0, 3, 0, 4, 21, 22, 23,
  802. 24, 25, 0, 26, 27, 23, 24, 25, 0, 26,
  803. 27
  804. };
  805. static const yytype_int8 yycheck[] =
  806. {
  807. 1, 2, 3, 20, 21, 0, 22, 3, -1, 10,
  808. -1, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  809. 21, 22, 23, 24, 25, 26, 27, 23, -1, 5,
  810. 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  811. 16, 17, 18, -1, 20, 21, 47, 23, 49, 4,
  812. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  813. 15, 16, 17, 18, -1, 20, 21, 5, 6, 7,
  814. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  815. 18, -1, 20, 21, 6, 7, 8, 9, 10, 11,
  816. 12, 13, 14, 15, 16, 17, 18, -1, 20, 21,
  817. 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  818. 17, 18, -1, 20, 21, 8, 9, 10, 11, 12,
  819. 13, 14, 15, 16, 17, 18, 14, 20, 21, -1,
  820. -1, 19, -1, -1, 22, -1, 24, 14, 15, 16,
  821. 17, 18, -1, 20, 21, 16, 17, 18, -1, 20,
  822. 21
  823. };
  824. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  825. symbol of state STATE-NUM. */
  826. static const yytype_uint8 yystos[] =
  827. {
  828. 0, 14, 19, 22, 24, 26, 28, 28, 28, 28,
  829. 22, 0, 5, 6, 7, 8, 9, 10, 11, 12,
  830. 13, 14, 15, 16, 17, 18, 20, 21, 23, 27,
  831. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  832. 28, 28, 28, 28, 28, 28, 28, 3, 23, 4,
  833. 28, 28
  834. };
  835. #define yyerrok (yyerrstatus = 0)
  836. #define yyclearin (yychar = YYEMPTY)
  837. #define YYEMPTY (-2)
  838. #define YYEOF 0
  839. #define YYACCEPT goto yyacceptlab
  840. #define YYABORT goto yyabortlab
  841. #define YYERROR goto yyerrorlab
  842. /* Like YYERROR except do call yyerror. This remains here temporarily
  843. to ease the transition to the new meaning of YYERROR, for GCC.
  844. Once GCC version 2 has supplanted version 1, this can go. */
  845. #define YYFAIL goto yyerrlab
  846. #define YYRECOVERING() (!!yyerrstatus)
  847. #define YYBACKUP(Token, Value) \
  848. do \
  849. if (yychar == YYEMPTY && yylen == 1) \
  850. { \
  851. yychar = (Token); \
  852. yylval = (Value); \
  853. yytoken = YYTRANSLATE (yychar); \
  854. YYPOPSTACK (1); \
  855. goto yybackup; \
  856. } \
  857. else \
  858. { \
  859. yyerror (YY_("syntax error: cannot back up")); \
  860. YYERROR; \
  861. } \
  862. while (YYID (0))
  863. #define YYTERROR 1
  864. #define YYERRCODE 256
  865. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  866. If N is 0, then set CURRENT to the empty location which ends
  867. the previous symbol: RHS[0] (always defined). */
  868. #define YYRHSLOC(Rhs, K) ((Rhs)[K])
  869. #ifndef YYLLOC_DEFAULT
  870. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  871. do \
  872. if (YYID (N)) \
  873. { \
  874. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  875. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  876. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  877. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  878. } \
  879. else \
  880. { \
  881. (Current).first_line = (Current).last_line = \
  882. YYRHSLOC (Rhs, 0).last_line; \
  883. (Current).first_column = (Current).last_column = \
  884. YYRHSLOC (Rhs, 0).last_column; \
  885. } \
  886. while (YYID (0))
  887. #endif
  888. /* YY_LOCATION_PRINT -- Print the location on the stream.
  889. This macro was not mandated originally: define only if we know
  890. we won't break user code: when these are the locations we know. */
  891. #ifndef YY_LOCATION_PRINT
  892. # if YYLTYPE_IS_TRIVIAL
  893. # define YY_LOCATION_PRINT(File, Loc) \
  894. fprintf (File, "%d.%d-%d.%d", \
  895. (Loc).first_line, (Loc).first_column, \
  896. (Loc).last_line, (Loc).last_column)
  897. # else
  898. # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  899. # endif
  900. #endif
  901. /* YYLEX -- calling `yylex' with the right arguments. */
  902. #ifdef YYLEX_PARAM
  903. # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
  904. #else
  905. # define YYLEX yylex (&yylval, &yylloc)
  906. #endif
  907. /* Enable debugging if requested. */
  908. #if YYDEBUG
  909. # ifndef YYFPRINTF
  910. # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  911. # define YYFPRINTF fprintf
  912. # endif
  913. # define YYDPRINTF(Args) \
  914. do { \
  915. if (yydebug) \
  916. YYFPRINTF Args; \
  917. } while (YYID (0))
  918. # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  919. do { \
  920. if (yydebug) \
  921. { \
  922. YYFPRINTF (stderr, "%s ", Title); \
  923. yy_symbol_print (stderr, \
  924. Type, Value, Location); \
  925. YYFPRINTF (stderr, "\n"); \
  926. } \
  927. } while (YYID (0))
  928. /*--------------------------------.
  929. | Print this symbol on YYOUTPUT. |
  930. `--------------------------------*/
  931. /*ARGSUSED*/
  932. #if (defined __STDC__ || defined __C99__FUNC__ \
  933. || defined __cplusplus || defined _MSC_VER)
  934. static void
  935. yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  936. #else
  937. static void
  938. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp)
  939. FILE *yyoutput;
  940. int yytype;
  941. YYSTYPE const * const yyvaluep;
  942. YYLTYPE const * const yylocationp;
  943. #endif
  944. {
  945. if (!yyvaluep)
  946. return;
  947. YYUSE (yylocationp);
  948. # ifdef YYPRINT
  949. if (yytype < YYNTOKENS)
  950. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  951. # else
  952. YYUSE (yyoutput);
  953. # endif
  954. switch (yytype)
  955. {
  956. default:
  957. break;
  958. }
  959. }
  960. /*--------------------------------.
  961. | Print this symbol on YYOUTPUT. |
  962. `--------------------------------*/
  963. #if (defined __STDC__ || defined __C99__FUNC__ \
  964. || defined __cplusplus || defined _MSC_VER)
  965. static void
  966. yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
  967. #else
  968. static void
  969. yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp)
  970. FILE *yyoutput;
  971. int yytype;
  972. YYSTYPE const * const yyvaluep;
  973. YYLTYPE const * const yylocationp;
  974. #endif
  975. {
  976. if (yytype < YYNTOKENS)
  977. YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  978. else
  979. YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  980. YY_LOCATION_PRINT (yyoutput, *yylocationp);
  981. YYFPRINTF (yyoutput, ": ");
  982. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
  983. YYFPRINTF (yyoutput, ")");
  984. }
  985. /*------------------------------------------------------------------.
  986. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  987. | TOP (included). |
  988. `------------------------------------------------------------------*/
  989. #if (defined __STDC__ || defined __C99__FUNC__ \
  990. || defined __cplusplus || defined _MSC_VER)
  991. static void
  992. yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
  993. #else
  994. static void
  995. yy_stack_print (bottom, top)
  996. yytype_int16 *bottom;
  997. yytype_int16 *top;
  998. #endif
  999. {
  1000. YYFPRINTF (stderr, "Stack now");
  1001. for (; bottom <= top; ++bottom)
  1002. YYFPRINTF (stderr, " %d", *bottom);
  1003. YYFPRINTF (stderr, "\n");
  1004. }
  1005. # define YY_STACK_PRINT(Bottom, Top) \
  1006. do { \
  1007. if (yydebug) \
  1008. yy_stack_print ((Bottom), (Top)); \
  1009. } while (YYID (0))
  1010. /*------------------------------------------------.
  1011. | Report that the YYRULE is going to be reduced. |
  1012. `------------------------------------------------*/
  1013. #if (defined __STDC__ || defined __C99__FUNC__ \
  1014. || defined __cplusplus || defined _MSC_VER)
  1015. static void
  1016. yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
  1017. #else
  1018. static void
  1019. yy_reduce_print (yyvsp, yylsp, yyrule)
  1020. YYSTYPE *yyvsp;
  1021. YYLTYPE *yylsp;
  1022. int yyrule;
  1023. #endif
  1024. {
  1025. int yynrhs = yyr2[yyrule];
  1026. int yyi;
  1027. unsigned long int yylno = yyrline[yyrule];
  1028. YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  1029. yyrule - 1, yylno);
  1030. /* The symbols being reduced. */
  1031. for (yyi = 0; yyi < yynrhs; yyi++)
  1032. {
  1033. fprintf (stderr, " $%d = ", yyi + 1);
  1034. yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  1035. &(yyvsp[(yyi + 1) - (yynrhs)])
  1036. , &(yylsp[(yyi + 1) - (yynrhs)]) );
  1037. fprintf (stderr, "\n");
  1038. }
  1039. }
  1040. # define YY_REDUCE_PRINT(Rule) \
  1041. do { \
  1042. if (yydebug) \
  1043. yy_reduce_print (yyvsp, yylsp, Rule); \
  1044. } while (YYID (0))
  1045. /* Nonzero means print parse trace. It is left uninitialized so that
  1046. multiple parsers can coexist. */
  1047. int yydebug;
  1048. #else /* !YYDEBUG */
  1049. # define YYDPRINTF(Args)
  1050. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1051. # define YY_STACK_PRINT(Bottom, Top)
  1052. # define YY_REDUCE_PRINT(Rule)
  1053. #endif /* !YYDEBUG */
  1054. /* YYINITDEPTH -- initial size of the parser's stacks. */
  1055. #ifndef YYINITDEPTH
  1056. # define YYINITDEPTH 200
  1057. #endif
  1058. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1059. if the built-in stack extension method is used).
  1060. Do not make this value too large; the results are undefined if
  1061. YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1062. evaluated with infinite-precision integer arithmetic. */
  1063. #ifndef YYMAXDEPTH
  1064. # define YYMAXDEPTH 10000
  1065. #endif
  1066. #if YYERROR_VERBOSE
  1067. # ifndef yystrlen
  1068. # if defined __GLIBC__ && defined _STRING_H
  1069. # define yystrlen strlen
  1070. # else
  1071. /* Return the length of YYSTR. */
  1072. #if (defined __STDC__ || defined __C99__FUNC__ \
  1073. || defined __cplusplus || defined _MSC_VER)
  1074. static YYSIZE_T
  1075. yystrlen (const char *yystr)
  1076. #else
  1077. static YYSIZE_T
  1078. yystrlen (yystr)
  1079. const char *yystr;
  1080. #endif
  1081. {
  1082. YYSIZE_T yylen;
  1083. for (yylen = 0; yystr[yylen]; yylen++)
  1084. continue;
  1085. return yylen;
  1086. }
  1087. # endif
  1088. # endif
  1089. # ifndef yystpcpy
  1090. # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1091. # define yystpcpy stpcpy
  1092. # else
  1093. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1094. YYDEST. */
  1095. #if (defined __STDC__ || defined __C99__FUNC__ \
  1096. || defined __cplusplus || defined _MSC_VER)
  1097. static char *
  1098. yystpcpy (char *yydest, const char *yysrc)
  1099. #else
  1100. static char *
  1101. yystpcpy (yydest, yysrc)
  1102. char *yydest;
  1103. const char *yysrc;
  1104. #endif
  1105. {
  1106. char *yyd = yydest;
  1107. const char *yys = yysrc;
  1108. while ((*yyd++ = *yys++) != '\0')
  1109. continue;
  1110. return yyd - 1;
  1111. }
  1112. # endif
  1113. # endif
  1114. # ifndef yytnamerr
  1115. /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1116. quotes and backslashes, so that it's suitable for yyerror. The
  1117. heuristic is that double-quoting is unnecessary unless the string
  1118. contains an apostrophe, a comma, or backslash (other than
  1119. backslash-backslash). YYSTR is taken from yytname. If YYRES is
  1120. null, do not copy; instead, return the length of what the result
  1121. would have been. */
  1122. static YYSIZE_T
  1123. yytnamerr (char *yyres, const char *yystr)
  1124. {
  1125. if (*yystr == '"')
  1126. {
  1127. YYSIZE_T yyn = 0;
  1128. char const *yyp = yystr;
  1129. for (;;)
  1130. switch (*++yyp)
  1131. {
  1132. case '\'':
  1133. case ',':
  1134. goto do_not_strip_quotes;
  1135. case '\\':
  1136. if (*++yyp != '\\')
  1137. goto do_not_strip_quotes;
  1138. /* Fall through. */
  1139. default:
  1140. if (yyres)
  1141. yyres[yyn] = *yyp;
  1142. yyn++;
  1143. break;
  1144. case '"':
  1145. if (yyres)
  1146. yyres[yyn] = '\0';
  1147. return yyn;
  1148. }
  1149. do_not_strip_quotes: ;
  1150. }
  1151. if (! yyres)
  1152. return yystrlen (yystr);
  1153. return yystpcpy (yyres, yystr) - yyres;
  1154. }
  1155. # endif
  1156. /* Copy into YYRESULT an error message about the unexpected token
  1157. YYCHAR while in state YYSTATE. Return the number of bytes copied,
  1158. including the terminating null byte. If YYRESULT is null, do not
  1159. copy anything; just return the number of bytes that would be
  1160. copied. As a special case, return 0 if an ordinary "syntax error"
  1161. message will do. Return YYSIZE_MAXIMUM if overflow occurs during
  1162. size calculation. */
  1163. static YYSIZE_T
  1164. yysyntax_error (char *yyresult, int yystate, int yychar)
  1165. {
  1166. int yyn = yypact[yystate];
  1167. if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
  1168. return 0;
  1169. else
  1170. {
  1171. int yytype = YYTRANSLATE (yychar);
  1172. YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
  1173. YYSIZE_T yysize = yysize0;
  1174. YYSIZE_T yysize1;
  1175. int yysize_overflow = 0;
  1176. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1177. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1178. int yyx;
  1179. # if 0
  1180. /* This is so xgettext sees the translatable formats that are
  1181. constructed on the fly. */
  1182. YY_("syntax error, unexpected %s");
  1183. YY_("syntax error, unexpected %s, expecting %s");
  1184. YY_("syntax error, unexpected %s, expecting %s or %s");
  1185. YY_("syntax error, unexpected %s, expecting %s or %s or %s");
  1186. YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
  1187. # endif
  1188. char *yyfmt;
  1189. char const *yyf;
  1190. static char const yyunexpected[] = "syntax error, unexpected %s";
  1191. static char const yyexpecting[] = ", expecting %s";
  1192. static char const yyor[] = " or %s";
  1193. char yyformat[sizeof yyunexpected
  1194. + sizeof yyexpecting - 1
  1195. + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
  1196. * (sizeof yyor - 1))];
  1197. char const *yyprefix = yyexpecting;
  1198. /* Start YYX at -YYN if negative to avoid negative indexes in
  1199. YYCHECK. */
  1200. int yyxbegin = yyn < 0 ? -yyn : 0;
  1201. /* Stay within bounds of both yycheck and yytname. */
  1202. int yychecklim = YYLAST - yyn + 1;
  1203. int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1204. int yycount = 1;
  1205. yyarg[0] = yytname[yytype];
  1206. yyfmt = yystpcpy (yyformat, yyunexpected);
  1207. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1208. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1209. {
  1210. if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1211. {
  1212. yycount = 1;
  1213. yysize = yysize0;
  1214. yyformat[sizeof yyunexpected - 1] = '\0';
  1215. break;
  1216. }
  1217. yyarg[yycount++] = yytname[yyx];
  1218. yysize1 = yysize + yytnamerr (0, yytname[yyx]);
  1219. yysize_overflow |= (yysize1 < yysize);
  1220. yysize = yysize1;
  1221. yyfmt = yystpcpy (yyfmt, yyprefix);
  1222. yyprefix = yyor;
  1223. }
  1224. yyf = YY_(yyformat);
  1225. yysize1 = yysize + yystrlen (yyf);
  1226. yysize_overflow |= (yysize1 < yysize);
  1227. yysize = yysize1;
  1228. if (yysize_overflow)
  1229. return YYSIZE_MAXIMUM;
  1230. if (yyresult)
  1231. {
  1232. /* Avoid sprintf, as that infringes on the user's name space.
  1233. Don't have undefined behavior even if the translation
  1234. produced a string with the wrong number of "%s"s. */
  1235. char *yyp = yyresult;
  1236. int yyi = 0;
  1237. while ((*yyp = *yyf) != '\0')
  1238. {
  1239. if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
  1240. {
  1241. yyp += yytnamerr (yyp, yyarg[yyi++]);
  1242. yyf += 2;
  1243. }
  1244. else
  1245. {
  1246. yyp++;
  1247. yyf++;
  1248. }
  1249. }
  1250. }
  1251. return yysize;
  1252. }
  1253. }
  1254. #endif /* YYERROR_VERBOSE */
  1255. /*-----------------------------------------------.
  1256. | Release the memory associated to this symbol. |
  1257. `-----------------------------------------------*/
  1258. /*ARGSUSED*/
  1259. #if (defined __STDC__ || defined __C99__FUNC__ \
  1260. || defined __cplusplus || defined _MSC_VER)
  1261. static void
  1262. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
  1263. #else
  1264. static void
  1265. yydestruct (yymsg, yytype, yyvaluep, yylocationp)
  1266. const char *yymsg;
  1267. int yytype;
  1268. YYSTYPE *yyvaluep;
  1269. YYLTYPE *yylocationp;
  1270. #endif
  1271. {
  1272. YYUSE (yyvaluep);
  1273. YYUSE (yylocationp);
  1274. if (!yymsg)
  1275. yymsg = "Deleting";
  1276. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1277. switch (yytype)
  1278. {
  1279. case 4: /* "TOK_COLONCOLON" */
  1280. #line 369 "ast_expr2.y"
  1281. { free_value((yyvaluep->val)); };
  1282. #line 1474 "ast_expr2.c"
  1283. break;
  1284. case 5: /* "TOK_COND" */
  1285. #line 369 "ast_expr2.y"
  1286. { free_value((yyvaluep->val)); };
  1287. #line 1479 "ast_expr2.c"
  1288. break;
  1289. case 6: /* "TOK_OR" */
  1290. #line 369 "ast_expr2.y"
  1291. { free_value((yyvaluep->val)); };
  1292. #line 1484 "ast_expr2.c"
  1293. break;
  1294. case 7: /* "TOK_AND" */
  1295. #line 369 "ast_expr2.y"
  1296. { free_value((yyvaluep->val)); };
  1297. #line 1489 "ast_expr2.c"
  1298. break;
  1299. case 8: /* "TOK_NE" */
  1300. #line 369 "ast_expr2.y"
  1301. { free_value((yyvaluep->val)); };
  1302. #line 1494 "ast_expr2.c"
  1303. break;
  1304. case 9: /* "TOK_LE" */
  1305. #line 369 "ast_expr2.y"
  1306. { free_value((yyvaluep->val)); };
  1307. #line 1499 "ast_expr2.c"
  1308. break;
  1309. case 10: /* "TOK_GE" */
  1310. #line 369 "ast_expr2.y"
  1311. { free_value((yyvaluep->val)); };
  1312. #line 1504 "ast_expr2.c"
  1313. break;
  1314. case 11: /* "TOK_LT" */
  1315. #line 369 "ast_expr2.y"
  1316. { free_value((yyvaluep->val)); };
  1317. #line 1509 "ast_expr2.c"
  1318. break;
  1319. case 12: /* "TOK_GT" */
  1320. #line 369 "ast_expr2.y"
  1321. { free_value((yyvaluep->val)); };
  1322. #line 1514 "ast_expr2.c"
  1323. break;
  1324. case 13: /* "TOK_EQ" */
  1325. #line 369 "ast_expr2.y"
  1326. { free_value((yyvaluep->val)); };
  1327. #line 1519 "ast_expr2.c"
  1328. break;
  1329. case 14: /* "TOK_MINUS" */
  1330. #line 369 "ast_expr2.y"
  1331. { free_value((yyvaluep->val)); };
  1332. #line 1524 "ast_expr2.c"
  1333. break;
  1334. case 15: /* "TOK_PLUS" */
  1335. #line 369 "ast_expr2.y"
  1336. { free_value((yyvaluep->val)); };
  1337. #line 1529 "ast_expr2.c"
  1338. break;
  1339. case 16: /* "TOK_MOD" */
  1340. #line 369 "ast_expr2.y"
  1341. { free_value((yyvaluep->val)); };
  1342. #line 1534 "ast_expr2.c"
  1343. break;
  1344. case 17: /* "TOK_DIV" */
  1345. #line 369 "ast_expr2.y"
  1346. { free_value((yyvaluep->val)); };
  1347. #line 1539 "ast_expr2.c"
  1348. break;
  1349. case 18: /* "TOK_MULT" */
  1350. #line 369 "ast_expr2.y"
  1351. { free_value((yyvaluep->val)); };
  1352. #line 1544 "ast_expr2.c"
  1353. break;
  1354. case 19: /* "TOK_COMPL" */
  1355. #line 369 "ast_expr2.y"
  1356. { free_value((yyvaluep->val)); };
  1357. #line 1549 "ast_expr2.c"
  1358. break;
  1359. case 20: /* "TOK_EQTILDE" */
  1360. #line 369 "ast_expr2.y"
  1361. { free_value((yyvaluep->val)); };
  1362. #line 1554 "ast_expr2.c"
  1363. break;
  1364. case 21: /* "TOK_COLON" */
  1365. #line 369 "ast_expr2.y"
  1366. { free_value((yyvaluep->val)); };
  1367. #line 1559 "ast_expr2.c"
  1368. break;
  1369. case 22: /* "TOK_LP" */
  1370. #line 369 "ast_expr2.y"
  1371. { free_value((yyvaluep->val)); };
  1372. #line 1564 "ast_expr2.c"
  1373. break;
  1374. case 23: /* "TOK_RP" */
  1375. #line 369 "ast_expr2.y"
  1376. { free_value((yyvaluep->val)); };
  1377. #line 1569 "ast_expr2.c"
  1378. break;
  1379. case 24: /* "TOKEN" */
  1380. #line 369 "ast_expr2.y"
  1381. { free_value((yyvaluep->val)); };
  1382. #line 1574 "ast_expr2.c"
  1383. break;
  1384. case 28: /* "expr" */
  1385. #line 369 "ast_expr2.y"
  1386. { free_value((yyvaluep->val)); };
  1387. #line 1579 "ast_expr2.c"
  1388. break;
  1389. default:
  1390. break;
  1391. }
  1392. }
  1393. /* Prevent warnings from -Wmissing-prototypes. */
  1394. #ifdef YYPARSE_PARAM
  1395. #if defined __STDC__ || defined __cplusplus
  1396. int yyparse (void *YYPARSE_PARAM);
  1397. #else
  1398. int yyparse ();
  1399. #endif
  1400. #else /* ! YYPARSE_PARAM */
  1401. #if defined __STDC__ || defined __cplusplus
  1402. int yyparse (void);
  1403. #else
  1404. int yyparse ();
  1405. #endif
  1406. #endif /* ! YYPARSE_PARAM */
  1407. /*----------.
  1408. | yyparse. |
  1409. `----------*/
  1410. #ifdef YYPARSE_PARAM
  1411. #if (defined __STDC__ || defined __C99__FUNC__ \
  1412. || defined __cplusplus || defined _MSC_VER)
  1413. int
  1414. yyparse (void *YYPARSE_PARAM)
  1415. #else
  1416. int
  1417. yyparse (YYPARSE_PARAM)
  1418. void *YYPARSE_PARAM;
  1419. #endif
  1420. #else /* ! YYPARSE_PARAM */
  1421. #if (defined __STDC__ || defined __C99__FUNC__ \
  1422. || defined __cplusplus || defined _MSC_VER)
  1423. int
  1424. yyparse (void)
  1425. #else
  1426. int
  1427. yyparse ()
  1428. #endif
  1429. #endif
  1430. {
  1431. /* The look-ahead symbol. */
  1432. int yychar;
  1433. /* The semantic value of the look-ahead symbol. */
  1434. YYSTYPE yylval;
  1435. /* Number of syntax errors so far. */
  1436. int yynerrs;
  1437. /* Location data for the look-ahead symbol. */
  1438. YYLTYPE yylloc;
  1439. int yystate;
  1440. int yyn;
  1441. int yyresult;
  1442. /* Number of tokens to shift before error messages enabled. */
  1443. int yyerrstatus;
  1444. /* Look-ahead token as an internal (translated) token number. */
  1445. int yytoken = 0;
  1446. #if YYERROR_VERBOSE
  1447. /* Buffer for error messages, and its allocated size. */
  1448. char yymsgbuf[128];
  1449. char *yymsg = yymsgbuf;
  1450. YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  1451. #endif
  1452. /* Three stacks and their tools:
  1453. `yyss': related to states,
  1454. `yyvs': related to semantic values,
  1455. `yyls': related to locations.
  1456. Refer to the stacks thru separate pointers, to allow yyoverflow
  1457. to reallocate them elsewhere. */
  1458. /* The state stack. */
  1459. yytype_int16 yyssa[YYINITDEPTH];
  1460. yytype_int16 *yyss = yyssa;
  1461. yytype_int16 *yyssp;
  1462. /* The semantic value stack. */
  1463. YYSTYPE yyvsa[YYINITDEPTH];
  1464. YYSTYPE *yyvs = yyvsa;
  1465. YYSTYPE *yyvsp;
  1466. /* The location stack. */
  1467. YYLTYPE yylsa[YYINITDEPTH];
  1468. YYLTYPE *yyls = yylsa;
  1469. YYLTYPE *yylsp;
  1470. /* The locations where the error started and ended. */
  1471. YYLTYPE yyerror_range[2];
  1472. #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  1473. YYSIZE_T yystacksize = YYINITDEPTH;
  1474. /* The variables used to return semantic value and location from the
  1475. action routines. */
  1476. YYSTYPE yyval;
  1477. YYLTYPE yyloc;
  1478. /* The number of symbols on the RHS of the reduced rule.
  1479. Keep to zero when no symbol should be popped. */
  1480. int yylen = 0;
  1481. YYDPRINTF ((stderr, "Starting parse\n"));
  1482. yystate = 0;
  1483. yyerrstatus = 0;
  1484. yynerrs = 0;
  1485. yychar = YYEMPTY; /* Cause a token to be read. */
  1486. /* Initialize stack pointers.
  1487. Waste one element of value and location stack
  1488. so that they stay on the same level as the state stack.
  1489. The wasted elements are never initialized. */
  1490. yyssp = yyss;
  1491. yyvsp = yyvs;
  1492. yylsp = yyls;
  1493. #if YYLTYPE_IS_TRIVIAL
  1494. /* Initialize the default location before parsing starts. */
  1495. yylloc.first_line = yylloc.last_line = 1;
  1496. yylloc.first_column = yylloc.last_column = 0;
  1497. #endif
  1498. goto yysetstate;
  1499. /*------------------------------------------------------------.
  1500. | yynewstate -- Push a new state, which is found in yystate. |
  1501. `------------------------------------------------------------*/
  1502. yynewstate:
  1503. /* In all cases, when you get here, the value and location stacks
  1504. have just been pushed. So pushing a state here evens the stacks. */
  1505. yyssp++;
  1506. yysetstate:
  1507. *yyssp = yystate;
  1508. if (yyss + yystacksize - 1 <= yyssp)
  1509. {
  1510. /* Get the current used size of the three stacks, in elements. */
  1511. YYSIZE_T yysize = yyssp - yyss + 1;
  1512. #ifdef yyoverflow
  1513. {
  1514. /* Give user a chance to reallocate the stack. Use copies of
  1515. these so that the &'s don't force the real ones into
  1516. memory. */
  1517. YYSTYPE *yyvs1 = yyvs;
  1518. yytype_int16 *yyss1 = yyss;
  1519. YYLTYPE *yyls1 = yyls;
  1520. /* Each stack pointer address is followed by the size of the
  1521. data in use in that stack, in bytes. This used to be a
  1522. conditional around just the two extra args, but that might
  1523. be undefined if yyoverflow is a macro. */
  1524. yyoverflow (YY_("memory exhausted"),
  1525. &yyss1, yysize * sizeof (*yyssp),
  1526. &yyvs1, yysize * sizeof (*yyvsp),
  1527. &yyls1, yysize * sizeof (*yylsp),
  1528. &yystacksize);
  1529. yyls = yyls1;
  1530. yyss = yyss1;
  1531. yyvs = yyvs1;
  1532. }
  1533. #else /* no yyoverflow */
  1534. # ifndef YYSTACK_RELOCATE
  1535. goto yyexhaustedlab;
  1536. # else
  1537. /* Extend the stack our own way. */
  1538. if (YYMAXDEPTH <= yystacksize)
  1539. goto yyexhaustedlab;
  1540. yystacksize *= 2;
  1541. if (YYMAXDEPTH < yystacksize)
  1542. yystacksize = YYMAXDEPTH;
  1543. {
  1544. yytype_int16 *yyss1 = yyss;
  1545. union yyalloc *yyptr =
  1546. (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  1547. if (! yyptr)
  1548. goto yyexhaustedlab;
  1549. YYSTACK_RELOCATE (yyss);
  1550. YYSTACK_RELOCATE (yyvs);
  1551. YYSTACK_RELOCATE (yyls);
  1552. # undef YYSTACK_RELOCATE
  1553. if (yyss1 != yyssa)
  1554. YYSTACK_FREE (yyss1);
  1555. }
  1556. # endif
  1557. #endif /* no yyoverflow */
  1558. yyssp = yyss + yysize - 1;
  1559. yyvsp = yyvs + yysize - 1;
  1560. yylsp = yyls + yysize - 1;
  1561. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  1562. (unsigned long int) yystacksize));
  1563. if (yyss + yystacksize - 1 <= yyssp)
  1564. YYABORT;
  1565. }
  1566. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1567. goto yybackup;
  1568. /*-----------.
  1569. | yybackup. |
  1570. `-----------*/
  1571. yybackup:
  1572. /* Do appropriate processing given the current state. Read a
  1573. look-ahead token if we need one and don't already have one. */
  1574. /* First try to decide what to do without reference to look-ahead token. */
  1575. yyn = yypact[yystate];
  1576. if (yyn == YYPACT_NINF)
  1577. goto yydefault;
  1578. /* Not known => get a look-ahead token if don't already have one. */
  1579. /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
  1580. if (yychar == YYEMPTY)
  1581. {
  1582. YYDPRINTF ((stderr, "Reading a token: "));
  1583. yychar = YYLEX;
  1584. }
  1585. if (yychar <= YYEOF)
  1586. {
  1587. yychar = yytoken = YYEOF;
  1588. YYDPRINTF ((stderr, "Now at end of input.\n"));
  1589. }
  1590. else
  1591. {
  1592. yytoken = YYTRANSLATE (yychar);
  1593. YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1594. }
  1595. /* If the proper action on seeing token YYTOKEN is to reduce or to
  1596. detect an error, take that action. */
  1597. yyn += yytoken;
  1598. if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1599. goto yydefault;
  1600. yyn = yytable[yyn];
  1601. if (yyn <= 0)
  1602. {
  1603. if (yyn == 0 || yyn == YYTABLE_NINF)
  1604. goto yyerrlab;
  1605. yyn = -yyn;
  1606. goto yyreduce;
  1607. }
  1608. if (yyn == YYFINAL)
  1609. YYACCEPT;
  1610. /* Count tokens shifted since error; after three, turn off error
  1611. status. */
  1612. if (yyerrstatus)
  1613. yyerrstatus--;
  1614. /* Shift the look-ahead token. */
  1615. YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1616. /* Discard the shifted token unless it is eof. */
  1617. if (yychar != YYEOF)
  1618. yychar = YYEMPTY;
  1619. yystate = yyn;
  1620. *++yyvsp = yylval;
  1621. *++yylsp = yylloc;
  1622. goto yynewstate;
  1623. /*-----------------------------------------------------------.
  1624. | yydefault -- do the default action for the current state. |
  1625. `-----------------------------------------------------------*/
  1626. yydefault:
  1627. yyn = yydefact[yystate];
  1628. if (yyn == 0)
  1629. goto yyerrlab;
  1630. goto yyreduce;
  1631. /*-----------------------------.
  1632. | yyreduce -- Do a reduction. |
  1633. `-----------------------------*/
  1634. yyreduce:
  1635. /* yyn is the number of a rule to reduce with. */
  1636. yylen = yyr2[yyn];
  1637. /* If YYLEN is nonzero, implement the default value of the action:
  1638. `$$ = $1'.
  1639. Otherwise, the following line sets YYVAL to garbage.
  1640. This behavior is undocumented and Bison
  1641. users should not rely upon it. Assigning to YYVAL
  1642. unconditionally makes the parser a bit smaller, and it avoids a
  1643. GCC warning that YYVAL may be used uninitialized. */
  1644. yyval = yyvsp[1-yylen];
  1645. /* Default location. */
  1646. YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  1647. YY_REDUCE_PRINT (yyn);
  1648. switch (yyn)
  1649. {
  1650. case 2:
  1651. #line 375 "ast_expr2.y"
  1652. { ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
  1653. ((struct parse_io *)parseio)->val->type = (yyvsp[(1) - (1)].val)->type;
  1654. if( (yyvsp[(1) - (1)].val)->type == AST_EXPR_number )
  1655. ((struct parse_io *)parseio)->val->u.i = (yyvsp[(1) - (1)].val)->u.i;
  1656. else
  1657. ((struct parse_io *)parseio)->val->u.s = (yyvsp[(1) - (1)].val)->u.s;
  1658. free((yyvsp[(1) - (1)].val));
  1659. ;}
  1660. break;
  1661. case 3:
  1662. #line 383 "ast_expr2.y"
  1663. {/* nothing */ ((struct parse_io *)parseio)->val = (struct val *)calloc(sizeof(struct val),1);
  1664. ((struct parse_io *)parseio)->val->type = AST_EXPR_string;
  1665. ((struct parse_io *)parseio)->val->u.s = strdup("");
  1666. ;}
  1667. break;
  1668. case 4:
  1669. #line 390 "ast_expr2.y"
  1670. { (yyval.arglist) = alloc_expr_node(AST_EXPR_NODE_VAL); (yyval.arglist)->val = (yyvsp[(1) - (1)].val);;}
  1671. break;
  1672. case 5:
  1673. #line 391 "ast_expr2.y"
  1674. {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
  1675. struct expr_node *t;
  1676. DESTROY((yyvsp[(2) - (3)].val));
  1677. for (t=(yyvsp[(1) - (3)].arglist);t->right;t=t->right)
  1678. ;
  1679. (yyval.arglist) = (yyvsp[(1) - (3)].arglist); t->right = x; x->val = (yyvsp[(3) - (3)].val);;}
  1680. break;
  1681. case 6:
  1682. #line 397 "ast_expr2.y"
  1683. {struct expr_node *x = alloc_expr_node(AST_EXPR_NODE_VAL);
  1684. struct expr_node *t; /* NULL args should OK */
  1685. DESTROY((yyvsp[(2) - (2)].val));
  1686. for (t=(yyvsp[(1) - (2)].arglist);t->right;t=t->right)
  1687. ;
  1688. (yyval.arglist) = (yyvsp[(1) - (2)].arglist); t->right = x; x->val = make_str("");;}
  1689. break;
  1690. case 7:
  1691. #line 406 "ast_expr2.y"
  1692. { (yyval.val) = op_func((yyvsp[(1) - (4)].val),(yyvsp[(3) - (4)].arglist), ((struct parse_io *)parseio)->chan);
  1693. DESTROY((yyvsp[(2) - (4)].val));
  1694. DESTROY((yyvsp[(4) - (4)].val));
  1695. DESTROY((yyvsp[(1) - (4)].val));
  1696. destroy_arglist((yyvsp[(3) - (4)].arglist));
  1697. ;}
  1698. break;
  1699. case 8:
  1700. #line 412 "ast_expr2.y"
  1701. {(yyval.val) = (yyvsp[(1) - (1)].val);;}
  1702. break;
  1703. case 9:
  1704. #line 413 "ast_expr2.y"
  1705. { (yyval.val) = (yyvsp[(2) - (3)].val);
  1706. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1707. (yyloc).first_line=0; (yyloc).last_line=0;
  1708. DESTROY((yyvsp[(1) - (3)].val)); DESTROY((yyvsp[(3) - (3)].val)); ;}
  1709. break;
  1710. case 10:
  1711. #line 417 "ast_expr2.y"
  1712. { (yyval.val) = op_or ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1713. DESTROY((yyvsp[(2) - (3)].val));
  1714. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1715. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1716. break;
  1717. case 11:
  1718. #line 421 "ast_expr2.y"
  1719. { (yyval.val) = op_and ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1720. DESTROY((yyvsp[(2) - (3)].val));
  1721. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1722. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1723. break;
  1724. case 12:
  1725. #line 425 "ast_expr2.y"
  1726. { (yyval.val) = op_eq ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1727. DESTROY((yyvsp[(2) - (3)].val));
  1728. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1729. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1730. break;
  1731. case 13:
  1732. #line 429 "ast_expr2.y"
  1733. { (yyval.val) = op_gt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1734. DESTROY((yyvsp[(2) - (3)].val));
  1735. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1736. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1737. break;
  1738. case 14:
  1739. #line 433 "ast_expr2.y"
  1740. { (yyval.val) = op_lt ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1741. DESTROY((yyvsp[(2) - (3)].val));
  1742. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1743. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1744. break;
  1745. case 15:
  1746. #line 437 "ast_expr2.y"
  1747. { (yyval.val) = op_ge ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1748. DESTROY((yyvsp[(2) - (3)].val));
  1749. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1750. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1751. break;
  1752. case 16:
  1753. #line 441 "ast_expr2.y"
  1754. { (yyval.val) = op_le ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1755. DESTROY((yyvsp[(2) - (3)].val));
  1756. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1757. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1758. break;
  1759. case 17:
  1760. #line 445 "ast_expr2.y"
  1761. { (yyval.val) = op_ne ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1762. DESTROY((yyvsp[(2) - (3)].val));
  1763. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1764. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1765. break;
  1766. case 18:
  1767. #line 449 "ast_expr2.y"
  1768. { (yyval.val) = op_plus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1769. DESTROY((yyvsp[(2) - (3)].val));
  1770. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1771. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1772. break;
  1773. case 19:
  1774. #line 453 "ast_expr2.y"
  1775. { (yyval.val) = op_minus ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1776. DESTROY((yyvsp[(2) - (3)].val));
  1777. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1778. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1779. break;
  1780. case 20:
  1781. #line 457 "ast_expr2.y"
  1782. { (yyval.val) = op_negate ((yyvsp[(2) - (2)].val));
  1783. DESTROY((yyvsp[(1) - (2)].val));
  1784. (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
  1785. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1786. break;
  1787. case 21:
  1788. #line 461 "ast_expr2.y"
  1789. { (yyval.val) = op_compl ((yyvsp[(2) - (2)].val));
  1790. DESTROY((yyvsp[(1) - (2)].val));
  1791. (yyloc).first_column = (yylsp[(1) - (2)]).first_column; (yyloc).last_column = (yylsp[(2) - (2)]).last_column;
  1792. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1793. break;
  1794. case 22:
  1795. #line 465 "ast_expr2.y"
  1796. { (yyval.val) = op_times ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1797. DESTROY((yyvsp[(2) - (3)].val));
  1798. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1799. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1800. break;
  1801. case 23:
  1802. #line 469 "ast_expr2.y"
  1803. { (yyval.val) = op_div ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1804. DESTROY((yyvsp[(2) - (3)].val));
  1805. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1806. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1807. break;
  1808. case 24:
  1809. #line 473 "ast_expr2.y"
  1810. { (yyval.val) = op_rem ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1811. DESTROY((yyvsp[(2) - (3)].val));
  1812. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1813. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1814. break;
  1815. case 25:
  1816. #line 477 "ast_expr2.y"
  1817. { (yyval.val) = op_colon ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1818. DESTROY((yyvsp[(2) - (3)].val));
  1819. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1820. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1821. break;
  1822. case 26:
  1823. #line 481 "ast_expr2.y"
  1824. { (yyval.val) = op_eqtilde ((yyvsp[(1) - (3)].val), (yyvsp[(3) - (3)].val));
  1825. DESTROY((yyvsp[(2) - (3)].val));
  1826. (yyloc).first_column = (yylsp[(1) - (3)]).first_column; (yyloc).last_column = (yylsp[(3) - (3)]).last_column;
  1827. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1828. break;
  1829. case 27:
  1830. #line 485 "ast_expr2.y"
  1831. { (yyval.val) = op_cond ((yyvsp[(1) - (5)].val), (yyvsp[(3) - (5)].val), (yyvsp[(5) - (5)].val));
  1832. DESTROY((yyvsp[(2) - (5)].val));
  1833. DESTROY((yyvsp[(4) - (5)].val));
  1834. (yyloc).first_column = (yylsp[(1) - (5)]).first_column; (yyloc).last_column = (yylsp[(3) - (5)]).last_column;
  1835. (yyloc).first_line=0; (yyloc).last_line=0;;}
  1836. break;
  1837. /* Line 1267 of yacc.c. */
  1838. #line 2116 "ast_expr2.c"
  1839. default: break;
  1840. }
  1841. YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  1842. YYPOPSTACK (yylen);
  1843. yylen = 0;
  1844. YY_STACK_PRINT (yyss, yyssp);
  1845. *++yyvsp = yyval;
  1846. *++yylsp = yyloc;
  1847. /* Now `shift' the result of the reduction. Determine what state
  1848. that goes to, based on the state we popped back to and the rule
  1849. number reduced by. */
  1850. yyn = yyr1[yyn];
  1851. yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  1852. if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1853. yystate = yytable[yystate];
  1854. else
  1855. yystate = yydefgoto[yyn - YYNTOKENS];
  1856. goto yynewstate;
  1857. /*------------------------------------.
  1858. | yyerrlab -- here on detecting error |
  1859. `------------------------------------*/
  1860. yyerrlab:
  1861. /* If not already recovering from an error, report this error. */
  1862. if (!yyerrstatus)
  1863. {
  1864. ++yynerrs;
  1865. #if ! YYERROR_VERBOSE
  1866. yyerror (YY_("syntax error"));
  1867. #else
  1868. {
  1869. YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
  1870. if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
  1871. {
  1872. YYSIZE_T yyalloc = 2 * yysize;
  1873. if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
  1874. yyalloc = YYSTACK_ALLOC_MAXIMUM;
  1875. if (yymsg != yymsgbuf)
  1876. YYSTACK_FREE (yymsg);
  1877. yymsg = (char *) YYSTACK_ALLOC (yyalloc);
  1878. if (yymsg)
  1879. yymsg_alloc = yyalloc;
  1880. else
  1881. {
  1882. yymsg = yymsgbuf;
  1883. yymsg_alloc = sizeof yymsgbuf;
  1884. }
  1885. }
  1886. if (0 < yysize && yysize <= yymsg_alloc)
  1887. {
  1888. (void) yysyntax_error (yymsg, yystate, yychar);
  1889. yyerror (yymsg);
  1890. }
  1891. else
  1892. {
  1893. yyerror (YY_("syntax error"));
  1894. if (yysize != 0)
  1895. goto yyexhaustedlab;
  1896. }
  1897. }
  1898. #endif
  1899. }
  1900. yyerror_range[0] = yylloc;
  1901. if (yyerrstatus == 3)
  1902. {
  1903. /* If just tried and failed to reuse look-ahead token after an
  1904. error, discard it. */
  1905. if (yychar <= YYEOF)
  1906. {
  1907. /* Return failure if at end of input. */
  1908. if (yychar == YYEOF)
  1909. YYABORT;
  1910. }
  1911. else
  1912. {
  1913. yydestruct ("Error: discarding",
  1914. yytoken, &yylval, &yylloc);
  1915. yychar = YYEMPTY;
  1916. }
  1917. }
  1918. /* Else will try to reuse look-ahead token after shifting the error
  1919. token. */
  1920. goto yyerrlab1;
  1921. /*---------------------------------------------------.
  1922. | yyerrorlab -- error raised explicitly by YYERROR. |
  1923. `---------------------------------------------------*/
  1924. yyerrorlab:
  1925. /* Pacify compilers like GCC when the user code never invokes
  1926. YYERROR and the label yyerrorlab therefore never appears in user
  1927. code. */
  1928. if (/*CONSTCOND*/ 0)
  1929. goto yyerrorlab;
  1930. yyerror_range[0] = yylsp[1-yylen];
  1931. /* Do not reclaim the symbols of the rule which action triggered
  1932. this YYERROR. */
  1933. YYPOPSTACK (yylen);
  1934. yylen = 0;
  1935. YY_STACK_PRINT (yyss, yyssp);
  1936. yystate = *yyssp;
  1937. goto yyerrlab1;
  1938. /*-------------------------------------------------------------.
  1939. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  1940. `-------------------------------------------------------------*/
  1941. yyerrlab1:
  1942. yyerrstatus = 3; /* Each real token shifted decrements this. */
  1943. for (;;)
  1944. {
  1945. yyn = yypact[yystate];
  1946. if (yyn != YYPACT_NINF)
  1947. {
  1948. yyn += YYTERROR;
  1949. if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  1950. {
  1951. yyn = yytable[yyn];
  1952. if (0 < yyn)
  1953. break;
  1954. }
  1955. }
  1956. /* Pop the current state because it cannot handle the error token. */
  1957. if (yyssp == yyss)
  1958. YYABORT;
  1959. yyerror_range[0] = *yylsp;
  1960. yydestruct ("Error: popping",
  1961. yystos[yystate], yyvsp, yylsp);
  1962. YYPOPSTACK (1);
  1963. yystate = *yyssp;
  1964. YY_STACK_PRINT (yyss, yyssp);
  1965. }
  1966. if (yyn == YYFINAL)
  1967. YYACCEPT;
  1968. *++yyvsp = yylval;
  1969. yyerror_range[1] = yylloc;
  1970. /* Using YYLLOC is tempting, but would change the location of
  1971. the look-ahead. YYLOC is available though. */
  1972. YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
  1973. *++yylsp = yyloc;
  1974. /* Shift the error token. */
  1975. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  1976. yystate = yyn;
  1977. goto yynewstate;
  1978. /*-------------------------------------.
  1979. | yyacceptlab -- YYACCEPT comes here. |
  1980. `-------------------------------------*/
  1981. yyacceptlab:
  1982. yyresult = 0;
  1983. goto yyreturn;
  1984. /*-----------------------------------.
  1985. | yyabortlab -- YYABORT comes here. |
  1986. `-----------------------------------*/
  1987. yyabortlab:
  1988. yyresult = 1;
  1989. goto yyreturn;
  1990. #ifndef yyoverflow
  1991. /*-------------------------------------------------.
  1992. | yyexhaustedlab -- memory exhaustion comes here. |
  1993. `-------------------------------------------------*/
  1994. yyexhaustedlab:
  1995. yyerror (YY_("memory exhausted"));
  1996. yyresult = 2;
  1997. /* Fall through. */
  1998. #endif
  1999. yyreturn:
  2000. if (yychar != YYEOF && yychar != YYEMPTY)
  2001. yydestruct ("Cleanup: discarding lookahead",
  2002. yytoken, &yylval, &yylloc);
  2003. /* Do not reclaim the symbols of the rule which action triggered
  2004. this YYABORT or YYACCEPT. */
  2005. YYPOPSTACK (yylen);
  2006. YY_STACK_PRINT (yyss, yyssp);
  2007. while (yyssp != yyss)
  2008. {
  2009. yydestruct ("Cleanup: popping",
  2010. yystos[*yyssp], yyvsp, yylsp);
  2011. YYPOPSTACK (1);
  2012. }
  2013. #ifndef yyoverflow
  2014. if (yyss != yyssa)
  2015. YYSTACK_FREE (yyss);
  2016. #endif
  2017. #if YYERROR_VERBOSE
  2018. if (yymsg != yymsgbuf)
  2019. YYSTACK_FREE (yymsg);
  2020. #endif
  2021. /* Make sure YYID is used. */
  2022. return YYID (yyresult);
  2023. }
  2024. #line 492 "ast_expr2.y"
  2025. static struct expr_node *alloc_expr_node(enum node_type nt)
  2026. {
  2027. struct expr_node *x = calloc(1,sizeof(struct expr_node));
  2028. if (!x) {
  2029. ast_log(LOG_ERROR, "Allocation for expr_node FAILED!!\n");
  2030. return 0;
  2031. }
  2032. x->type = nt;
  2033. return x;
  2034. }
  2035. static struct val *
  2036. make_number (FP___TYPE i)
  2037. {
  2038. struct val *vp;
  2039. vp = (struct val *) malloc (sizeof (*vp));
  2040. if (vp == NULL) {
  2041. ast_log(LOG_WARNING, "malloc() failed\n");
  2042. return(NULL);
  2043. }
  2044. vp->type = AST_EXPR_number;
  2045. vp->u.i = i;
  2046. return vp;
  2047. }
  2048. static struct val *
  2049. make_str (const char *s)
  2050. {
  2051. struct val *vp;
  2052. size_t i;
  2053. int isint; /* this started out being a test for an integer, but then ended up being a test for a float */
  2054. vp = (struct val *) malloc (sizeof (*vp));
  2055. if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
  2056. ast_log(LOG_WARNING,"malloc() failed\n");
  2057. return(NULL);
  2058. }
  2059. for (i = 0, isint = (isdigit(s[0]) || s[0] == '-' || s[0]=='.'); isint && i < strlen(s); i++)
  2060. {
  2061. if (!isdigit(s[i]) && s[i] != '.') {
  2062. isint = 0;
  2063. break;
  2064. }
  2065. }
  2066. if (isint)
  2067. vp->type = AST_EXPR_numeric_string;
  2068. else
  2069. vp->type = AST_EXPR_string;
  2070. return vp;
  2071. }
  2072. static void
  2073. free_value (struct val *vp)
  2074. {
  2075. if (vp==NULL) {
  2076. return;
  2077. }
  2078. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  2079. free (vp->u.s);
  2080. free(vp);
  2081. }
  2082. static int
  2083. to_number (struct val *vp)
  2084. {
  2085. FP___TYPE i;
  2086. if (vp == NULL) {
  2087. ast_log(LOG_WARNING,"vp==NULL in to_number()\n");
  2088. return(0);
  2089. }
  2090. if (vp->type == AST_EXPR_number)
  2091. return 1;
  2092. if (vp->type == AST_EXPR_string)
  2093. return 0;
  2094. /* vp->type == AST_EXPR_numeric_string, make it numeric */
  2095. errno = 0;
  2096. i = FUNC_STRTOD(vp->u.s, (char**)0); /* either strtod, or strtold on a good day */
  2097. if (errno != 0) {
  2098. ast_log(LOG_WARNING,"Conversion of %s to number under/overflowed!\n", vp->u.s);
  2099. free(vp->u.s);
  2100. vp->u.s = 0;
  2101. return(0);
  2102. }
  2103. free (vp->u.s);
  2104. vp->u.i = i;
  2105. vp->type = AST_EXPR_number;
  2106. return 1;
  2107. }
  2108. static void
  2109. strip_quotes(struct val *vp)
  2110. {
  2111. if (vp->type != AST_EXPR_string && vp->type != AST_EXPR_numeric_string)
  2112. return;
  2113. if( vp->u.s[0] == '"' && vp->u.s[strlen(vp->u.s)-1] == '"' )
  2114. {
  2115. char *f, *t;
  2116. f = vp->u.s;
  2117. t = vp->u.s;
  2118. while( *f )
  2119. {
  2120. if( *f && *f != '"' )
  2121. *t++ = *f++;
  2122. else
  2123. f++;
  2124. }
  2125. *t = *f;
  2126. }
  2127. }
  2128. static void
  2129. to_string (struct val *vp)
  2130. {
  2131. char *tmp;
  2132. if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
  2133. return;
  2134. tmp = malloc ((size_t)25);
  2135. if (tmp == NULL) {
  2136. ast_log(LOG_WARNING,"malloc() failed\n");
  2137. return;
  2138. }
  2139. sprintf(tmp, FP___PRINTF, vp->u.i);
  2140. vp->type = AST_EXPR_string;
  2141. vp->u.s = tmp;
  2142. }
  2143. static int
  2144. isstring (struct val *vp)
  2145. {
  2146. /* only TRUE if this string is not a valid number */
  2147. return (vp->type == AST_EXPR_string);
  2148. }
  2149. static int
  2150. is_zero_or_null (struct val *vp)
  2151. {
  2152. if (vp->type == AST_EXPR_number) {
  2153. return (vp->u.i == 0);
  2154. } else {
  2155. return (*vp->u.s == 0 || (to_number(vp) && vp->u.i == 0));
  2156. }
  2157. /* NOTREACHED */
  2158. }
  2159. #ifdef STANDALONE2
  2160. void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
  2161. {
  2162. va_list vars;
  2163. va_start(vars,fmt);
  2164. printf("LOG: lev:%d file:%s line:%d func: %s ",
  2165. level, file, line, function);
  2166. vprintf(fmt, vars);
  2167. fflush(stdout);
  2168. va_end(vars);
  2169. }
  2170. int main(int argc,char **argv) {
  2171. char s[4096];
  2172. char out[4096];
  2173. FILE *infile;
  2174. if( !argv[1] )
  2175. exit(20);
  2176. if( access(argv[1],F_OK)== 0 )
  2177. {
  2178. int ret;
  2179. infile = fopen(argv[1],"r");
  2180. if( !infile )
  2181. {
  2182. printf("Sorry, couldn't open %s for reading!\n", argv[1]);
  2183. exit(10);
  2184. }
  2185. while( fgets(s,sizeof(s),infile) )
  2186. {
  2187. if( s[strlen(s)-1] == '\n' )
  2188. s[strlen(s)-1] = 0;
  2189. ret = ast_expr(s, out, sizeof(out), NULL);
  2190. printf("Expression: %s Result: [%d] '%s'\n",
  2191. s, ret, out);
  2192. }
  2193. fclose(infile);
  2194. }
  2195. else
  2196. {
  2197. if (ast_expr(argv[1], s, sizeof(s), NULL))
  2198. printf("=====%s======\n",s);
  2199. else
  2200. printf("No result\n");
  2201. }
  2202. return 0;
  2203. }
  2204. #endif
  2205. #undef ast_yyerror
  2206. #define ast_yyerror(x) ast_yyerror(x, YYLTYPE *yylloc, struct parse_io *parseio)
  2207. /* I put the ast_yyerror func in the flex input file,
  2208. because it refers to the buffer state. Best to
  2209. let it access the BUFFER stuff there and not trying
  2210. define all the structs, macros etc. in this file! */
  2211. static void destroy_arglist(struct expr_node *arglist)
  2212. {
  2213. struct expr_node *arglist_next;
  2214. while (arglist)
  2215. {
  2216. arglist_next = arglist->right;
  2217. if (arglist->val)
  2218. free_value(arglist->val);
  2219. arglist->val = 0;
  2220. arglist->right = 0;
  2221. free(arglist);
  2222. arglist = arglist_next;
  2223. }
  2224. }
  2225. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2226. static char *compose_func_args(struct expr_node *arglist)
  2227. {
  2228. struct expr_node *t = arglist;
  2229. char *argbuf;
  2230. int total_len = 0;
  2231. while (t) {
  2232. if (t != arglist)
  2233. total_len += 1; /* for the sep */
  2234. if (t->val) {
  2235. if (t->val->type == AST_EXPR_number)
  2236. total_len += 25; /* worst case */
  2237. else
  2238. total_len += strlen(t->val->u.s);
  2239. }
  2240. t = t->right;
  2241. }
  2242. total_len++; /* for the null */
  2243. ast_log(LOG_NOTICE,"argbuf allocated %d bytes;\n", total_len);
  2244. argbuf = malloc(total_len);
  2245. argbuf[0] = 0;
  2246. t = arglist;
  2247. while (t) {
  2248. char numbuf[30];
  2249. if (t != arglist)
  2250. strcat(argbuf,",");
  2251. if (t->val) {
  2252. if (t->val->type == AST_EXPR_number) {
  2253. sprintf(numbuf,FP___PRINTF,t->val->u.i);
  2254. strcat(argbuf,numbuf);
  2255. } else
  2256. strcat(argbuf,t->val->u.s);
  2257. }
  2258. t = t->right;
  2259. }
  2260. ast_log(LOG_NOTICE,"argbuf uses %d bytes;\n", (int) strlen(argbuf));
  2261. return argbuf;
  2262. }
  2263. static int is_really_num(char *str)
  2264. {
  2265. if ( strspn(str,"-0123456789. ") == strlen(str))
  2266. return 1;
  2267. else
  2268. return 0;
  2269. }
  2270. #endif
  2271. static struct val *op_func(struct val *funcname, struct expr_node *arglist, struct ast_channel *chan)
  2272. {
  2273. if (strspn(funcname->u.s,"ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == strlen(funcname->u.s))
  2274. {
  2275. struct val *result;
  2276. if (0) {
  2277. #ifdef FUNC_COS
  2278. } else if (strcmp(funcname->u.s,"COS") == 0) {
  2279. if (arglist && !arglist->right && arglist->val){
  2280. to_number(arglist->val);
  2281. result = make_number(FUNC_COS(arglist->val->u.i));
  2282. return result;
  2283. } else {
  2284. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2285. return make_number(0.0);
  2286. }
  2287. #endif
  2288. #ifdef FUNC_SIN
  2289. } else if (strcmp(funcname->u.s,"SIN") == 0) {
  2290. if (arglist && !arglist->right && arglist->val){
  2291. to_number(arglist->val);
  2292. result = make_number(FUNC_SIN(arglist->val->u.i));
  2293. return result;
  2294. } else {
  2295. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2296. return make_number(0.0);
  2297. }
  2298. #endif
  2299. #ifdef FUNC_TAN
  2300. } else if (strcmp(funcname->u.s,"TAN") == 0) {
  2301. if (arglist && !arglist->right && arglist->val){
  2302. to_number(arglist->val);
  2303. result = make_number(FUNC_TAN(arglist->val->u.i));
  2304. return result;
  2305. } else {
  2306. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2307. return make_number(0.0);
  2308. }
  2309. #endif
  2310. #ifdef FUNC_ACOS
  2311. } else if (strcmp(funcname->u.s,"ACOS") == 0) {
  2312. if (arglist && !arglist->right && arglist->val){
  2313. to_number(arglist->val);
  2314. result = make_number(FUNC_ACOS(arglist->val->u.i));
  2315. return result;
  2316. } else {
  2317. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2318. return make_number(0.0);
  2319. }
  2320. #endif
  2321. #ifdef FUNC_ASIN
  2322. } else if (strcmp(funcname->u.s,"ASIN") == 0) {
  2323. if (arglist && !arglist->right && arglist->val){
  2324. to_number(arglist->val);
  2325. result = make_number(FUNC_ASIN(arglist->val->u.i));
  2326. return result;
  2327. } else {
  2328. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2329. return make_number(0.0);
  2330. }
  2331. #endif
  2332. #ifdef FUNC_ATAN
  2333. } else if (strcmp(funcname->u.s,"ATAN") == 0) {
  2334. if (arglist && !arglist->right && arglist->val){
  2335. to_number(arglist->val);
  2336. result = make_number(FUNC_ATAN(arglist->val->u.i));
  2337. return result;
  2338. } else {
  2339. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2340. return make_number(0.0);
  2341. }
  2342. #endif
  2343. #ifdef FUNC_ATAN2
  2344. } else if (strcmp(funcname->u.s,"ATAN2") == 0) {
  2345. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2346. to_number(arglist->val);
  2347. to_number(arglist->right->val);
  2348. result = make_number(FUNC_ATAN2(arglist->val->u.i, arglist->right->val->u.i));
  2349. return result;
  2350. } else {
  2351. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2352. return make_number(0.0);
  2353. }
  2354. #endif
  2355. #ifdef FUNC_POW
  2356. } else if (strcmp(funcname->u.s,"POW") == 0) {
  2357. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2358. to_number(arglist->val);
  2359. to_number(arglist->right->val);
  2360. result = make_number(FUNC_POW(arglist->val->u.i, arglist->right->val->u.i));
  2361. return result;
  2362. } else {
  2363. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2364. return make_number(0.0);
  2365. }
  2366. #endif
  2367. #ifdef FUNC_SQRT
  2368. } else if (strcmp(funcname->u.s,"SQRT") == 0) {
  2369. if (arglist && !arglist->right && arglist->val){
  2370. to_number(arglist->val);
  2371. result = make_number(FUNC_SQRT(arglist->val->u.i));
  2372. return result;
  2373. } else {
  2374. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2375. return make_number(0.0);
  2376. }
  2377. #endif
  2378. #ifdef FUNC_FLOOR
  2379. } else if (strcmp(funcname->u.s,"FLOOR") == 0) {
  2380. if (arglist && !arglist->right && arglist->val){
  2381. to_number(arglist->val);
  2382. result = make_number(FUNC_FLOOR(arglist->val->u.i));
  2383. return result;
  2384. } else {
  2385. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2386. return make_number(0.0);
  2387. }
  2388. #endif
  2389. #ifdef FUNC_CEIL
  2390. } else if (strcmp(funcname->u.s,"CEIL") == 0) {
  2391. if (arglist && !arglist->right && arglist->val){
  2392. to_number(arglist->val);
  2393. result = make_number(FUNC_CEIL(arglist->val->u.i));
  2394. return result;
  2395. } else {
  2396. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2397. return make_number(0.0);
  2398. }
  2399. #endif
  2400. #ifdef FUNC_ROUND
  2401. } else if (strcmp(funcname->u.s,"ROUND") == 0) {
  2402. if (arglist && !arglist->right && arglist->val){
  2403. to_number(arglist->val);
  2404. result = make_number(FUNC_ROUND(arglist->val->u.i));
  2405. return result;
  2406. } else {
  2407. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2408. return make_number(0.0);
  2409. }
  2410. #endif /* defined(FUNC_ROUND) */
  2411. #ifdef FUNC_RINT
  2412. } else if (strcmp(funcname->u.s,"RINT") == 0) {
  2413. if (arglist && !arglist->right && arglist->val){
  2414. to_number(arglist->val);
  2415. result = make_number(FUNC_RINT(arglist->val->u.i));
  2416. return result;
  2417. } else {
  2418. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2419. return make_number(0.0);
  2420. }
  2421. #endif
  2422. #ifdef FUNC_TRUNC
  2423. } else if (strcmp(funcname->u.s,"TRUNC") == 0) {
  2424. if (arglist && !arglist->right && arglist->val){
  2425. to_number(arglist->val);
  2426. result = make_number(FUNC_TRUNC(arglist->val->u.i));
  2427. return result;
  2428. } else {
  2429. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2430. return make_number(0.0);
  2431. }
  2432. #endif /* defined(FUNC_TRUNC) */
  2433. #ifdef FUNC_EXP
  2434. } else if (strcmp(funcname->u.s,"EXP") == 0) {
  2435. if (arglist && !arglist->right && arglist->val){
  2436. to_number(arglist->val);
  2437. result = make_number(FUNC_EXP(arglist->val->u.i));
  2438. return result;
  2439. } else {
  2440. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2441. return make_number(0.0);
  2442. }
  2443. #endif
  2444. #ifdef FUNC_EXP2
  2445. } else if (strcmp(funcname->u.s,"EXP2") == 0) {
  2446. if (arglist && !arglist->right && arglist->val){
  2447. to_number(arglist->val);
  2448. result = make_number(FUNC_EXP2(arglist->val->u.i));
  2449. return result;
  2450. } else {
  2451. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2452. return make_number(0.0);
  2453. }
  2454. #endif
  2455. #ifdef FUNC_EXP10
  2456. } else if (strcmp(funcname->u.s,"EXP10") == 0) {
  2457. if (arglist && !arglist->right && arglist->val){
  2458. to_number(arglist->val);
  2459. result = make_number(FUNC_EXP10(arglist->val->u.i));
  2460. return result;
  2461. } else {
  2462. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2463. return make_number(0.0);
  2464. }
  2465. #endif
  2466. #ifdef FUNC_LOG
  2467. } else if (strcmp(funcname->u.s,"LOG") == 0) {
  2468. if (arglist && !arglist->right && arglist->val){
  2469. to_number(arglist->val);
  2470. result = make_number(FUNC_LOG(arglist->val->u.i));
  2471. return result;
  2472. } else {
  2473. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2474. return make_number(0.0);
  2475. }
  2476. #endif
  2477. #ifdef FUNC_LOG2
  2478. } else if (strcmp(funcname->u.s,"LOG2") == 0) {
  2479. if (arglist && !arglist->right && arglist->val){
  2480. to_number(arglist->val);
  2481. result = make_number(FUNC_LOG2(arglist->val->u.i));
  2482. return result;
  2483. } else {
  2484. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2485. return make_number(0.0);
  2486. }
  2487. #endif
  2488. #ifdef FUNC_LOG10
  2489. } else if (strcmp(funcname->u.s,"LOG10") == 0) {
  2490. if (arglist && !arglist->right && arglist->val){
  2491. to_number(arglist->val);
  2492. result = make_number(FUNC_LOG10(arglist->val->u.i));
  2493. return result;
  2494. } else {
  2495. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2496. return make_number(0.0);
  2497. }
  2498. #endif
  2499. #ifdef FUNC_REMAINDER
  2500. } else if (strcmp(funcname->u.s,"REMAINDER") == 0) {
  2501. if (arglist && arglist->right && !arglist->right->right && arglist->val && arglist->right->val){
  2502. to_number(arglist->val);
  2503. to_number(arglist->right->val);
  2504. result = make_number(FUNC_REMAINDER(arglist->val->u.i, arglist->right->val->u.i));
  2505. return result;
  2506. } else {
  2507. ast_log(LOG_WARNING,"Wrong args to %s() function\n",funcname->u.s);
  2508. return make_number(0.0);
  2509. }
  2510. #endif
  2511. } else {
  2512. /* is this a custom function we should execute and collect the results of? */
  2513. #if !defined(STANDALONE) && !defined(STANDALONE2)
  2514. struct ast_custom_function *f = ast_custom_function_find(funcname->u.s);
  2515. if (!chan)
  2516. ast_log(LOG_WARNING,"Hey! chan is NULL.\n");
  2517. if (!f)
  2518. ast_log(LOG_WARNING,"Hey! could not find func %s.\n", funcname->u.s);
  2519. if (f && chan) {
  2520. if (f->read) {
  2521. char workspace[512];
  2522. char *argbuf = compose_func_args(arglist);
  2523. f->read(chan, funcname->u.s, argbuf, workspace, sizeof(workspace));
  2524. free(argbuf);
  2525. if (is_really_num(workspace))
  2526. return make_number(FUNC_STRTOD(workspace,(char **)NULL));
  2527. else
  2528. return make_str(workspace);
  2529. } else {
  2530. ast_log(LOG_ERROR,"Error! Function '%s' cannot be read!\n", funcname->u.s);
  2531. return (make_number ((FP___TYPE)0.0));
  2532. }
  2533. } else {
  2534. ast_log(LOG_ERROR,"Error! '%s' doesn't appear to be an available function!", funcname->u.s);
  2535. return (make_number ((FP___TYPE)0.0));
  2536. }
  2537. #else
  2538. ast_log(LOG_ERROR,"Error! '%s' is not available in the standalone version!", funcname->u.s);
  2539. return (make_number ((FP___TYPE)0.0));
  2540. #endif
  2541. }
  2542. }
  2543. else
  2544. {
  2545. ast_log(LOG_ERROR,"Error! '%s' is not possibly a function name!", funcname->u.s);
  2546. return (make_number ((FP___TYPE)0.0));
  2547. }
  2548. return (make_number ((FP___TYPE)0.0));
  2549. }
  2550. static struct val *
  2551. op_or (struct val *a, struct val *b)
  2552. {
  2553. if (is_zero_or_null (a)) {
  2554. free_value (a);
  2555. return (b);
  2556. } else {
  2557. free_value (b);
  2558. return (a);
  2559. }
  2560. }
  2561. static struct val *
  2562. op_and (struct val *a, struct val *b)
  2563. {
  2564. if (is_zero_or_null (a) || is_zero_or_null (b)) {
  2565. free_value (a);
  2566. free_value (b);
  2567. return (make_number ((FP___TYPE)0.0));
  2568. } else {
  2569. free_value (b);
  2570. return (a);
  2571. }
  2572. }
  2573. static struct val *
  2574. op_eq (struct val *a, struct val *b)
  2575. {
  2576. struct val *r;
  2577. if (isstring (a) || isstring (b)) {
  2578. to_string (a);
  2579. to_string (b);
  2580. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) == 0));
  2581. } else {
  2582. #ifdef DEBUG_FOR_CONVERSIONS
  2583. char buffer[2000];
  2584. sprintf(buffer,"Converting '%s' and '%s' ", a->u.s, b->u.s);
  2585. #endif
  2586. (void)to_number(a);
  2587. (void)to_number(b);
  2588. #ifdef DEBUG_FOR_CONVERSIONS
  2589. ast_log(LOG_WARNING,"%s to '%lld' and '%lld'\n", buffer, a->u.i, b->u.i);
  2590. #endif
  2591. r = make_number ((FP___TYPE)(a->u.i == b->u.i));
  2592. }
  2593. free_value (a);
  2594. free_value (b);
  2595. return r;
  2596. }
  2597. static struct val *
  2598. op_gt (struct val *a, struct val *b)
  2599. {
  2600. struct val *r;
  2601. if (isstring (a) || isstring (b)) {
  2602. to_string (a);
  2603. to_string (b);
  2604. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) > 0));
  2605. } else {
  2606. (void)to_number(a);
  2607. (void)to_number(b);
  2608. r = make_number ((FP___TYPE)(a->u.i > b->u.i));
  2609. }
  2610. free_value (a);
  2611. free_value (b);
  2612. return r;
  2613. }
  2614. static struct val *
  2615. op_lt (struct val *a, struct val *b)
  2616. {
  2617. struct val *r;
  2618. if (isstring (a) || isstring (b)) {
  2619. to_string (a);
  2620. to_string (b);
  2621. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) < 0));
  2622. } else {
  2623. (void)to_number(a);
  2624. (void)to_number(b);
  2625. r = make_number ((FP___TYPE)(a->u.i < b->u.i));
  2626. }
  2627. free_value (a);
  2628. free_value (b);
  2629. return r;
  2630. }
  2631. static struct val *
  2632. op_ge (struct val *a, struct val *b)
  2633. {
  2634. struct val *r;
  2635. if (isstring (a) || isstring (b)) {
  2636. to_string (a);
  2637. to_string (b);
  2638. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) >= 0));
  2639. } else {
  2640. (void)to_number(a);
  2641. (void)to_number(b);
  2642. r = make_number ((FP___TYPE)(a->u.i >= b->u.i));
  2643. }
  2644. free_value (a);
  2645. free_value (b);
  2646. return r;
  2647. }
  2648. static struct val *
  2649. op_le (struct val *a, struct val *b)
  2650. {
  2651. struct val *r;
  2652. if (isstring (a) || isstring (b)) {
  2653. to_string (a);
  2654. to_string (b);
  2655. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) <= 0));
  2656. } else {
  2657. (void)to_number(a);
  2658. (void)to_number(b);
  2659. r = make_number ((FP___TYPE)(a->u.i <= b->u.i));
  2660. }
  2661. free_value (a);
  2662. free_value (b);
  2663. return r;
  2664. }
  2665. static struct val *
  2666. op_cond (struct val *a, struct val *b, struct val *c)
  2667. {
  2668. struct val *r;
  2669. if( isstring(a) )
  2670. {
  2671. if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 )
  2672. {
  2673. free_value(a);
  2674. free_value(c);
  2675. r = b;
  2676. }
  2677. else
  2678. {
  2679. free_value(a);
  2680. free_value(b);
  2681. r = c;
  2682. }
  2683. }
  2684. else
  2685. {
  2686. (void)to_number(a);
  2687. if( a->u.i )
  2688. {
  2689. free_value(a);
  2690. free_value(c);
  2691. r = b;
  2692. }
  2693. else
  2694. {
  2695. free_value(a);
  2696. free_value(b);
  2697. r = c;
  2698. }
  2699. }
  2700. return r;
  2701. }
  2702. static struct val *
  2703. op_ne (struct val *a, struct val *b)
  2704. {
  2705. struct val *r;
  2706. if (isstring (a) || isstring (b)) {
  2707. to_string (a);
  2708. to_string (b);
  2709. r = make_number ((FP___TYPE)(strcoll (a->u.s, b->u.s) != 0));
  2710. } else {
  2711. (void)to_number(a);
  2712. (void)to_number(b);
  2713. r = make_number ((FP___TYPE)(a->u.i != b->u.i));
  2714. }
  2715. free_value (a);
  2716. free_value (b);
  2717. return r;
  2718. }
  2719. static int
  2720. chk_plus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2721. {
  2722. /* sum of two positive numbers must be positive */
  2723. if (a > 0 && b > 0 && r <= 0)
  2724. return 1;
  2725. /* sum of two negative numbers must be negative */
  2726. if (a < 0 && b < 0 && r >= 0)
  2727. return 1;
  2728. /* all other cases are OK */
  2729. return 0;
  2730. }
  2731. static struct val *
  2732. op_plus (struct val *a, struct val *b)
  2733. {
  2734. struct val *r;
  2735. if (!to_number (a)) {
  2736. if( !extra_error_message_supplied )
  2737. ast_log(LOG_WARNING,"non-numeric argument\n");
  2738. if (!to_number (b)) {
  2739. free_value(a);
  2740. free_value(b);
  2741. return make_number(0);
  2742. } else {
  2743. free_value(a);
  2744. return (b);
  2745. }
  2746. } else if (!to_number(b)) {
  2747. free_value(b);
  2748. return (a);
  2749. }
  2750. r = make_number (a->u.i + b->u.i);
  2751. if (chk_plus (a->u.i, b->u.i, r->u.i)) {
  2752. ast_log(LOG_WARNING,"overflow\n");
  2753. }
  2754. free_value (a);
  2755. free_value (b);
  2756. return r;
  2757. }
  2758. static int
  2759. chk_minus (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2760. {
  2761. /* special case subtraction of QUAD_MIN */
  2762. if (b == QUAD_MIN) {
  2763. if (a >= 0)
  2764. return 1;
  2765. else
  2766. return 0;
  2767. }
  2768. /* this is allowed for b != QUAD_MIN */
  2769. return chk_plus (a, -b, r);
  2770. }
  2771. static struct val *
  2772. op_minus (struct val *a, struct val *b)
  2773. {
  2774. struct val *r;
  2775. if (!to_number (a)) {
  2776. if( !extra_error_message_supplied )
  2777. ast_log(LOG_WARNING, "non-numeric argument\n");
  2778. if (!to_number (b)) {
  2779. free_value(a);
  2780. free_value(b);
  2781. return make_number(0);
  2782. } else {
  2783. r = make_number(0 - b->u.i);
  2784. free_value(a);
  2785. free_value(b);
  2786. return (r);
  2787. }
  2788. } else if (!to_number(b)) {
  2789. if( !extra_error_message_supplied )
  2790. ast_log(LOG_WARNING, "non-numeric argument\n");
  2791. free_value(b);
  2792. return (a);
  2793. }
  2794. r = make_number (a->u.i - b->u.i);
  2795. if (chk_minus (a->u.i, b->u.i, r->u.i)) {
  2796. ast_log(LOG_WARNING, "overflow\n");
  2797. }
  2798. free_value (a);
  2799. free_value (b);
  2800. return r;
  2801. }
  2802. static struct val *
  2803. op_negate (struct val *a)
  2804. {
  2805. struct val *r;
  2806. if (!to_number (a) ) {
  2807. free_value(a);
  2808. if( !extra_error_message_supplied )
  2809. ast_log(LOG_WARNING, "non-numeric argument\n");
  2810. return make_number(0);
  2811. }
  2812. r = make_number (- a->u.i);
  2813. if (chk_minus (0, a->u.i, r->u.i)) {
  2814. ast_log(LOG_WARNING, "overflow\n");
  2815. }
  2816. free_value (a);
  2817. return r;
  2818. }
  2819. static struct val *
  2820. op_compl (struct val *a)
  2821. {
  2822. int v1 = 1;
  2823. struct val *r;
  2824. if( !a )
  2825. {
  2826. v1 = 0;
  2827. }
  2828. else
  2829. {
  2830. switch( a->type )
  2831. {
  2832. case AST_EXPR_number:
  2833. if( a->u.i == 0 )
  2834. v1 = 0;
  2835. break;
  2836. case AST_EXPR_string:
  2837. if( a->u.s == 0 )
  2838. v1 = 0;
  2839. else
  2840. {
  2841. if( a->u.s[0] == 0 )
  2842. v1 = 0;
  2843. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2844. v1 = 0;
  2845. }
  2846. break;
  2847. case AST_EXPR_numeric_string:
  2848. if( a->u.s == 0 )
  2849. v1 = 0;
  2850. else
  2851. {
  2852. if( a->u.s[0] == 0 )
  2853. v1 = 0;
  2854. else if (strlen(a->u.s) == 1 && a->u.s[0] == '0' )
  2855. v1 = 0;
  2856. }
  2857. break;
  2858. }
  2859. }
  2860. r = make_number (!v1);
  2861. free_value (a);
  2862. return r;
  2863. }
  2864. static int
  2865. chk_times (FP___TYPE a, FP___TYPE b, FP___TYPE r)
  2866. {
  2867. /* special case: first operand is 0, no overflow possible */
  2868. if (a == 0)
  2869. return 0;
  2870. /* cerify that result of division matches second operand */
  2871. if (r / a != b)
  2872. return 1;
  2873. return 0;
  2874. }
  2875. static struct val *
  2876. op_times (struct val *a, struct val *b)
  2877. {
  2878. struct val *r;
  2879. if (!to_number (a) || !to_number (b)) {
  2880. free_value(a);
  2881. free_value(b);
  2882. if( !extra_error_message_supplied )
  2883. ast_log(LOG_WARNING, "non-numeric argument\n");
  2884. return(make_number(0));
  2885. }
  2886. r = make_number (a->u.i * b->u.i);
  2887. if (chk_times (a->u.i, b->u.i, r->u.i)) {
  2888. ast_log(LOG_WARNING, "overflow\n");
  2889. }
  2890. free_value (a);
  2891. free_value (b);
  2892. return (r);
  2893. }
  2894. static int
  2895. chk_div (FP___TYPE a, FP___TYPE b)
  2896. {
  2897. /* div by zero has been taken care of before */
  2898. /* only QUAD_MIN / -1 causes overflow */
  2899. if (a == QUAD_MIN && b == -1)
  2900. return 1;
  2901. /* everything else is OK */
  2902. return 0;
  2903. }
  2904. static struct val *
  2905. op_div (struct val *a, struct val *b)
  2906. {
  2907. struct val *r;
  2908. if (!to_number (a)) {
  2909. free_value(a);
  2910. free_value(b);
  2911. if( !extra_error_message_supplied )
  2912. ast_log(LOG_WARNING, "non-numeric argument\n");
  2913. return make_number(0);
  2914. } else if (!to_number (b)) {
  2915. free_value(a);
  2916. free_value(b);
  2917. if( !extra_error_message_supplied )
  2918. ast_log(LOG_WARNING, "non-numeric argument\n");
  2919. return make_number(INT_MAX);
  2920. }
  2921. if (b->u.i == 0) {
  2922. ast_log(LOG_WARNING, "division by zero\n");
  2923. free_value(a);
  2924. free_value(b);
  2925. return make_number(INT_MAX);
  2926. }
  2927. r = make_number (a->u.i / b->u.i);
  2928. if (chk_div (a->u.i, b->u.i)) {
  2929. ast_log(LOG_WARNING, "overflow\n");
  2930. }
  2931. free_value (a);
  2932. free_value (b);
  2933. return r;
  2934. }
  2935. static struct val *
  2936. op_rem (struct val *a, struct val *b)
  2937. {
  2938. struct val *r;
  2939. if (!to_number (a) || !to_number (b)) {
  2940. if( !extra_error_message_supplied )
  2941. ast_log(LOG_WARNING, "non-numeric argument\n");
  2942. free_value(a);
  2943. free_value(b);
  2944. return make_number(0);
  2945. }
  2946. if (b->u.i == 0) {
  2947. ast_log(LOG_WARNING, "div by zero\n");
  2948. free_value(a);
  2949. return(b);
  2950. }
  2951. r = make_number (FUNC_FMOD(a->u.i, b->u.i)); /* either fmod or fmodl if FP___TYPE is available */
  2952. /* chk_rem necessary ??? */
  2953. free_value (a);
  2954. free_value (b);
  2955. return r;
  2956. }
  2957. static struct val *
  2958. op_colon (struct val *a, struct val *b)
  2959. {
  2960. regex_t rp;
  2961. regmatch_t rm[2];
  2962. char errbuf[256];
  2963. int eval;
  2964. struct val *v;
  2965. /* coerce to both arguments to strings */
  2966. to_string(a);
  2967. to_string(b);
  2968. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  2969. strip_quotes(a);
  2970. strip_quotes(b);
  2971. /* compile regular expression */
  2972. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  2973. regerror (eval, &rp, errbuf, sizeof(errbuf));
  2974. ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
  2975. free_value(a);
  2976. free_value(b);
  2977. return make_str("");
  2978. }
  2979. /* compare string against pattern */
  2980. /* remember that patterns are anchored to the beginning of the line */
  2981. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 && rm[0].rm_so == 0) {
  2982. if (rm[1].rm_so >= 0) {
  2983. *(a->u.s + rm[1].rm_eo) = '\0';
  2984. v = make_str (a->u.s + rm[1].rm_so);
  2985. } else {
  2986. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  2987. }
  2988. } else {
  2989. if (rp.re_nsub == 0) {
  2990. v = make_number ((FP___TYPE)0);
  2991. } else {
  2992. v = make_str ("");
  2993. }
  2994. }
  2995. /* free arguments and pattern buffer */
  2996. free_value (a);
  2997. free_value (b);
  2998. regfree (&rp);
  2999. return v;
  3000. }
  3001. static struct val *
  3002. op_eqtilde (struct val *a, struct val *b)
  3003. {
  3004. regex_t rp;
  3005. regmatch_t rm[2];
  3006. char errbuf[256];
  3007. int eval;
  3008. struct val *v;
  3009. /* coerce to both arguments to strings */
  3010. to_string(a);
  3011. to_string(b);
  3012. /* strip double quotes from both -- they'll screw up the pattern, and the search string starting at ^ */
  3013. strip_quotes(a);
  3014. strip_quotes(b);
  3015. /* compile regular expression */
  3016. if ((eval = regcomp (&rp, b->u.s, REG_EXTENDED)) != 0) {
  3017. regerror (eval, &rp, errbuf, sizeof(errbuf));
  3018. ast_log(LOG_WARNING,"regcomp() error : %s",errbuf);
  3019. free_value(a);
  3020. free_value(b);
  3021. return make_str("");
  3022. }
  3023. /* compare string against pattern */
  3024. /* remember that patterns are anchored to the beginning of the line */
  3025. if (regexec(&rp, a->u.s, (size_t)2, rm, 0) == 0 ) {
  3026. if (rm[1].rm_so >= 0) {
  3027. *(a->u.s + rm[1].rm_eo) = '\0';
  3028. v = make_str (a->u.s + rm[1].rm_so);
  3029. } else {
  3030. v = make_number ((FP___TYPE)(rm[0].rm_eo - rm[0].rm_so));
  3031. }
  3032. } else {
  3033. if (rp.re_nsub == 0) {
  3034. v = make_number ((FP___TYPE)0.0);
  3035. } else {
  3036. v = make_str ("");
  3037. }
  3038. }
  3039. /* free arguments and pattern buffer */
  3040. free_value (a);
  3041. free_value (b);
  3042. regfree (&rp);
  3043. return v;
  3044. }