MMRScriptTokenize.cs 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. /**
  28. * @brief Parse raw source file string into token list.
  29. *
  30. * Usage:
  31. *
  32. * emsg = some function to output error messages to
  33. * source = string containing entire source file
  34. *
  35. * TokenBegin tokenBegin = TokenBegin.Construct (emsg, source);
  36. *
  37. * tokenBegin = null: tokenizing error
  38. * else: first (dummy) token in file
  39. * the rest are chained by nextToken,prevToken
  40. * final token is always a (dummy) TokenEnd
  41. */
  42. using System;
  43. using System.Collections.Generic;
  44. using System.IO;
  45. using System.Net;
  46. using System.Reflection;
  47. using System.Reflection.Emit;
  48. using System.Text;
  49. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  50. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  51. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  52. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  53. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  54. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  55. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  56. namespace OpenSim.Region.ScriptEngine.Yengine
  57. {
  58. public delegate void TokenErrorMessage(Token token, string message);
  59. /**
  60. * @brief base class for all tokens
  61. */
  62. public class Token
  63. {
  64. public static readonly int MAX_NAME_LEN = 255;
  65. public static readonly int MAX_STRING_LEN = 4096;
  66. public Token nextToken;
  67. public Token prevToken;
  68. public bool nr2l;
  69. // used for error message printing
  70. public TokenErrorMessage emsg;
  71. public string file = "";
  72. public int line;
  73. public int posn;
  74. public Token copiedFrom;
  75. /**
  76. * @brief construct a token coming directly from a source file
  77. * @param emsg = object that error messages get sent to
  78. * @param file = source file name (or "" if none)
  79. * @param line = source file line number
  80. * @param posn = token's position within that source line
  81. */
  82. public Token(TokenErrorMessage emsg, string file, int line, int posn)
  83. {
  84. this.emsg = emsg;
  85. this.file = file;
  86. this.line = line;
  87. this.posn = posn;
  88. }
  89. /**
  90. * @brief construct a token with same error message parameters
  91. * @param original = original token to create from
  92. */
  93. public Token(Token original)
  94. {
  95. if(original != null)
  96. {
  97. this.emsg = original.emsg;
  98. this.file = original.file;
  99. this.line = original.line;
  100. this.posn = original.posn;
  101. this.nr2l = original.nr2l;
  102. }
  103. }
  104. /**
  105. * @brief output an error message associated with this token
  106. * sends the message to the token's error object
  107. * @param message = error message string
  108. */
  109. public void ErrorMsg(string message)
  110. {
  111. if(emsg != null)
  112. {
  113. emsg(this, message);
  114. }
  115. }
  116. /*
  117. * Generate a unique string (for use in CIL label names, etc)
  118. */
  119. public string Unique
  120. {
  121. get
  122. {
  123. return file + "_" + line + "_" + posn;
  124. }
  125. }
  126. /*
  127. * Generate source location string (for use in error messages)
  128. */
  129. public string SrcLoc
  130. {
  131. get
  132. {
  133. string loc = file + "(" + line + "," + posn + ")";
  134. if(copiedFrom == null)
  135. return loc;
  136. string fromLoc = copiedFrom.SrcLoc;
  137. if(fromLoc.StartsWith(loc))
  138. return fromLoc;
  139. return loc + ":" + fromLoc;
  140. }
  141. }
  142. /*
  143. * Used in generic instantiation to copy token.
  144. * Only valid for parsing tokens, not reduction tokens
  145. * because it is a shallow copy.
  146. */
  147. public Token CopyToken(Token src)
  148. {
  149. Token t = (Token)this.MemberwiseClone();
  150. t.file = src.file;
  151. t.line = src.line;
  152. t.posn = src.posn;
  153. t.copiedFrom = this;
  154. return t;
  155. }
  156. /*
  157. * Generate debugging string - should look like source code.
  158. */
  159. public virtual void DebString(StringBuilder sb)
  160. {
  161. sb.Append(this.ToString());
  162. }
  163. }
  164. /**
  165. * @brief token that begins a source file
  166. * Along with TokenEnd, it keeps insertion/removal of intermediate tokens
  167. * simple as the intermediate tokens always have non-null nextToken,prevToken.
  168. */
  169. public class TokenBegin: Token
  170. {
  171. private class Options
  172. {
  173. public bool arrays; // has seen 'XMROption arrays;'
  174. public bool advFlowCtl; // has seen 'XMROption advFlowCtl;'
  175. public bool tryCatch; // has seen 'XMROption tryCatch;'
  176. public bool objects; // has seen 'XMROption objects;'
  177. public bool chars; // has seen 'XMROption chars;'
  178. public bool noRightToLeft; // has seen 'XMROption noRightToLeft;'
  179. public bool dollarsigns; // has seen 'XMROption dollarsigns;'
  180. }
  181. private bool youveAnError; // there was some error tokenizing
  182. private int bolIdx; // index in 'source' at begining of current line
  183. private int lineNo; // current line in source file, starting at 0
  184. private string filNam; // current source file name
  185. private string source; // the whole script source code
  186. private Token lastToken; // last token created so far
  187. private string cameFrom; // where the source came from
  188. private TextWriter saveSource; // save copy of source here (or null)
  189. private Options options = new Options();
  190. /**
  191. * @brief convert a source file in the form of a string
  192. * to a list of raw tokens
  193. * @param cameFrom = where the source came from
  194. * @param emsg = where to output messages to
  195. * @param source = whole source file contents
  196. * @returns null: conversion error, message already output
  197. * else: list of tokens, starting with TokenBegin, ending with TokenEnd.
  198. */
  199. public static TokenBegin Construct(string cameFrom, TextWriter saveSource, TokenErrorMessage emsg, string source, out string sourceHash)
  200. {
  201. sourceHash = null;
  202. // Now do the tokenization.
  203. TokenBegin tokenBegin = new TokenBegin(emsg, "", 0, 0);
  204. tokenBegin.cameFrom = cameFrom;
  205. tokenBegin.saveSource = saveSource;
  206. tokenBegin.lastToken = tokenBegin;
  207. tokenBegin.source = source;
  208. tokenBegin.filNam = cameFrom;
  209. if(saveSource != null)
  210. saveSource.WriteLine(source);
  211. tokenBegin.Tokenize();
  212. if(tokenBegin.youveAnError)
  213. return null;
  214. tokenBegin.AppendToken(new TokenEnd(emsg, tokenBegin.filNam, ++tokenBegin.lineNo, 0));
  215. /*
  216. * Return source hash so caller can know if source changes.
  217. */
  218. System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
  219. byte[] hashBytes = md5.ComputeHash(new TokenStream(tokenBegin));
  220. int hashBytesLen = hashBytes.Length;
  221. StringBuilder sb = new StringBuilder(hashBytesLen * 2);
  222. for(int i = 0; i < hashBytesLen; i++)
  223. {
  224. sb.Append(hashBytes[i].ToString("X2"));
  225. }
  226. sourceHash = sb.ToString();
  227. if(saveSource != null)
  228. {
  229. saveSource.WriteLine(" ");
  230. saveSource.WriteLine("********************************************************************************");
  231. saveSource.WriteLine("**** source hash: " + sourceHash);
  232. saveSource.WriteLine("********************************************************************************");
  233. }
  234. return tokenBegin;
  235. }
  236. private TokenBegin(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  237. /*
  238. * Stream consisting of all the tokens.
  239. * Null delimeters between the tokens.
  240. * Used for creating the source hash.
  241. */
  242. private class TokenStream: Stream
  243. {
  244. private Token curTok;
  245. private bool delim;
  246. private byte[] curBuf;
  247. private int curOfs;
  248. private int curLen;
  249. public TokenStream(Token t)
  250. {
  251. curTok = t;
  252. }
  253. public override bool CanRead
  254. {
  255. get
  256. {
  257. return true;
  258. }
  259. }
  260. public override bool CanSeek
  261. {
  262. get
  263. {
  264. return false;
  265. }
  266. }
  267. public override bool CanWrite
  268. {
  269. get
  270. {
  271. return false;
  272. }
  273. }
  274. public override long Length
  275. {
  276. get
  277. {
  278. return 0;
  279. }
  280. }
  281. public override long Position
  282. {
  283. get
  284. {
  285. return 0;
  286. }
  287. set
  288. {
  289. }
  290. }
  291. public override void Write(byte[] buffer, int offset, int count)
  292. {
  293. }
  294. public override void Flush()
  295. {
  296. }
  297. public override long Seek(long offset, SeekOrigin origin)
  298. {
  299. return 0;
  300. }
  301. public override void SetLength(long value)
  302. {
  303. }
  304. public override int Read(byte[] buffer, int offset, int count)
  305. {
  306. int len, total;
  307. for(total = 0; total < count; total += len)
  308. {
  309. while((len = curLen - curOfs) <= 0)
  310. {
  311. if(curTok is TokenEnd)
  312. goto done;
  313. curTok = curTok.nextToken;
  314. if(curTok is TokenEnd)
  315. goto done;
  316. curBuf = System.Text.Encoding.UTF8.GetBytes(curTok.ToString());
  317. curOfs = 0;
  318. curLen = curBuf.Length;
  319. delim = true;
  320. }
  321. if(delim)
  322. {
  323. buffer[offset + total] = 0;
  324. delim = false;
  325. len = 1;
  326. }
  327. else
  328. {
  329. if(len > count - total)
  330. len = count - total;
  331. Array.Copy(curBuf, curOfs, buffer, offset + total, len);
  332. curOfs += len;
  333. }
  334. }
  335. done:
  336. return total;
  337. }
  338. }
  339. /*
  340. * Produces raw token stream: names, numbers, strings, keywords/delimeters.
  341. * @param this.source = whole source file in one string
  342. * @returns this.nextToken = filled in with tokens
  343. * this.youveAnError = true: some tokenizing error
  344. * false: successful
  345. */
  346. private void Tokenize()
  347. {
  348. bolIdx = 0;
  349. lineNo = 0;
  350. for(int i = 0; i < source.Length; i++)
  351. {
  352. char c = source[i];
  353. if(c == '\n')
  354. {
  355. // Increment source line number and set char index of beg of next line.
  356. lineNo++;
  357. bolIdx = i + 1;
  358. // Check for '#' lineno filename newline
  359. // lineno is line number of next line in file
  360. // If found, save values and remove tokens from stream
  361. if((lastToken is TokenStr) &&
  362. (lastToken.prevToken is TokenInt) &&
  363. (lastToken.prevToken.prevToken is TokenKwHash))
  364. {
  365. filNam = ((TokenStr)lastToken).val;
  366. lineNo = ((TokenInt)lastToken.prevToken).val;
  367. lastToken = lastToken.prevToken.prevToken.prevToken;
  368. lastToken.nextToken = null;
  369. }
  370. continue;
  371. }
  372. // Skip over whitespace.
  373. if(c <= ' ')
  374. continue;
  375. // Skip over comments.
  376. if((i + 2 <= source.Length) && source.Substring(i, 2).Equals("//"))
  377. {
  378. while((i < source.Length) && (source[i] != '\n'))
  379. i++;
  380. lineNo++;
  381. bolIdx = i + 1;
  382. continue;
  383. }
  384. if((i + 2 <= source.Length) && (source.Substring(i, 2).Equals("/*")))
  385. {
  386. i += 2;
  387. while((i + 1 < source.Length) && (((c = source[i]) != '*') || (source[i + 1] != '/')))
  388. {
  389. if(c == '\n')
  390. {
  391. lineNo++;
  392. bolIdx = i + 1;
  393. }
  394. i++;
  395. }
  396. i++;
  397. continue;
  398. }
  399. // Check for numbers.
  400. if((c >= '0') && (c <= '9'))
  401. {
  402. int j = TryParseFloat(i);
  403. if(j == 0)
  404. j = TryParseInt(i);
  405. i = --j;
  406. continue;
  407. }
  408. if((c == '.') && (i + 1 < source.Length) && (source[i + 1] >= '0') && (source[i + 1] <= '9'))
  409. {
  410. int j = TryParseFloat(i);
  411. if(j > 0)
  412. i = --j;
  413. continue;
  414. }
  415. // Check for quoted strings.
  416. if(c == '"')
  417. {
  418. StringBuilder sb = new StringBuilder();
  419. bool backslash;
  420. int j;
  421. backslash = false;
  422. for(j = i; ++j < source.Length;)
  423. {
  424. c = source[j];
  425. if(c == '\\' && !backslash)
  426. {
  427. backslash = true;
  428. continue;
  429. }
  430. if(c == '\n')
  431. {
  432. lineNo++;
  433. bolIdx = j + 1;
  434. }
  435. else
  436. {
  437. if(!backslash && (c == '"'))
  438. break;
  439. if(backslash && (c == 'n'))
  440. c = '\n';
  441. if(backslash && (c == 't'))
  442. {
  443. sb.Append(" ");
  444. c = ' ';
  445. }
  446. }
  447. backslash = false;
  448. sb.Append(c);
  449. }
  450. if(j - i > MAX_STRING_LEN)
  451. {
  452. TokenError(i, "string too long, max " + MAX_STRING_LEN);
  453. }
  454. else
  455. {
  456. AppendToken(new TokenStr(emsg, filNam, lineNo, i - bolIdx, sb.ToString()));
  457. }
  458. i = j;
  459. continue;
  460. }
  461. // Check for quoted characters.
  462. if(c == '\'')
  463. {
  464. char cb = (char)0;
  465. bool backslash, overflow, underflow;
  466. int j;
  467. backslash = false;
  468. overflow = false;
  469. underflow = true;
  470. for(j = i; ++j < source.Length;)
  471. {
  472. c = source[j];
  473. if(c == '\\' && !backslash)
  474. {
  475. backslash = true;
  476. continue;
  477. }
  478. if(c == '\n')
  479. {
  480. lineNo++;
  481. bolIdx = j + 1;
  482. }
  483. else
  484. {
  485. if(!backslash && (c == '\''))
  486. break;
  487. if(backslash && (c == 'n'))
  488. c = '\n';
  489. if(backslash && (c == 't'))
  490. c = '\t';
  491. }
  492. backslash = false;
  493. overflow = !underflow;
  494. underflow = false;
  495. cb = c;
  496. }
  497. if(underflow || overflow)
  498. {
  499. TokenError(i, "character must be exactly one character");
  500. }
  501. else
  502. {
  503. AppendToken(new TokenChar(emsg, filNam, lineNo, i - bolIdx, cb));
  504. }
  505. i = j;
  506. continue;
  507. }
  508. // Check for keywords/names.
  509. if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_') || (c == '$' && options.dollarsigns))
  510. {
  511. int j;
  512. for(j = i; ++j < source.Length;)
  513. {
  514. c = source[j];
  515. if(c >= 'a' && c <= 'z')
  516. continue;
  517. if(c >= 'A' && c <= 'Z')
  518. continue;
  519. if(c >= '0' && c <= '9')
  520. continue;
  521. if(c == '$' && options.dollarsigns)
  522. continue;
  523. if(c != '_')
  524. break;
  525. }
  526. if(j - i > MAX_NAME_LEN)
  527. {
  528. TokenError(i, "name too long, max " + MAX_NAME_LEN);
  529. }
  530. else
  531. {
  532. string name = source.Substring(i, j - i);
  533. if(name == "quaternion")
  534. name = "rotation"; // see lslangtest1.lsl
  535. if(keywords.ContainsKey(name))
  536. {
  537. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  538. AppendToken((Token)keywords[name].Invoke(args));
  539. }
  540. else if(options.arrays && arrayKeywords.ContainsKey(name))
  541. {
  542. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  543. AppendToken((Token)arrayKeywords[name].Invoke(args));
  544. }
  545. else if(options.advFlowCtl && advFlowCtlKeywords.ContainsKey(name))
  546. {
  547. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  548. AppendToken((Token)advFlowCtlKeywords[name].Invoke(args));
  549. }
  550. else if(options.tryCatch && tryCatchKeywords.ContainsKey(name))
  551. {
  552. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  553. AppendToken((Token)tryCatchKeywords[name].Invoke(args));
  554. }
  555. else if(options.objects && objectsKeywords.ContainsKey(name))
  556. {
  557. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  558. AppendToken((Token)objectsKeywords[name].Invoke(args));
  559. }
  560. else if(options.chars && charsKeywords.ContainsKey(name))
  561. {
  562. Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
  563. AppendToken((Token)charsKeywords[name].Invoke(args));
  564. }
  565. else
  566. {
  567. AppendToken(new TokenName(emsg, filNam, lineNo, i - bolIdx, name));
  568. }
  569. }
  570. i = --j;
  571. continue;
  572. }
  573. // Check for option enables.
  574. if ((c == ';') && (lastToken is TokenName))
  575. {
  576. if(strcasecmp(((TokenName)lastToken).val, "yoptions") == 0)
  577. {
  578. options.advFlowCtl = true;
  579. options.tryCatch = true;
  580. lastToken = lastToken.prevToken;
  581. lastToken.nextToken = null;
  582. continue;
  583. }
  584. else if ((lastToken.prevToken is TokenName) &&
  585. (strcasecmp(((TokenName)lastToken.prevToken).val, "yoption") == 0))
  586. {
  587. string opt = ((TokenName)lastToken).val;
  588. if(strcasecmp(opt, "allowall") == 0)
  589. {
  590. options.arrays = true;
  591. options.advFlowCtl = true;
  592. options.tryCatch = true;
  593. options.objects = true;
  594. options.chars = true;
  595. // options.noRightToLeft = true;
  596. options.dollarsigns = true;
  597. }
  598. else if(strcasecmp(opt, "arrays") == 0)
  599. options.arrays = true;
  600. else if(strcasecmp(opt, "advflowctl") == 0)
  601. options.advFlowCtl = true;
  602. else if(strcasecmp(opt, "trycatch") == 0)
  603. options.tryCatch = true;
  604. else if(strcasecmp(opt, "objects") == 0)
  605. options.objects = true;
  606. else if(strcasecmp(opt, "chars") == 0)
  607. options.chars = true;
  608. else if(strcasecmp(opt, "norighttoleft") == 0)
  609. options.noRightToLeft = true;
  610. else if(strcasecmp(opt, "dollarsigns") == 0)
  611. options.dollarsigns = true;
  612. else
  613. lastToken.ErrorMsg("unknown YOption");
  614. lastToken = lastToken.prevToken.prevToken;
  615. lastToken.nextToken = null;
  616. continue;
  617. }
  618. }
  619. // Lastly, check for delimeters.
  620. {
  621. int j;
  622. int len = 0;
  623. for(j = 0; j < delims.Length; j++)
  624. {
  625. len = delims[j].str.Length;
  626. if((i + len <= source.Length) && (source.Substring(i, len).Equals(delims[j].str)))
  627. break;
  628. }
  629. if(j < delims.Length)
  630. {
  631. Object[] args = { emsg, filNam, lineNo, i - bolIdx };
  632. Token kwToken = (Token)delims[j].ctorInfo.Invoke(args);
  633. AppendToken(kwToken);
  634. i += --len;
  635. continue;
  636. }
  637. }
  638. // Don't know what it is!
  639. TokenError(i, "unknown character '" + c + "'");
  640. }
  641. }
  642. private static int strcasecmp(String s, String t)
  643. {
  644. return String.Compare(s, t, StringComparison.OrdinalIgnoreCase);
  645. }
  646. /**
  647. * @brief try to parse a floating-point number from the source
  648. * @param i = starting position within this.source of number
  649. * @returns 0: not a floating point number, try something else
  650. * else: position in this.source of terminating character, ie, past number
  651. * TokenFloat appended to token list
  652. * or error message has been output
  653. */
  654. private int TryParseFloat(int i)
  655. {
  656. bool decimals, error, negexp, nulexp;
  657. char c;
  658. double f, f10;
  659. int exponent, j, x, y;
  660. ulong m, mantissa;
  661. decimals = false;
  662. error = false;
  663. exponent = 0;
  664. mantissa = 0;
  665. for(j = i; j < source.Length; j++)
  666. {
  667. c = source[j];
  668. if((c >= '0') && (c <= '9'))
  669. {
  670. m = mantissa * 10 + (ulong)(c - '0');
  671. if(m / 10 != mantissa)
  672. {
  673. if(!decimals)
  674. exponent++;
  675. }
  676. else
  677. {
  678. mantissa = m;
  679. if(decimals)
  680. exponent--;
  681. }
  682. continue;
  683. }
  684. if(c == '.')
  685. {
  686. if(decimals)
  687. {
  688. TokenError(i, "more than one decimal point");
  689. return j;
  690. }
  691. decimals = true;
  692. continue;
  693. }
  694. if((c == 'E') || (c == 'e'))
  695. {
  696. if(++j >= source.Length)
  697. {
  698. TokenError(i, "floating exponent off end of source");
  699. return j;
  700. }
  701. c = source[j];
  702. negexp = (c == '-');
  703. if(negexp || (c == '+'))
  704. j++;
  705. y = 0;
  706. nulexp = true;
  707. for(; j < source.Length; j++)
  708. {
  709. c = source[j];
  710. if((c < '0') || (c > '9'))
  711. break;
  712. x = y * 10 + (c - '0');
  713. if(x / 10 != y)
  714. {
  715. if(!error)
  716. TokenError(i, "floating exponent overflow");
  717. error = true;
  718. }
  719. y = x;
  720. nulexp = false;
  721. }
  722. if(nulexp)
  723. {
  724. TokenError(i, "bad or missing floating exponent");
  725. return j;
  726. }
  727. if(negexp)
  728. {
  729. x = exponent - y;
  730. if(x > exponent)
  731. {
  732. if(!error)
  733. TokenError(i, "floating exponent overflow");
  734. error = true;
  735. }
  736. }
  737. else
  738. {
  739. x = exponent + y;
  740. if(x < exponent)
  741. {
  742. if(!error)
  743. TokenError(i, "floating exponent overflow");
  744. error = true;
  745. }
  746. }
  747. exponent = x;
  748. }
  749. if ((c == 'F') || (c == 'f'))
  750. {
  751. if (++j >= source.Length)
  752. {
  753. TokenError(i, "f at end of source");
  754. return j;
  755. }
  756. c = source[j];
  757. if (((c >= '0') && (c <= '9')) || c == '.' || ((c == 'E') || (c == 'e')) || ((c == 'F') || (c == 'f')))
  758. {
  759. TokenError(j-1, "Syntax error");
  760. return j;
  761. }
  762. break;
  763. }
  764. break;
  765. }
  766. if(!decimals)
  767. {
  768. return 0;
  769. }
  770. f = mantissa;
  771. if((exponent != 0) && (mantissa != 0) && !error)
  772. {
  773. f10 = 10.0;
  774. if(exponent < 0)
  775. {
  776. exponent = -exponent;
  777. while(exponent > 0)
  778. {
  779. if((exponent & 1) != 0)
  780. {
  781. f /= f10;
  782. }
  783. exponent /= 2;
  784. f10 *= f10;
  785. }
  786. }
  787. else
  788. {
  789. while(exponent > 0)
  790. {
  791. if((exponent & 1) != 0)
  792. {
  793. f *= f10;
  794. }
  795. exponent /= 2;
  796. f10 *= f10;
  797. }
  798. }
  799. }
  800. if(!error)
  801. {
  802. AppendToken(new TokenFloat(emsg, filNam, lineNo, i - bolIdx, f));
  803. }
  804. return j;
  805. }
  806. /**
  807. * @brief try to parse an integer number from the source
  808. * @param i = starting position within this.source of number
  809. * @returns 0: not an integer number, try something else
  810. * else: position in this.source of terminating character, ie, past number
  811. * TokenInt appended to token list
  812. * or error message has been output
  813. */
  814. private int TryParseInt(int i)
  815. {
  816. bool error;
  817. char c;
  818. int j;
  819. uint basse, m, mantissa;
  820. basse = 10;
  821. error = false;
  822. mantissa = 0;
  823. for(j = i; j < source.Length; j++)
  824. {
  825. c = source[j];
  826. if((c >= '0') && (c <= '9'))
  827. {
  828. m = mantissa * basse + (uint)(c - '0');
  829. if(m / basse != mantissa)
  830. {
  831. if(!error)
  832. TokenError(i, "integer overflow");
  833. error = true;
  834. }
  835. mantissa = m;
  836. continue;
  837. }
  838. if((basse == 16) && ((c >= 'A') && (c <= 'F')))
  839. {
  840. m = mantissa * basse + (uint)(c - 'A') + 10U;
  841. if(m / basse != mantissa)
  842. {
  843. if(!error)
  844. TokenError(i, "integer overflow");
  845. error = true;
  846. }
  847. mantissa = m;
  848. continue;
  849. }
  850. if((basse == 16) && ((c >= 'a') && (c <= 'f')))
  851. {
  852. m = mantissa * basse + (uint)(c - 'a') + 10U;
  853. if(m / basse != mantissa)
  854. {
  855. if(!error)
  856. TokenError(i, "integer overflow");
  857. error = true;
  858. }
  859. mantissa = m;
  860. continue;
  861. }
  862. if(((c == 'x') || (c == 'X')) && (mantissa == 0) && (basse == 10))
  863. {
  864. basse = 16;
  865. continue;
  866. }
  867. break;
  868. }
  869. if(!error)
  870. {
  871. AppendToken(new TokenInt(emsg, filNam, lineNo, i - bolIdx, (int)mantissa));
  872. }
  873. return j;
  874. }
  875. /**
  876. * @brief append token on to end of list
  877. * @param newToken = token to append
  878. * @returns with token appended onto this.lastToken
  879. */
  880. private void AppendToken(Token newToken)
  881. {
  882. newToken.nextToken = null;
  883. newToken.prevToken = lastToken;
  884. newToken.nr2l = this.options.noRightToLeft;
  885. lastToken.nextToken = newToken;
  886. lastToken = newToken;
  887. }
  888. /**
  889. * @brief print tokenizing error message
  890. * and remember that we've an error
  891. * @param i = position within source file of the error
  892. * @param message = error message text
  893. * @returns with this.youveAnError set
  894. */
  895. private void TokenError(int i, string message)
  896. {
  897. Token temp = new Token(this.emsg, this.filNam, this.lineNo, i - this.bolIdx);
  898. temp.ErrorMsg(message);
  899. youveAnError = true;
  900. }
  901. /**
  902. * @brief get a token's constructor
  903. * @param tokenType = token's type
  904. * @returns token's constructor
  905. */
  906. private static Type[] constrTypes = new Type[] {
  907. typeof (TokenErrorMessage), typeof (string), typeof (int), typeof (int)
  908. };
  909. private static System.Reflection.ConstructorInfo GetTokenCtor(Type tokenType)
  910. {
  911. return tokenType.GetConstructor(constrTypes);
  912. }
  913. /**
  914. * @brief delimeter table
  915. */
  916. private class Delim
  917. {
  918. public string str;
  919. public System.Reflection.ConstructorInfo ctorInfo;
  920. public Delim(string str, Type type)
  921. {
  922. this.str = str;
  923. ctorInfo = GetTokenCtor(type);
  924. }
  925. }
  926. private static Delim[] delims = new Delim[] {
  927. new Delim ("...", typeof (TokenKwDotDotDot)),
  928. new Delim ("&&&", typeof (TokenKwAndAndAnd)),
  929. new Delim ("|||", typeof (TokenKwOrOrOr)),
  930. new Delim ("<<=", typeof (TokenKwAsnLSh)),
  931. new Delim (">>=", typeof (TokenKwAsnRSh)),
  932. new Delim ("<=", typeof (TokenKwCmpLE)),
  933. new Delim (">=", typeof (TokenKwCmpGE)),
  934. new Delim ("==", typeof (TokenKwCmpEQ)),
  935. new Delim ("!=", typeof (TokenKwCmpNE)),
  936. new Delim ("++", typeof (TokenKwIncr)),
  937. new Delim ("--", typeof (TokenKwDecr)),
  938. new Delim ("&&", typeof (TokenKwAndAnd)),
  939. new Delim ("||", typeof (TokenKwOrOr)),
  940. new Delim ("+=", typeof (TokenKwAsnAdd)),
  941. new Delim ("&=", typeof (TokenKwAsnAnd)),
  942. new Delim ("-=", typeof (TokenKwAsnSub)),
  943. new Delim ("*=", typeof (TokenKwAsnMul)),
  944. new Delim ("/=", typeof (TokenKwAsnDiv)),
  945. new Delim ("%=", typeof (TokenKwAsnMod)),
  946. new Delim ("|=", typeof (TokenKwAsnOr)),
  947. new Delim ("^=", typeof (TokenKwAsnXor)),
  948. new Delim ("<<", typeof (TokenKwLSh)),
  949. new Delim (">>", typeof (TokenKwRSh)),
  950. new Delim ("~", typeof (TokenKwTilde)),
  951. new Delim ("!", typeof (TokenKwExclam)),
  952. new Delim ("@", typeof (TokenKwAt)),
  953. new Delim ("%", typeof (TokenKwMod)),
  954. new Delim ("^", typeof (TokenKwXor)),
  955. new Delim ("&", typeof (TokenKwAnd)),
  956. new Delim ("*", typeof (TokenKwMul)),
  957. new Delim ("(", typeof (TokenKwParOpen)),
  958. new Delim (")", typeof (TokenKwParClose)),
  959. new Delim ("-", typeof (TokenKwSub)),
  960. new Delim ("+", typeof (TokenKwAdd)),
  961. new Delim ("=", typeof (TokenKwAssign)),
  962. new Delim ("{", typeof (TokenKwBrcOpen)),
  963. new Delim ("}", typeof (TokenKwBrcClose)),
  964. new Delim ("[", typeof (TokenKwBrkOpen)),
  965. new Delim ("]", typeof (TokenKwBrkClose)),
  966. new Delim (";", typeof (TokenKwSemi)),
  967. new Delim (":", typeof (TokenKwColon)),
  968. new Delim ("<", typeof (TokenKwCmpLT)),
  969. new Delim (">", typeof (TokenKwCmpGT)),
  970. new Delim (",", typeof (TokenKwComma)),
  971. new Delim (".", typeof (TokenKwDot)),
  972. new Delim ("?", typeof (TokenKwQMark)),
  973. new Delim ("/", typeof (TokenKwDiv)),
  974. new Delim ("|", typeof (TokenKwOr)),
  975. new Delim ("#", typeof (TokenKwHash))
  976. };
  977. /**
  978. * @brief keyword tables
  979. * The keyword tables translate a keyword string
  980. * to the corresponding token constructor.
  981. */
  982. private static Dictionary<string, System.Reflection.ConstructorInfo> keywords = BuildKeywords();
  983. private static Dictionary<string, System.Reflection.ConstructorInfo> arrayKeywords = BuildArrayKeywords();
  984. private static Dictionary<string, System.Reflection.ConstructorInfo> advFlowCtlKeywords = BuildAdvFlowCtlKeywords();
  985. private static Dictionary<string, System.Reflection.ConstructorInfo> tryCatchKeywords = BuildTryCatchKeywords();
  986. private static Dictionary<string, System.Reflection.ConstructorInfo> objectsKeywords = BuildObjectsKeywords();
  987. private static Dictionary<string, System.Reflection.ConstructorInfo> charsKeywords = BuildCharsKeywords();
  988. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildKeywords()
  989. {
  990. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  991. kws.Add("default", GetTokenCtor(typeof(TokenKwDefault)));
  992. kws.Add("do", GetTokenCtor(typeof(TokenKwDo)));
  993. kws.Add("else", GetTokenCtor(typeof(TokenKwElse)));
  994. kws.Add("float", GetTokenCtor(typeof(TokenTypeFloat)));
  995. kws.Add("for", GetTokenCtor(typeof(TokenKwFor)));
  996. kws.Add("if", GetTokenCtor(typeof(TokenKwIf)));
  997. kws.Add("integer", GetTokenCtor(typeof(TokenTypeInt)));
  998. kws.Add("list", GetTokenCtor(typeof(TokenTypeList)));
  999. kws.Add("jump", GetTokenCtor(typeof(TokenKwJump)));
  1000. kws.Add("key", GetTokenCtor(typeof(TokenTypeKey)));
  1001. kws.Add("return", GetTokenCtor(typeof(TokenKwRet)));
  1002. kws.Add("rotation", GetTokenCtor(typeof(TokenTypeRot)));
  1003. kws.Add("state", GetTokenCtor(typeof(TokenKwState)));
  1004. kws.Add("string", GetTokenCtor(typeof(TokenTypeStr)));
  1005. kws.Add("vector", GetTokenCtor(typeof(TokenTypeVec)));
  1006. kws.Add("while", GetTokenCtor(typeof(TokenKwWhile)));
  1007. return kws;
  1008. }
  1009. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildArrayKeywords()
  1010. {
  1011. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1012. kws.Add("array", GetTokenCtor(typeof(TokenTypeArray)));
  1013. kws.Add("foreach", GetTokenCtor(typeof(TokenKwForEach)));
  1014. kws.Add("in", GetTokenCtor(typeof(TokenKwIn)));
  1015. kws.Add("is", GetTokenCtor(typeof(TokenKwIs)));
  1016. kws.Add("object", GetTokenCtor(typeof(TokenTypeObject)));
  1017. kws.Add("undef", GetTokenCtor(typeof(TokenKwUndef)));
  1018. return kws;
  1019. }
  1020. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildAdvFlowCtlKeywords()
  1021. {
  1022. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1023. kws.Add("break", GetTokenCtor(typeof(TokenKwBreak)));
  1024. kws.Add("case", GetTokenCtor(typeof(TokenKwCase)));
  1025. kws.Add("constant", GetTokenCtor(typeof(TokenKwConst)));
  1026. kws.Add("continue", GetTokenCtor(typeof(TokenKwCont)));
  1027. kws.Add("switch", GetTokenCtor(typeof(TokenKwSwitch)));
  1028. return kws;
  1029. }
  1030. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildTryCatchKeywords()
  1031. {
  1032. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1033. kws.Add("catch", GetTokenCtor(typeof(TokenKwCatch)));
  1034. kws.Add("exception", GetTokenCtor(typeof(TokenTypeExc)));
  1035. kws.Add("finally", GetTokenCtor(typeof(TokenKwFinally)));
  1036. kws.Add("throw", GetTokenCtor(typeof(TokenKwThrow)));
  1037. kws.Add("try", GetTokenCtor(typeof(TokenKwTry)));
  1038. return kws;
  1039. }
  1040. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildObjectsKeywords()
  1041. {
  1042. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1043. kws.Add("abstract", GetTokenCtor(typeof(TokenKwAbstract)));
  1044. kws.Add("base", GetTokenCtor(typeof(TokenKwBase)));
  1045. kws.Add("class", GetTokenCtor(typeof(TokenKwClass)));
  1046. kws.Add("constructor", GetTokenCtor(typeof(TokenKwConstructor)));
  1047. kws.Add("delegate", GetTokenCtor(typeof(TokenKwDelegate)));
  1048. kws.Add("destructor", GetTokenCtor(typeof(TokenKwDestructor)));
  1049. kws.Add("final", GetTokenCtor(typeof(TokenKwFinal)));
  1050. kws.Add("get", GetTokenCtor(typeof(TokenKwGet)));
  1051. kws.Add("interface", GetTokenCtor(typeof(TokenKwInterface)));
  1052. kws.Add("new", GetTokenCtor(typeof(TokenKwNew)));
  1053. kws.Add("override", GetTokenCtor(typeof(TokenKwOverride)));
  1054. kws.Add("partial", GetTokenCtor(typeof(TokenKwPartial)));
  1055. kws.Add("private", GetTokenCtor(typeof(TokenKwPrivate)));
  1056. kws.Add("protected", GetTokenCtor(typeof(TokenKwProtected)));
  1057. kws.Add("public", GetTokenCtor(typeof(TokenKwPublic)));
  1058. kws.Add("set", GetTokenCtor(typeof(TokenKwSet)));
  1059. kws.Add("static", GetTokenCtor(typeof(TokenKwStatic)));
  1060. kws.Add("this", GetTokenCtor(typeof(TokenKwThis)));
  1061. kws.Add("typedef", GetTokenCtor(typeof(TokenKwTypedef)));
  1062. kws.Add("virtual", GetTokenCtor(typeof(TokenKwVirtual)));
  1063. return kws;
  1064. }
  1065. private static Dictionary<string, System.Reflection.ConstructorInfo> BuildCharsKeywords()
  1066. {
  1067. Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo>();
  1068. kws.Add("char", GetTokenCtor(typeof(TokenTypeChar)));
  1069. return kws;
  1070. }
  1071. }
  1072. /**
  1073. * @brief All output token types in addition to TokenBegin.
  1074. * They are all sub-types of Token.
  1075. */
  1076. public class TokenChar: Token
  1077. {
  1078. public char val;
  1079. public TokenChar(TokenErrorMessage emsg, string file, int line, int posn, char val) : base(emsg, file, line, posn)
  1080. {
  1081. this.val = val;
  1082. }
  1083. public TokenChar(Token original, char val) : base(original)
  1084. {
  1085. this.val = val;
  1086. }
  1087. public override string ToString()
  1088. {
  1089. switch(val)
  1090. {
  1091. case '\'':
  1092. return "'\\''";
  1093. case '\\':
  1094. return "'\\\\'";
  1095. case '\n':
  1096. return "'\\n'";
  1097. case '\t':
  1098. return "'\\t'";
  1099. default:
  1100. return "'" + val + "'";
  1101. }
  1102. }
  1103. }
  1104. public class TokenFloat: Token
  1105. {
  1106. public double val;
  1107. public TokenFloat(TokenErrorMessage emsg, string file, int line, int posn, double val) : base(emsg, file, line, posn)
  1108. {
  1109. this.val = val;
  1110. }
  1111. public override string ToString()
  1112. {
  1113. return val.ToString();
  1114. }
  1115. }
  1116. public class TokenInt: Token
  1117. {
  1118. public int val;
  1119. public TokenInt(TokenErrorMessage emsg, string file, int line, int posn, int val) : base(emsg, file, line, posn)
  1120. {
  1121. this.val = val;
  1122. }
  1123. public TokenInt(Token original, int val) : base(original)
  1124. {
  1125. this.val = val;
  1126. }
  1127. public override string ToString()
  1128. {
  1129. return val.ToString();
  1130. }
  1131. }
  1132. public class TokenName: Token
  1133. {
  1134. public string val;
  1135. public TokenName(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1136. {
  1137. this.val = val;
  1138. }
  1139. public TokenName(Token original, string val) : base(original)
  1140. {
  1141. this.val = val;
  1142. }
  1143. public override string ToString()
  1144. {
  1145. return this.val;
  1146. }
  1147. }
  1148. public class TokenStr: Token
  1149. {
  1150. public string val;
  1151. public TokenStr(TokenErrorMessage emsg, string file, int line, int posn, string val) : base(emsg, file, line, posn)
  1152. {
  1153. this.val = val;
  1154. }
  1155. public override string ToString()
  1156. {
  1157. if((val.IndexOf('"') < 0) &&
  1158. (val.IndexOf('\\') < 0) &&
  1159. (val.IndexOf('\n') < 0) &&
  1160. (val.IndexOf('\t') < 0))
  1161. return "\"" + val + "\"";
  1162. int len = val.Length;
  1163. StringBuilder sb = new StringBuilder(len * 2 + 2);
  1164. sb.Append('"');
  1165. for(int i = 0; i < len; i++)
  1166. {
  1167. char c = val[i];
  1168. switch(c)
  1169. {
  1170. case '"':
  1171. {
  1172. sb.Append('\\');
  1173. sb.Append('"');
  1174. break;
  1175. }
  1176. case '\\':
  1177. {
  1178. sb.Append('\\');
  1179. sb.Append('\\');
  1180. break;
  1181. }
  1182. case '\n':
  1183. {
  1184. sb.Append('\\');
  1185. sb.Append('n');
  1186. break;
  1187. }
  1188. case '\t':
  1189. {
  1190. sb.Append('\\');
  1191. sb.Append('t');
  1192. break;
  1193. }
  1194. default:
  1195. {
  1196. sb.Append(c);
  1197. break;
  1198. }
  1199. }
  1200. }
  1201. return sb.ToString();
  1202. }
  1203. }
  1204. /*
  1205. * This one marks the end-of-file.
  1206. */
  1207. public class TokenEnd: Token
  1208. {
  1209. public TokenEnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  1210. }
  1211. /*
  1212. * Various keywords and delimeters.
  1213. */
  1214. public delegate object TokenRValConstBinOpDelegate(object left, object right);
  1215. public delegate object TokenRValConstUnOpDelegate(object right);
  1216. public class TokenKw: Token
  1217. {
  1218. public TokenRValConstBinOpDelegate binOpConst;
  1219. public TokenRValConstUnOpDelegate unOpConst;
  1220. public bool sdtClassOp;
  1221. public TokenKw(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1222. {
  1223. }
  1224. public TokenKw(Token original) : base(original)
  1225. {
  1226. }
  1227. }
  1228. public class TokenKwDotDotDot: TokenKw
  1229. {
  1230. public TokenKwDotDotDot(TokenErrorMessage emsg, string file,
  1231. int line, int posn) : base(emsg, file, line, posn)
  1232. {
  1233. binOpConst = TokenRValConstOps.Null;
  1234. unOpConst = TokenRValConstOps.Null;
  1235. sdtClassOp = false;
  1236. }
  1237. public TokenKwDotDotDot(Token original) : base(original)
  1238. {
  1239. binOpConst = TokenRValConstOps.Null;
  1240. unOpConst = TokenRValConstOps.Null;
  1241. sdtClassOp = false;
  1242. }
  1243. public override string ToString()
  1244. {
  1245. return "...";
  1246. }
  1247. }
  1248. public class TokenKwAndAndAnd: TokenKw
  1249. {
  1250. public TokenKwAndAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1251. {
  1252. binOpConst = TokenRValConstOps.binConstsLogicAndAnd;
  1253. unOpConst = TokenRValConstOps.Null;
  1254. sdtClassOp = false;
  1255. }
  1256. public TokenKwAndAndAnd(Token original) : base(original)
  1257. {
  1258. binOpConst = TokenRValConstOps.binConstsLogicAndAnd;
  1259. unOpConst = TokenRValConstOps.Null;
  1260. sdtClassOp = false;
  1261. }
  1262. public override string ToString()
  1263. {
  1264. return "&&&";
  1265. }
  1266. }
  1267. public class TokenKwOrOrOr: TokenKw
  1268. {
  1269. public TokenKwOrOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1270. {
  1271. binOpConst = TokenRValConstOps.binConstsLoginOrOr;
  1272. unOpConst = TokenRValConstOps.Null;
  1273. sdtClassOp = false;
  1274. }
  1275. public TokenKwOrOrOr(Token original) : base(original)
  1276. {
  1277. binOpConst = TokenRValConstOps.binConstsLoginOrOr;
  1278. unOpConst = TokenRValConstOps.Null;
  1279. sdtClassOp = false;
  1280. }
  1281. public override string ToString()
  1282. {
  1283. return "|||";
  1284. }
  1285. }
  1286. public class TokenKwAsnLSh: TokenKw
  1287. {
  1288. public TokenKwAsnLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn)
  1289. {
  1290. binOpConst = TokenRValConstOps.Null;
  1291. unOpConst = TokenRValConstOps.Null;
  1292. sdtClassOp = true;
  1293. }
  1294. public TokenKwAsnLSh(Token original) : base(original)
  1295. {
  1296. binOpConst = TokenRValConstOps.Null;
  1297. unOpConst = TokenRValConstOps.Null;
  1298. sdtClassOp = true;
  1299. }
  1300. public override string ToString()
  1301. {
  1302. return "<<=";
  1303. }
  1304. }
  1305. public class TokenKwAsnRSh: TokenKw
  1306. {
  1307. public TokenKwAsnRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1308. public TokenKwAsnRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1309. public override string ToString()
  1310. {
  1311. return ">>=";
  1312. }
  1313. }
  1314. public class TokenKwCmpLE: TokenKw
  1315. {
  1316. public TokenKwCmpLE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1317. public TokenKwCmpLE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1318. public override string ToString()
  1319. {
  1320. return "<=";
  1321. }
  1322. }
  1323. public class TokenKwCmpGE: TokenKw
  1324. {
  1325. public TokenKwCmpGE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1326. public TokenKwCmpGE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1327. public override string ToString()
  1328. {
  1329. return ">=";
  1330. }
  1331. }
  1332. public class TokenKwCmpEQ: TokenKw
  1333. {
  1334. public TokenKwCmpEQ(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1335. public TokenKwCmpEQ(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsEQ; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1336. public override string ToString()
  1337. {
  1338. return "==";
  1339. }
  1340. }
  1341. public class TokenKwCmpNE: TokenKw
  1342. {
  1343. public TokenKwCmpNE(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1344. public TokenKwCmpNE(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsNE; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1345. public override string ToString()
  1346. {
  1347. return "!=";
  1348. }
  1349. }
  1350. public class TokenKwIncr: TokenKw
  1351. {
  1352. public TokenKwIncr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1353. public TokenKwIncr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1354. public override string ToString()
  1355. {
  1356. return "++";
  1357. }
  1358. }
  1359. public class TokenKwDecr: TokenKw
  1360. {
  1361. public TokenKwDecr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1362. public TokenKwDecr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1363. public override string ToString()
  1364. {
  1365. return "--";
  1366. }
  1367. }
  1368. public class TokenKwAndAnd: TokenKw
  1369. {
  1370. public TokenKwAndAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLogicAndAnd; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1371. public TokenKwAndAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLogicAndAnd; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1372. public override string ToString()
  1373. {
  1374. return "&&";
  1375. }
  1376. }
  1377. public class TokenKwOrOr: TokenKw
  1378. {
  1379. public TokenKwOrOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLoginOrOr; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1380. public TokenKwOrOr(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLoginOrOr; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1381. public override string ToString()
  1382. {
  1383. return "||";
  1384. }
  1385. }
  1386. public class TokenKwAsnAdd: TokenKw
  1387. {
  1388. public TokenKwAsnAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1389. public TokenKwAsnAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1390. public override string ToString()
  1391. {
  1392. return "+=";
  1393. }
  1394. }
  1395. public class TokenKwAsnAnd: TokenKw
  1396. {
  1397. public TokenKwAsnAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1398. public TokenKwAsnAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1399. public override string ToString()
  1400. {
  1401. return "&=";
  1402. }
  1403. }
  1404. public class TokenKwAsnSub: TokenKw
  1405. {
  1406. public TokenKwAsnSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1407. public TokenKwAsnSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1408. public override string ToString()
  1409. {
  1410. return "-=";
  1411. }
  1412. }
  1413. public class TokenKwAsnMul: TokenKw
  1414. {
  1415. public TokenKwAsnMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1416. public TokenKwAsnMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1417. public override string ToString()
  1418. {
  1419. return "*=";
  1420. }
  1421. }
  1422. public class TokenKwAsnDiv: TokenKw
  1423. {
  1424. public TokenKwAsnDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1425. public TokenKwAsnDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1426. public override string ToString()
  1427. {
  1428. return "/=";
  1429. }
  1430. }
  1431. public class TokenKwAsnMod: TokenKw
  1432. {
  1433. public TokenKwAsnMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1434. public TokenKwAsnMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1435. public override string ToString()
  1436. {
  1437. return "%=";
  1438. }
  1439. }
  1440. public class TokenKwAsnOr: TokenKw
  1441. {
  1442. public TokenKwAsnOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1443. public TokenKwAsnOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1444. public override string ToString()
  1445. {
  1446. return "|=";
  1447. }
  1448. }
  1449. public class TokenKwAsnXor: TokenKw
  1450. {
  1451. public TokenKwAsnXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1452. public TokenKwAsnXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1453. public override string ToString()
  1454. {
  1455. return "^=";
  1456. }
  1457. }
  1458. public class TokenKwLSh: TokenKw
  1459. {
  1460. public TokenKwLSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1461. public TokenKwLSh(Token original) : base(original) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1462. public override string ToString()
  1463. {
  1464. return "<<";
  1465. }
  1466. }
  1467. public class TokenKwRSh: TokenKw
  1468. {
  1469. public TokenKwRSh(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1470. public TokenKwRSh(Token original) : base(original) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1471. public override string ToString()
  1472. {
  1473. return ">>";
  1474. }
  1475. }
  1476. public class TokenKwTilde: TokenKw
  1477. {
  1478. public TokenKwTilde(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1479. public TokenKwTilde(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; }
  1480. public override string ToString()
  1481. {
  1482. return "~";
  1483. }
  1484. }
  1485. public class TokenKwExclam: TokenKw
  1486. {
  1487. public TokenKwExclam(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.unOpExclam; sdtClassOp = true; }
  1488. public TokenKwExclam(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.unOpExclam; sdtClassOp = true; }
  1489. public override string ToString()
  1490. {
  1491. return "!";
  1492. }
  1493. }
  1494. public class TokenKwAt: TokenKw
  1495. {
  1496. public TokenKwAt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1497. public TokenKwAt(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1498. public override string ToString()
  1499. {
  1500. return "@";
  1501. }
  1502. }
  1503. public class TokenKwMod: TokenKw
  1504. {
  1505. public TokenKwMod(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1506. public TokenKwMod(Token original) : base(original) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1507. public override string ToString()
  1508. {
  1509. return "%";
  1510. }
  1511. }
  1512. public class TokenKwXor: TokenKw
  1513. {
  1514. public TokenKwXor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1515. public TokenKwXor(Token original) : base(original) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1516. public override string ToString()
  1517. {
  1518. return "^";
  1519. }
  1520. }
  1521. public class TokenKwAnd: TokenKw
  1522. {
  1523. public TokenKwAnd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1524. public TokenKwAnd(Token original) : base(original) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1525. public override string ToString()
  1526. {
  1527. return "&";
  1528. }
  1529. }
  1530. public class TokenKwMul: TokenKw
  1531. {
  1532. public TokenKwMul(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1533. public TokenKwMul(Token original) : base(original) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1534. public override string ToString()
  1535. {
  1536. return "*";
  1537. }
  1538. }
  1539. public class TokenKwParOpen: TokenKw
  1540. {
  1541. public TokenKwParOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1542. public TokenKwParOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1543. public override string ToString()
  1544. {
  1545. return "(";
  1546. }
  1547. }
  1548. public class TokenKwParClose: TokenKw
  1549. {
  1550. public TokenKwParClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1551. public TokenKwParClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1552. public override string ToString()
  1553. {
  1554. return ")";
  1555. }
  1556. }
  1557. public class TokenKwSub: TokenKw
  1558. {
  1559. public TokenKwSub(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1560. public TokenKwSub(Token original) : base(original) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; }
  1561. public override string ToString()
  1562. {
  1563. return "-";
  1564. }
  1565. }
  1566. public class TokenKwAdd: TokenKw
  1567. {
  1568. public TokenKwAdd(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1569. public TokenKwAdd(Token original) : base(original) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1570. public override string ToString()
  1571. {
  1572. return "+";
  1573. }
  1574. }
  1575. public class TokenKwAssign: TokenKw
  1576. {
  1577. public TokenKwAssign(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1578. public TokenKwAssign(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1579. public override string ToString()
  1580. {
  1581. return "=";
  1582. }
  1583. }
  1584. public class TokenKwBrcOpen: TokenKw
  1585. {
  1586. public TokenKwBrcOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1587. public TokenKwBrcOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1588. public override string ToString()
  1589. {
  1590. return "{";
  1591. }
  1592. }
  1593. public class TokenKwBrcClose: TokenKw
  1594. {
  1595. public TokenKwBrcClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1596. public TokenKwBrcClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1597. public override string ToString()
  1598. {
  1599. return "}";
  1600. }
  1601. }
  1602. public class TokenKwBrkOpen: TokenKw
  1603. {
  1604. public TokenKwBrkOpen(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1605. public TokenKwBrkOpen(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1606. public override string ToString()
  1607. {
  1608. return "[";
  1609. }
  1610. }
  1611. public class TokenKwBrkClose: TokenKw
  1612. {
  1613. public TokenKwBrkClose(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1614. public TokenKwBrkClose(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1615. public override string ToString()
  1616. {
  1617. return "]";
  1618. }
  1619. }
  1620. public class TokenKwSemi: TokenKw
  1621. {
  1622. public TokenKwSemi(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1623. public TokenKwSemi(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1624. public override string ToString()
  1625. {
  1626. return ";";
  1627. }
  1628. }
  1629. public class TokenKwColon: TokenKw
  1630. {
  1631. public TokenKwColon(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1632. public TokenKwColon(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1633. public override string ToString()
  1634. {
  1635. return ":";
  1636. }
  1637. }
  1638. public class TokenKwCmpLT: TokenKw
  1639. {
  1640. public TokenKwCmpLT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1641. public TokenKwCmpLT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsLT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1642. public override string ToString()
  1643. {
  1644. return "<";
  1645. }
  1646. }
  1647. public class TokenKwCmpGT: TokenKw
  1648. {
  1649. public TokenKwCmpGT(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1650. public TokenKwCmpGT(Token original) : base(original) { binOpConst = TokenRValConstOps.binConstsGT; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1651. public override string ToString()
  1652. {
  1653. return ">";
  1654. }
  1655. }
  1656. public class TokenKwComma: TokenKw
  1657. {
  1658. public TokenKwComma(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1659. public TokenKwComma(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1660. public override string ToString()
  1661. {
  1662. return ",";
  1663. }
  1664. }
  1665. public class TokenKwDot: TokenKw
  1666. {
  1667. public TokenKwDot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1668. public TokenKwDot(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1669. public override string ToString()
  1670. {
  1671. return ".";
  1672. }
  1673. }
  1674. public class TokenKwQMark: TokenKw
  1675. {
  1676. public TokenKwQMark(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1677. public TokenKwQMark(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1678. public override string ToString()
  1679. {
  1680. return "?";
  1681. }
  1682. }
  1683. public class TokenKwDiv: TokenKw
  1684. {
  1685. public TokenKwDiv(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1686. public TokenKwDiv(Token original) : base(original) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1687. public override string ToString()
  1688. {
  1689. return "/";
  1690. }
  1691. }
  1692. public class TokenKwOr: TokenKw
  1693. {
  1694. public TokenKwOr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1695. public TokenKwOr(Token original) : base(original) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; }
  1696. public override string ToString()
  1697. {
  1698. return "|";
  1699. }
  1700. }
  1701. public class TokenKwHash: TokenKw
  1702. {
  1703. public TokenKwHash(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1704. public TokenKwHash(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1705. public override string ToString()
  1706. {
  1707. return "#";
  1708. }
  1709. }
  1710. public class TokenKwAbstract: TokenKw
  1711. {
  1712. public TokenKwAbstract(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1713. public TokenKwAbstract(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1714. public override string ToString()
  1715. {
  1716. return "abstract";
  1717. }
  1718. }
  1719. public class TokenKwBase: TokenKw
  1720. {
  1721. public TokenKwBase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1722. public TokenKwBase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1723. public override string ToString()
  1724. {
  1725. return "base";
  1726. }
  1727. }
  1728. public class TokenKwBreak: TokenKw
  1729. {
  1730. public TokenKwBreak(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1731. public TokenKwBreak(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1732. public override string ToString()
  1733. {
  1734. return "break";
  1735. }
  1736. }
  1737. public class TokenKwCase: TokenKw
  1738. {
  1739. public TokenKwCase(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1740. public TokenKwCase(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1741. public override string ToString()
  1742. {
  1743. return "case";
  1744. }
  1745. }
  1746. public class TokenKwCatch: TokenKw
  1747. {
  1748. public TokenKwCatch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1749. public TokenKwCatch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1750. public override string ToString()
  1751. {
  1752. return "catch";
  1753. }
  1754. }
  1755. public class TokenKwClass: TokenKw
  1756. {
  1757. public TokenKwClass(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1758. public TokenKwClass(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1759. public override string ToString()
  1760. {
  1761. return "class";
  1762. }
  1763. }
  1764. public class TokenKwConst: TokenKw
  1765. {
  1766. public TokenKwConst(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1767. public TokenKwConst(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1768. public override string ToString()
  1769. {
  1770. return "constant";
  1771. }
  1772. }
  1773. public class TokenKwConstructor: TokenKw
  1774. {
  1775. public TokenKwConstructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1776. public TokenKwConstructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1777. public override string ToString()
  1778. {
  1779. return "constructor";
  1780. }
  1781. }
  1782. public class TokenKwCont: TokenKw
  1783. {
  1784. public TokenKwCont(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1785. public TokenKwCont(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1786. public override string ToString()
  1787. {
  1788. return "continue";
  1789. }
  1790. }
  1791. public class TokenKwDelegate: TokenKw
  1792. {
  1793. public TokenKwDelegate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1794. public TokenKwDelegate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1795. public override string ToString()
  1796. {
  1797. return "delegate";
  1798. }
  1799. }
  1800. public class TokenKwDefault: TokenKw
  1801. {
  1802. public TokenKwDefault(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1803. public TokenKwDefault(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1804. public override string ToString()
  1805. {
  1806. return "default";
  1807. }
  1808. }
  1809. public class TokenKwDestructor: TokenKw
  1810. {
  1811. public TokenKwDestructor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1812. public TokenKwDestructor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1813. public override string ToString()
  1814. {
  1815. return "destructor";
  1816. }
  1817. }
  1818. public class TokenKwDo: TokenKw
  1819. {
  1820. public TokenKwDo(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1821. public TokenKwDo(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1822. public override string ToString()
  1823. {
  1824. return "do";
  1825. }
  1826. }
  1827. public class TokenKwElse: TokenKw
  1828. {
  1829. public TokenKwElse(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1830. public TokenKwElse(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1831. public override string ToString()
  1832. {
  1833. return "else";
  1834. }
  1835. }
  1836. public class TokenKwFinal: TokenKw
  1837. {
  1838. public TokenKwFinal(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1839. public TokenKwFinal(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1840. public override string ToString()
  1841. {
  1842. return "final";
  1843. }
  1844. }
  1845. public class TokenKwFinally: TokenKw
  1846. {
  1847. public TokenKwFinally(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1848. public TokenKwFinally(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1849. public override string ToString()
  1850. {
  1851. return "finally";
  1852. }
  1853. }
  1854. public class TokenKwFor: TokenKw
  1855. {
  1856. public TokenKwFor(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1857. public TokenKwFor(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1858. public override string ToString()
  1859. {
  1860. return "for";
  1861. }
  1862. }
  1863. public class TokenKwForEach: TokenKw
  1864. {
  1865. public TokenKwForEach(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1866. public TokenKwForEach(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1867. public override string ToString()
  1868. {
  1869. return "foreach";
  1870. }
  1871. }
  1872. public class TokenKwGet: TokenKw
  1873. {
  1874. public TokenKwGet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1875. public TokenKwGet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1876. public override string ToString()
  1877. {
  1878. return "get";
  1879. }
  1880. }
  1881. public class TokenKwIf: TokenKw
  1882. {
  1883. public TokenKwIf(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1884. public TokenKwIf(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1885. public override string ToString()
  1886. {
  1887. return "if";
  1888. }
  1889. }
  1890. public class TokenKwIn: TokenKw
  1891. {
  1892. public TokenKwIn(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1893. public TokenKwIn(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1894. public override string ToString()
  1895. {
  1896. return "in";
  1897. }
  1898. }
  1899. public class TokenKwInterface: TokenKw
  1900. {
  1901. public TokenKwInterface(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1902. public TokenKwInterface(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1903. public override string ToString()
  1904. {
  1905. return "interface";
  1906. }
  1907. }
  1908. public class TokenKwIs: TokenKw
  1909. {
  1910. public TokenKwIs(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1911. public TokenKwIs(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1912. public override string ToString()
  1913. {
  1914. return "is";
  1915. }
  1916. }
  1917. public class TokenKwJump: TokenKw
  1918. {
  1919. public TokenKwJump(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1920. public TokenKwJump(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1921. public override string ToString()
  1922. {
  1923. return "jump";
  1924. }
  1925. }
  1926. public class TokenKwNew: TokenKw
  1927. {
  1928. public TokenKwNew(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1929. public TokenKwNew(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1930. public override string ToString()
  1931. {
  1932. return "new";
  1933. }
  1934. }
  1935. public class TokenKwOverride: TokenKw
  1936. {
  1937. public TokenKwOverride(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1938. public TokenKwOverride(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1939. public override string ToString()
  1940. {
  1941. return "override";
  1942. }
  1943. }
  1944. public class TokenKwPartial: TokenKw
  1945. {
  1946. public TokenKwPartial(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1947. public TokenKwPartial(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1948. public override string ToString()
  1949. {
  1950. return "partial";
  1951. }
  1952. }
  1953. public class TokenKwPrivate: TokenKw
  1954. {
  1955. public TokenKwPrivate(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1956. public TokenKwPrivate(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1957. public override string ToString()
  1958. {
  1959. return "private";
  1960. }
  1961. }
  1962. public class TokenKwProtected: TokenKw
  1963. {
  1964. public TokenKwProtected(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1965. public TokenKwProtected(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1966. public override string ToString()
  1967. {
  1968. return "protected";
  1969. }
  1970. }
  1971. public class TokenKwPublic: TokenKw
  1972. {
  1973. public TokenKwPublic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1974. public TokenKwPublic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1975. public override string ToString()
  1976. {
  1977. return "public";
  1978. }
  1979. }
  1980. public class TokenKwRet: TokenKw
  1981. {
  1982. public TokenKwRet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1983. public TokenKwRet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1984. public override string ToString()
  1985. {
  1986. return "return";
  1987. }
  1988. }
  1989. public class TokenKwSet: TokenKw
  1990. {
  1991. public TokenKwSet(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1992. public TokenKwSet(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  1993. public override string ToString()
  1994. {
  1995. return "set";
  1996. }
  1997. }
  1998. public class TokenKwState: TokenKw
  1999. {
  2000. public TokenKwState(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2001. public TokenKwState(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2002. public override string ToString()
  2003. {
  2004. return "state";
  2005. }
  2006. }
  2007. public class TokenKwStatic: TokenKw
  2008. {
  2009. public TokenKwStatic(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2010. public TokenKwStatic(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2011. public override string ToString()
  2012. {
  2013. return "static";
  2014. }
  2015. }
  2016. public class TokenKwSwitch: TokenKw
  2017. {
  2018. public TokenKwSwitch(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2019. public TokenKwSwitch(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2020. public override string ToString()
  2021. {
  2022. return "switch";
  2023. }
  2024. }
  2025. public class TokenKwThis: TokenKw
  2026. {
  2027. public TokenKwThis(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2028. public TokenKwThis(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2029. public override string ToString()
  2030. {
  2031. return "this";
  2032. }
  2033. }
  2034. public class TokenKwThrow: TokenKw
  2035. {
  2036. public TokenKwThrow(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2037. public TokenKwThrow(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2038. public override string ToString()
  2039. {
  2040. return "throw";
  2041. }
  2042. }
  2043. public class TokenKwTry: TokenKw
  2044. {
  2045. public TokenKwTry(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2046. public TokenKwTry(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2047. public override string ToString()
  2048. {
  2049. return "try";
  2050. }
  2051. }
  2052. public class TokenKwTypedef: TokenKw
  2053. {
  2054. public TokenKwTypedef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2055. public TokenKwTypedef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2056. public override string ToString()
  2057. {
  2058. return "typedef";
  2059. }
  2060. }
  2061. public class TokenKwUndef: TokenKw
  2062. {
  2063. public TokenKwUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2064. public TokenKwUndef(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2065. public override string ToString()
  2066. {
  2067. return "undef";
  2068. }
  2069. }
  2070. public class TokenKwVirtual: TokenKw
  2071. {
  2072. public TokenKwVirtual(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2073. public TokenKwVirtual(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2074. public override string ToString()
  2075. {
  2076. return "virtual";
  2077. }
  2078. }
  2079. public class TokenKwWhile: TokenKw
  2080. {
  2081. public TokenKwWhile(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2082. public TokenKwWhile(Token original) : base(original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; }
  2083. public override string ToString()
  2084. {
  2085. return "while";
  2086. }
  2087. }
  2088. /**
  2089. * @brief These static functions attempt to perform arithmetic on two constant
  2090. * operands to generate the resultant constant.
  2091. * Likewise for unary operators.
  2092. *
  2093. * @param left = left-hand value
  2094. * @param right = right-hand value
  2095. * @returns null: not able to perform computation
  2096. * else: resultant value object
  2097. *
  2098. * Note: it is ok for these to throw any exception (such as overflow or div-by-zero),
  2099. * and it will be treated as the 'not able to perform computation' case.
  2100. */
  2101. public class TokenRValConstOps
  2102. {
  2103. public static object Null(object left, object right)
  2104. {
  2105. return null;
  2106. }
  2107. public static object Div(object left, object right)
  2108. {
  2109. double r;
  2110. try
  2111. {
  2112. if ((left is int li) && (right is int ri))
  2113. {
  2114. if(li == -2147483648 && ri == -1)
  2115. return -2147483648;
  2116. return (int)left / (int)right;
  2117. }
  2118. if ((left is double) && (right is int))
  2119. {
  2120. r = (double)left / (int)right;
  2121. if (double.IsNaN(r) || double.IsInfinity(r))
  2122. throw new Exception("Division by Zero");
  2123. return r;
  2124. }
  2125. }
  2126. catch (DivideByZeroException)
  2127. {
  2128. throw new Exception("Division by Zero");
  2129. }
  2130. if ((left is int) && (right is double))
  2131. {
  2132. r = (int)left / (double)right;
  2133. }
  2134. else if((left is double) && (right is double))
  2135. {
  2136. r= (double)left / (double)right;
  2137. }
  2138. else
  2139. return null;
  2140. if (double.IsNaN(r) || double.IsInfinity(r))
  2141. throw new Exception("Division by Zero");
  2142. return r;
  2143. }
  2144. public static object Mod(object left, object right)
  2145. {
  2146. double r;
  2147. try
  2148. {
  2149. if ((left is int li) && (right is int ri))
  2150. {
  2151. if (li == -2147483648 && ri == -1)
  2152. return 0;
  2153. return li % ri;
  2154. }
  2155. if ((left is double) && (right is int))
  2156. {
  2157. r = (double)left % (int)right;
  2158. if (double.IsNaN(r) || double.IsInfinity(r))
  2159. throw new Exception("Division by Zero");
  2160. return r;
  2161. }
  2162. }
  2163. catch (DivideByZeroException)
  2164. {
  2165. throw new Exception("Division by Zero");
  2166. }
  2167. if ((left is int) && (right is double))
  2168. {
  2169. r = (int)left % (double)right;
  2170. }
  2171. else if ((left is double) && (right is double))
  2172. {
  2173. r = (double)left % (double)right;
  2174. }
  2175. else
  2176. return null;
  2177. if (double.IsNaN(r) || double.IsInfinity(r))
  2178. throw new Exception("Division by Zero");
  2179. return r;
  2180. }
  2181. public static object Mul(object left, object right)
  2182. {
  2183. if((left is int) && (right is int))
  2184. {
  2185. return (int)left * (int)right;
  2186. }
  2187. if((left is int) && (right is double))
  2188. {
  2189. return (int)left * (double)right;
  2190. }
  2191. if((left is double) && (right is int))
  2192. {
  2193. return (double)left * (int)right;
  2194. }
  2195. if((left is double) && (right is double))
  2196. {
  2197. return (double)left * (double)right;
  2198. }
  2199. return null;
  2200. }
  2201. public static object And(object left, object right)
  2202. {
  2203. if((left is int) && (right is int))
  2204. {
  2205. return (int)left & (int)right;
  2206. }
  2207. return null;
  2208. }
  2209. public static object LSh(object left, object right)
  2210. {
  2211. if((left is int) && (right is int))
  2212. return (int)left << (int)right;
  2213. return null;
  2214. }
  2215. public static object Or(object left, object right)
  2216. {
  2217. if((left is int) && (right is int))
  2218. return (int)left | (int)right;
  2219. return null;
  2220. }
  2221. public static object RSh(object left, object right)
  2222. {
  2223. if((left is int) && (right is int))
  2224. return (int)left >> (int)right;
  2225. return null;
  2226. }
  2227. public static object Xor(object left, object right)
  2228. {
  2229. if((left is int) && (right is int))
  2230. return (int)left ^ (int)right;
  2231. return null;
  2232. }
  2233. public static object Add(object left, object right)
  2234. {
  2235. if((left is char) && (right is int))
  2236. {
  2237. return (char)((char)left + (int)right);
  2238. }
  2239. if((left is double) && (right is double))
  2240. {
  2241. return (double)left + (double)right;
  2242. }
  2243. if((left is double) && (right is int))
  2244. {
  2245. return (double)left + (int)right;
  2246. }
  2247. if((left is double) && (right is string))
  2248. {
  2249. return TypeCast.FloatToString((double)left) + (string)right;
  2250. }
  2251. if((left is int) && (right is double))
  2252. {
  2253. return (int)left + (double)right;
  2254. }
  2255. if((left is int) && (right is int))
  2256. {
  2257. return (int)left + (int)right;
  2258. }
  2259. if((left is int) && (right is string))
  2260. {
  2261. return TypeCast.IntegerToString((int)left) + (string)right;
  2262. }
  2263. if((left is string) && (right is char))
  2264. {
  2265. return (string)left + (char)right;
  2266. }
  2267. if((left is string) && (right is double))
  2268. {
  2269. return (string)left + TypeCast.FloatToString((double)right);
  2270. }
  2271. if((left is string) && (right is int))
  2272. {
  2273. return (string)left + TypeCast.IntegerToString((int)right);
  2274. }
  2275. if((left is string) && (right is string))
  2276. {
  2277. return (string)left + (string)right;
  2278. }
  2279. return null;
  2280. }
  2281. public static object Sub(object left, object right)
  2282. {
  2283. if((left is char) && (right is int))
  2284. {
  2285. return (char)((char)left - (int)right);
  2286. }
  2287. if((left is int) && (right is int))
  2288. {
  2289. return (int)left - (int)right;
  2290. }
  2291. if((left is int) && (right is double))
  2292. {
  2293. return (int)left - (double)right;
  2294. }
  2295. if((left is double) && (right is int))
  2296. {
  2297. return (double)left - (int)right;
  2298. }
  2299. if((left is double) && (right is double))
  2300. {
  2301. return (double)left - (double)right;
  2302. }
  2303. return null;
  2304. }
  2305. public static object Null(object right)
  2306. {
  2307. return null;
  2308. }
  2309. public static object Neg(object right)
  2310. {
  2311. if(right is int)
  2312. {
  2313. return -(int)right;
  2314. }
  2315. if(right is double)
  2316. {
  2317. return -(double)right;
  2318. }
  2319. return null;
  2320. }
  2321. public static object Not(object right)
  2322. {
  2323. if(right is int)
  2324. {
  2325. return ~(int)right;
  2326. }
  2327. return null;
  2328. }
  2329. public static int binConstCompare(object left, object right)
  2330. {
  2331. double a;
  2332. if (left is bool lb)
  2333. a = lb ? 1.0 : 0.0;
  2334. else if (left is int li)
  2335. a = li;
  2336. else if (left is float lf)
  2337. a = lf;
  2338. else if (left is double ld)
  2339. a = ld;
  2340. else if(left is string ls)
  2341. {
  2342. if(!(right is string rs))
  2343. return -2;
  2344. return ls.CompareTo(rs);
  2345. }
  2346. else
  2347. return -2;
  2348. double b;
  2349. if (right is bool rb)
  2350. b = rb ? 1.0 : 0.0;
  2351. else if (right is int ri)
  2352. b = ri;
  2353. else if (right is float rf)
  2354. b = rf;
  2355. else if (right is double rd)
  2356. b = rd;
  2357. else
  2358. return -2;
  2359. return a.CompareTo(b);
  2360. }
  2361. public static object binConstsLT(object left, object right)
  2362. {
  2363. int res = binConstCompare(left, right);
  2364. if (res == -2)
  2365. return null;
  2366. return (res < 0) ? 1 : 0;
  2367. }
  2368. public static object binConstsLE(object left, object right)
  2369. {
  2370. int res = binConstCompare(left, right);
  2371. if (res == -2)
  2372. return null;
  2373. return (res <= 0) ? 1 : 0;
  2374. }
  2375. public static object binConstsGT(object left, object right)
  2376. {
  2377. int res = binConstCompare(left, right);
  2378. if (res == -2)
  2379. return null;
  2380. return (res > 0) ? 1 : 0;
  2381. }
  2382. public static object binConstsGE(object left, object right)
  2383. {
  2384. int res = binConstCompare(left, right);
  2385. if (res == -2)
  2386. return null;
  2387. return (res >= 0) ? 1 : 0;
  2388. }
  2389. public static object binConstsEQ(object left, object right)
  2390. {
  2391. int res = binConstCompare(left, right);
  2392. if (res == -2)
  2393. return null;
  2394. return (res == 0) ? 1 : 0;
  2395. }
  2396. public static object binConstsNE(object left, object right)
  2397. {
  2398. int res = binConstCompare(left, right);
  2399. if (res == -2)
  2400. return null;
  2401. return (res != 0) ? 1 : 0;
  2402. }
  2403. public static object binConstsLogicAndAnd(object left, object right)
  2404. {
  2405. if ((left is int li) && (right is int ri))
  2406. {
  2407. if (li == 0)
  2408. return 0;
  2409. if (ri == 0)
  2410. return 0;
  2411. return 1;
  2412. }
  2413. return null;
  2414. }
  2415. public static object binConstsLoginOrOr(object left, object right)
  2416. {
  2417. if ((left is int li) && (right is int ri))
  2418. {
  2419. if (li != 0)
  2420. return 1;
  2421. if (ri != 0)
  2422. return 1;
  2423. return 0;
  2424. }
  2425. return null;
  2426. }
  2427. public static object unOpExclam(object left)
  2428. {
  2429. if ((left is int li))
  2430. {
  2431. if (li == 0)
  2432. return 1;
  2433. return 0;
  2434. }
  2435. return null;
  2436. }
  2437. }
  2438. /*
  2439. * Various datatypes.
  2440. */
  2441. public abstract class TokenType: Token
  2442. {
  2443. public TokenType(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2444. public TokenType(Token original) : base(original) { }
  2445. public static TokenType FromSysType(Token original, System.Type typ)
  2446. {
  2447. if(typ == typeof(LSL_List))
  2448. return new TokenTypeList(original);
  2449. if(typ == typeof(LSL_Rotation))
  2450. return new TokenTypeRot(original);
  2451. if(typ == typeof(void))
  2452. return new TokenTypeVoid(original);
  2453. if(typ == typeof(LSL_Vector))
  2454. return new TokenTypeVec(original);
  2455. if(typ == typeof(float))
  2456. return new TokenTypeFloat(original);
  2457. if(typ == typeof(int))
  2458. return new TokenTypeInt(original);
  2459. if(typ == typeof(string))
  2460. return new TokenTypeStr(original);
  2461. if(typ == typeof(double))
  2462. return new TokenTypeFloat(original);
  2463. if(typ == typeof(bool))
  2464. return new TokenTypeBool(original);
  2465. if(typ == typeof(object))
  2466. return new TokenTypeObject(original);
  2467. if(typ == typeof(XMR_Array))
  2468. return new TokenTypeArray(original);
  2469. if(typ == typeof(LSL_Integer))
  2470. return new TokenTypeLSLInt(original);
  2471. if(typ == typeof(LSL_Float))
  2472. return new TokenTypeLSLFloat(original);
  2473. if(typ == typeof(LSL_String))
  2474. return new TokenTypeLSLString(original);
  2475. if(typ == typeof(char))
  2476. return new TokenTypeChar(original);
  2477. if(typ == typeof(Exception))
  2478. return new TokenTypeExc(original);
  2479. throw new Exception("unknown script type " + typ.ToString());
  2480. }
  2481. public static TokenType FromLSLType(Token original, string typ)
  2482. {
  2483. if(typ == "list")
  2484. return new TokenTypeList(original);
  2485. if(typ == "rotation")
  2486. return new TokenTypeRot(original);
  2487. if(typ == "vector")
  2488. return new TokenTypeVec(original);
  2489. if(typ == "float")
  2490. return new TokenTypeFloat(original);
  2491. if(typ == "integer")
  2492. return new TokenTypeInt(original);
  2493. if(typ == "key")
  2494. return new TokenTypeKey(original);
  2495. if(typ == "string")
  2496. return new TokenTypeStr(original);
  2497. if(typ == "object")
  2498. return new TokenTypeObject(original);
  2499. if(typ == "array")
  2500. return new TokenTypeArray(original);
  2501. if(typ == "bool")
  2502. return new TokenTypeBool(original);
  2503. if(typ == "void")
  2504. return new TokenTypeVoid(original);
  2505. if(typ == "char")
  2506. return new TokenTypeChar(original);
  2507. if(typ == "exception")
  2508. return new TokenTypeExc(original);
  2509. throw new Exception("unknown type " + typ);
  2510. }
  2511. /**
  2512. * @brief Estimate the number of bytes of memory taken by one of these
  2513. * objects. For objects with widely varying size, return the
  2514. * smallest it can be.
  2515. */
  2516. public static int StaticSize(System.Type typ)
  2517. {
  2518. if(typ == typeof(LSL_List))
  2519. return 96;
  2520. if(typ == typeof(LSL_Rotation))
  2521. return 80;
  2522. if(typ == typeof(void))
  2523. return 0;
  2524. if(typ == typeof(LSL_Vector))
  2525. return 72;
  2526. if(typ == typeof(float))
  2527. return 8;
  2528. if(typ == typeof(int))
  2529. return 8;
  2530. if(typ == typeof(string))
  2531. return 40;
  2532. if(typ == typeof(double))
  2533. return 8;
  2534. if(typ == typeof(bool))
  2535. return 8;
  2536. if(typ == typeof(XMR_Array))
  2537. return 96;
  2538. if(typ == typeof(object))
  2539. return 32;
  2540. if(typ == typeof(char))
  2541. return 2;
  2542. if(typ == typeof(LSL_Integer))
  2543. return 32;
  2544. if(typ == typeof(LSL_Float))
  2545. return 32;
  2546. if(typ == typeof(LSL_String))
  2547. return 40;
  2548. throw new Exception("unknown type " + typ.ToString());
  2549. }
  2550. /**
  2551. * @brief Return the corresponding system type.
  2552. */
  2553. public abstract Type ToSysType();
  2554. /**
  2555. * @brief Return the equivalent LSL wrapping type.
  2556. *
  2557. * null: normal
  2558. * else: LSL-style wrapping, ie, LSL_Integer, LSL_Float, LSL_String
  2559. * ToSysType()=System.Int32; lslWrapping=LSL_Integer
  2560. * ToSysType()=System.Float; lslWrapping=LSL_Float
  2561. * ToSysType()=System.String; lslWrapping=LSL_String
  2562. */
  2563. public virtual Type ToLSLWrapType()
  2564. {
  2565. return null;
  2566. }
  2567. /**
  2568. * @brief Assign slots in either the global variable arrays or the script-defined type instance arrays.
  2569. * These only need to be implemented for script-visible types, ie, those that a script writer
  2570. * can actually define a variable as.
  2571. */
  2572. public virtual void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2573. {
  2574. throw new Exception("not implemented for " + ToString() + " (" + GetType() + ")");
  2575. }
  2576. /**
  2577. * @brief Get heap tracking type.
  2578. * null indicates there is no heap tracker for the type.
  2579. */
  2580. public virtual Type ToHeapTrackerType()
  2581. {
  2582. return null;
  2583. }
  2584. public virtual ConstructorInfo GetHeapTrackerCtor()
  2585. {
  2586. throw new ApplicationException("no GetHeapTrackerCtor for " + this.GetType());
  2587. }
  2588. public virtual void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2589. {
  2590. throw new ApplicationException("no CallHeapTrackerPopMeth for " + this.GetType());
  2591. }
  2592. public virtual void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2593. {
  2594. throw new ApplicationException("no CallHeapTrackerPushMeth for " + this.GetType());
  2595. }
  2596. }
  2597. public class TokenTypeArray: TokenType
  2598. {
  2599. private static readonly FieldInfo iarArraysFieldInfo = typeof(XMRInstArrays).GetField("iarArrays");
  2600. public TokenTypeArray(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2601. public TokenTypeArray(Token original) : base(original) { }
  2602. public override Type ToSysType()
  2603. {
  2604. return typeof(XMR_Array);
  2605. }
  2606. public override string ToString()
  2607. {
  2608. return "array";
  2609. }
  2610. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2611. {
  2612. declVar.vTableArray = iarArraysFieldInfo;
  2613. declVar.vTableIndex = arSizes.iasArrays++;
  2614. }
  2615. }
  2616. public class TokenTypeBool: TokenType
  2617. {
  2618. public TokenTypeBool(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2619. public TokenTypeBool(Token original) : base(original) { }
  2620. public override Type ToSysType()
  2621. {
  2622. return typeof(bool);
  2623. }
  2624. public override string ToString()
  2625. {
  2626. return "bool";
  2627. }
  2628. }
  2629. public class TokenTypeChar: TokenType
  2630. {
  2631. private static readonly FieldInfo iarCharsFieldInfo = typeof(XMRInstArrays).GetField("iarChars");
  2632. public TokenTypeChar(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2633. public TokenTypeChar(Token original) : base(original) { }
  2634. public override Type ToSysType()
  2635. {
  2636. return typeof(char);
  2637. }
  2638. public override string ToString()
  2639. {
  2640. return "char";
  2641. }
  2642. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2643. {
  2644. declVar.vTableArray = iarCharsFieldInfo;
  2645. declVar.vTableIndex = arSizes.iasChars++;
  2646. }
  2647. }
  2648. public class TokenTypeExc: TokenType
  2649. {
  2650. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2651. public TokenTypeExc(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2652. public TokenTypeExc(Token original) : base(original) { }
  2653. public override Type ToSysType()
  2654. {
  2655. return typeof(Exception);
  2656. }
  2657. public override string ToString()
  2658. {
  2659. return "exception";
  2660. }
  2661. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2662. {
  2663. declVar.vTableArray = iarObjectsFieldInfo;
  2664. declVar.vTableIndex = arSizes.iasObjects++;
  2665. }
  2666. }
  2667. public class TokenTypeFloat: TokenType
  2668. {
  2669. private static readonly FieldInfo iarFloatsFieldInfo = typeof(XMRInstArrays).GetField("iarFloats");
  2670. public TokenTypeFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2671. public TokenTypeFloat(Token original) : base(original) { }
  2672. public override Type ToSysType()
  2673. {
  2674. return typeof(double);
  2675. }
  2676. public override string ToString()
  2677. {
  2678. return "float";
  2679. }
  2680. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2681. {
  2682. declVar.vTableArray = iarFloatsFieldInfo;
  2683. declVar.vTableIndex = arSizes.iasFloats++;
  2684. }
  2685. }
  2686. public class TokenTypeInt: TokenType
  2687. {
  2688. private static readonly FieldInfo iarIntegersFieldInfo = typeof(XMRInstArrays).GetField("iarIntegers");
  2689. public TokenTypeInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2690. public TokenTypeInt(Token original) : base(original) { }
  2691. public override Type ToSysType()
  2692. {
  2693. return typeof(int);
  2694. }
  2695. public override string ToString()
  2696. {
  2697. return "integer";
  2698. }
  2699. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2700. {
  2701. declVar.vTableArray = iarIntegersFieldInfo;
  2702. declVar.vTableIndex = arSizes.iasIntegers++;
  2703. }
  2704. }
  2705. public class TokenTypeKey: TokenType
  2706. {
  2707. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2708. public TokenTypeKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2709. public TokenTypeKey(Token original) : base(original) { }
  2710. public override Type ToSysType()
  2711. {
  2712. return typeof(string);
  2713. }
  2714. public override string ToString()
  2715. {
  2716. return "key";
  2717. }
  2718. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2719. {
  2720. declVar.vTableArray = iarStringsFieldInfo;
  2721. declVar.vTableIndex = arSizes.iasStrings++;
  2722. }
  2723. }
  2724. public class TokenTypeList: TokenType
  2725. {
  2726. private static readonly FieldInfo iarListsFieldInfo = typeof(XMRInstArrays).GetField("iarLists");
  2727. private static readonly ConstructorInfo htListCtor = typeof(HeapTrackerList).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2728. public TokenTypeList(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2729. public TokenTypeList(Token original) : base(original) { }
  2730. public override Type ToSysType()
  2731. {
  2732. return typeof(LSL_List);
  2733. }
  2734. public override string ToString()
  2735. {
  2736. return "list";
  2737. }
  2738. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2739. {
  2740. declVar.vTableArray = iarListsFieldInfo;
  2741. declVar.vTableIndex = arSizes.iasLists++;
  2742. }
  2743. public override Type ToHeapTrackerType()
  2744. {
  2745. return typeof(HeapTrackerList);
  2746. }
  2747. public override ConstructorInfo GetHeapTrackerCtor()
  2748. {
  2749. return htListCtor;
  2750. }
  2751. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2752. {
  2753. HeapTrackerList.GenPop(errorAt, ilGen);
  2754. }
  2755. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2756. {
  2757. HeapTrackerList.GenPush(errorAt, ilGen);
  2758. }
  2759. }
  2760. public class TokenTypeObject: TokenType
  2761. {
  2762. private static readonly FieldInfo iarObjectsFieldInfo = typeof(XMRInstArrays).GetField("iarObjects");
  2763. private static readonly ConstructorInfo htObjectCtor = typeof(HeapTrackerObject).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2764. public TokenTypeObject(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2765. public TokenTypeObject(Token original) : base(original) { }
  2766. public override Type ToSysType()
  2767. {
  2768. return typeof(object);
  2769. }
  2770. public override string ToString()
  2771. {
  2772. return "object";
  2773. }
  2774. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2775. {
  2776. declVar.vTableArray = iarObjectsFieldInfo;
  2777. declVar.vTableIndex = arSizes.iasObjects++;
  2778. }
  2779. public override Type ToHeapTrackerType()
  2780. {
  2781. return typeof(HeapTrackerObject);
  2782. }
  2783. public override ConstructorInfo GetHeapTrackerCtor()
  2784. {
  2785. return htObjectCtor;
  2786. }
  2787. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2788. {
  2789. HeapTrackerObject.GenPop(errorAt, ilGen);
  2790. }
  2791. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2792. {
  2793. HeapTrackerObject.GenPush(errorAt, ilGen);
  2794. }
  2795. }
  2796. public class TokenTypeRot: TokenType
  2797. {
  2798. private static readonly FieldInfo iarRotationsFieldInfo = typeof(XMRInstArrays).GetField("iarRotations");
  2799. public TokenTypeRot(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2800. public TokenTypeRot(Token original) : base(original) { }
  2801. public override Type ToSysType()
  2802. {
  2803. return typeof(LSL_Rotation);
  2804. }
  2805. public override string ToString()
  2806. {
  2807. return "rotation";
  2808. }
  2809. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2810. {
  2811. declVar.vTableArray = iarRotationsFieldInfo;
  2812. declVar.vTableIndex = arSizes.iasRotations++;
  2813. }
  2814. }
  2815. public class TokenTypeStr: TokenType
  2816. {
  2817. private static readonly FieldInfo iarStringsFieldInfo = typeof(XMRInstArrays).GetField("iarStrings");
  2818. private static readonly ConstructorInfo htStringCtor = typeof(HeapTrackerString).GetConstructor(new Type[] { typeof(XMRInstAbstract) });
  2819. public TokenTypeStr(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2820. public TokenTypeStr(Token original) : base(original) { }
  2821. public override Type ToSysType()
  2822. {
  2823. return typeof(string);
  2824. }
  2825. public override string ToString()
  2826. {
  2827. return "string";
  2828. }
  2829. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2830. {
  2831. declVar.vTableArray = iarStringsFieldInfo;
  2832. declVar.vTableIndex = arSizes.iasStrings++;
  2833. }
  2834. public override Type ToHeapTrackerType()
  2835. {
  2836. return typeof(HeapTrackerString);
  2837. }
  2838. public override ConstructorInfo GetHeapTrackerCtor()
  2839. {
  2840. return htStringCtor;
  2841. }
  2842. public override void CallHeapTrackerPopMeth(Token errorAt, ScriptMyILGen ilGen)
  2843. {
  2844. HeapTrackerString.GenPop(errorAt, ilGen);
  2845. }
  2846. public override void CallHeapTrackerPushMeth(Token errorAt, ScriptMyILGen ilGen)
  2847. {
  2848. HeapTrackerString.GenPush(errorAt, ilGen);
  2849. }
  2850. }
  2851. public class TokenTypeUndef: TokenType
  2852. { // for the 'undef' constant, ie, null object pointer
  2853. public TokenTypeUndef(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2854. public TokenTypeUndef(Token original) : base(original) { }
  2855. public override Type ToSysType()
  2856. {
  2857. return typeof(object);
  2858. }
  2859. public override string ToString()
  2860. {
  2861. return "undef";
  2862. }
  2863. }
  2864. public class TokenTypeVec: TokenType
  2865. {
  2866. private static readonly FieldInfo iarVectorsFieldInfo = typeof(XMRInstArrays).GetField("iarVectors");
  2867. public TokenTypeVec(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2868. public TokenTypeVec(Token original) : base(original) { }
  2869. public override Type ToSysType()
  2870. {
  2871. return typeof(LSL_Vector);
  2872. }
  2873. public override string ToString()
  2874. {
  2875. return "vector";
  2876. }
  2877. public override void AssignVarSlot(TokenDeclVar declVar, XMRInstArSizes arSizes)
  2878. {
  2879. declVar.vTableArray = iarVectorsFieldInfo;
  2880. declVar.vTableIndex = arSizes.iasVectors++;
  2881. }
  2882. }
  2883. public class TokenTypeVoid: TokenType
  2884. { // used only for function/method return types
  2885. public TokenTypeVoid(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2886. public TokenTypeVoid(Token original) : base(original) { }
  2887. public override Type ToSysType()
  2888. {
  2889. return typeof(void);
  2890. }
  2891. public override string ToString()
  2892. {
  2893. return "void";
  2894. }
  2895. }
  2896. public class TokenTypeLSLFloat: TokenTypeFloat
  2897. {
  2898. public TokenTypeLSLFloat(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2899. public TokenTypeLSLFloat(Token original) : base(original) { }
  2900. public override Type ToLSLWrapType()
  2901. {
  2902. return typeof(LSL_Float);
  2903. }
  2904. }
  2905. public class TokenTypeLSLInt: TokenTypeInt
  2906. {
  2907. public TokenTypeLSLInt(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2908. public TokenTypeLSLInt(Token original) : base(original) { }
  2909. public override Type ToLSLWrapType()
  2910. {
  2911. return typeof(LSL_Integer);
  2912. }
  2913. }
  2914. public class TokenTypeLSLKey: TokenTypeKey
  2915. {
  2916. public TokenTypeLSLKey(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2917. public TokenTypeLSLKey(Token original) : base(original) { }
  2918. public override Type ToLSLWrapType()
  2919. {
  2920. return typeof(LSL_Key);
  2921. }
  2922. }
  2923. public class TokenTypeLSLString: TokenTypeStr
  2924. {
  2925. public TokenTypeLSLString(TokenErrorMessage emsg, string file, int line, int posn) : base(emsg, file, line, posn) { }
  2926. public TokenTypeLSLString(Token original) : base(original) { }
  2927. public override Type ToLSLWrapType()
  2928. {
  2929. return typeof(LSL_String);
  2930. }
  2931. }
  2932. }