ExcelFormulaParser.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. ### $ANTLR 2.7.7 (20060930): "xlwt/excel-formula.g" -> "ExcelFormulaParser.py"$
  2. ### import antlr and other modules ..
  3. from . import antlr
  4. ### header action >>>
  5. import struct
  6. from . import Utils
  7. from .UnicodeUtils import upack1
  8. from .ExcelMagic import *
  9. _RVAdelta = {"R": 0, "V": 0x20, "A": 0x40}
  10. _RVAdeltaRef = {"R": 0, "V": 0x20, "A": 0x40, "D": 0x20}
  11. _RVAdeltaArea = {"R": 0, "V": 0x20, "A": 0x40, "D": 0}
  12. class FormulaParseException(Exception):
  13. """
  14. An exception indicating that a Formula could not be successfully parsed.
  15. """
  16. ### header action <<<
  17. ### preamble action>>>
  18. ### preamble action <<<
  19. ### >>>The Known Token Types <<<
  20. SKIP = antlr.SKIP
  21. INVALID_TYPE = antlr.INVALID_TYPE
  22. EOF_TYPE = antlr.EOF_TYPE
  23. EOF = antlr.EOF
  24. NULL_TREE_LOOKAHEAD = antlr.NULL_TREE_LOOKAHEAD
  25. MIN_USER_TYPE = antlr.MIN_USER_TYPE
  26. TRUE_CONST = 4
  27. FALSE_CONST = 5
  28. STR_CONST = 6
  29. NUM_CONST = 7
  30. INT_CONST = 8
  31. FUNC_IF = 9
  32. FUNC_CHOOSE = 10
  33. NAME = 11
  34. QUOTENAME = 12
  35. EQ = 13
  36. NE = 14
  37. GT = 15
  38. LT = 16
  39. GE = 17
  40. LE = 18
  41. ADD = 19
  42. SUB = 20
  43. MUL = 21
  44. DIV = 22
  45. POWER = 23
  46. PERCENT = 24
  47. LP = 25
  48. RP = 26
  49. LB = 27
  50. RB = 28
  51. COLON = 29
  52. COMMA = 30
  53. SEMICOLON = 31
  54. REF2D = 32
  55. REF2D_R1C1 = 33
  56. BANG = 34
  57. CONCAT = 35
  58. class Parser(antlr.LLkParser):
  59. ### user action >>>
  60. ### user action <<<
  61. def __init__(self, *args, **kwargs):
  62. antlr.LLkParser.__init__(self, *args, **kwargs)
  63. self.tokenNames = _tokenNames
  64. ### __init__ header action >>>
  65. self.rpn = b""
  66. self.sheet_references = []
  67. self.xcall_references = []
  68. ### __init__ header action <<<
  69. def formula(self):
  70. pass
  71. self.expr("V")
  72. def expr(self,
  73. arg_type
  74. ):
  75. pass
  76. self.prec0_expr(arg_type)
  77. while True:
  78. if ((self.LA(1) >= EQ and self.LA(1) <= LE)):
  79. pass
  80. la1 = self.LA(1)
  81. if False:
  82. pass
  83. elif la1 and la1 in [EQ]:
  84. pass
  85. self.match(EQ)
  86. op = struct.pack('B', ptgEQ)
  87. elif la1 and la1 in [NE]:
  88. pass
  89. self.match(NE)
  90. op = struct.pack('B', ptgNE)
  91. elif la1 and la1 in [GT]:
  92. pass
  93. self.match(GT)
  94. op = struct.pack('B', ptgGT)
  95. elif la1 and la1 in [LT]:
  96. pass
  97. self.match(LT)
  98. op = struct.pack('B', ptgLT)
  99. elif la1 and la1 in [GE]:
  100. pass
  101. self.match(GE)
  102. op = struct.pack('B', ptgGE)
  103. elif la1 and la1 in [LE]:
  104. pass
  105. self.match(LE)
  106. op = struct.pack('B', ptgLE)
  107. else:
  108. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  109. self.prec0_expr(arg_type)
  110. self.rpn += op
  111. else:
  112. break
  113. def prec0_expr(self,
  114. arg_type
  115. ):
  116. pass
  117. self.prec1_expr(arg_type)
  118. while True:
  119. if (self.LA(1)==CONCAT):
  120. pass
  121. pass
  122. self.match(CONCAT)
  123. op = struct.pack('B', ptgConcat)
  124. self.prec1_expr(arg_type)
  125. self.rpn += op
  126. else:
  127. break
  128. def prec1_expr(self,
  129. arg_type
  130. ):
  131. pass
  132. self.prec2_expr(arg_type)
  133. while True:
  134. if (self.LA(1)==ADD or self.LA(1)==SUB):
  135. pass
  136. la1 = self.LA(1)
  137. if False:
  138. pass
  139. elif la1 and la1 in [ADD]:
  140. pass
  141. self.match(ADD)
  142. op = struct.pack('B', ptgAdd)
  143. elif la1 and la1 in [SUB]:
  144. pass
  145. self.match(SUB)
  146. op = struct.pack('B', ptgSub)
  147. else:
  148. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  149. self.prec2_expr(arg_type)
  150. self.rpn += op;
  151. # print "**prec1_expr4 %s" % arg_type
  152. else:
  153. break
  154. def prec2_expr(self,
  155. arg_type
  156. ):
  157. pass
  158. self.prec3_expr(arg_type)
  159. while True:
  160. if (self.LA(1)==MUL or self.LA(1)==DIV):
  161. pass
  162. la1 = self.LA(1)
  163. if False:
  164. pass
  165. elif la1 and la1 in [MUL]:
  166. pass
  167. self.match(MUL)
  168. op = struct.pack('B', ptgMul)
  169. elif la1 and la1 in [DIV]:
  170. pass
  171. self.match(DIV)
  172. op = struct.pack('B', ptgDiv)
  173. else:
  174. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  175. self.prec3_expr(arg_type)
  176. self.rpn += op
  177. else:
  178. break
  179. def prec3_expr(self,
  180. arg_type
  181. ):
  182. pass
  183. self.prec4_expr(arg_type)
  184. while True:
  185. if (self.LA(1)==POWER):
  186. pass
  187. pass
  188. self.match(POWER)
  189. op = struct.pack('B', ptgPower)
  190. self.prec4_expr(arg_type)
  191. self.rpn += op
  192. else:
  193. break
  194. def prec4_expr(self,
  195. arg_type
  196. ):
  197. pass
  198. self.prec5_expr(arg_type)
  199. la1 = self.LA(1)
  200. if False:
  201. pass
  202. elif la1 and la1 in [PERCENT]:
  203. pass
  204. self.match(PERCENT)
  205. self.rpn += struct.pack('B', ptgPercent)
  206. elif la1 and la1 in [EOF,EQ,NE,GT,LT,GE,LE,ADD,SUB,MUL,DIV,POWER,RP,COMMA,SEMICOLON,CONCAT]:
  207. pass
  208. else:
  209. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  210. def prec5_expr(self,
  211. arg_type
  212. ):
  213. la1 = self.LA(1)
  214. if False:
  215. pass
  216. elif la1 and la1 in [TRUE_CONST,FALSE_CONST,STR_CONST,NUM_CONST,INT_CONST,FUNC_IF,FUNC_CHOOSE,NAME,QUOTENAME,LP,REF2D]:
  217. pass
  218. self.primary(arg_type)
  219. elif la1 and la1 in [SUB]:
  220. pass
  221. self.match(SUB)
  222. self.primary(arg_type)
  223. self.rpn += struct.pack('B', ptgUminus)
  224. else:
  225. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  226. def primary(self,
  227. arg_type
  228. ):
  229. str_tok = None
  230. int_tok = None
  231. num_tok = None
  232. ref2d_tok = None
  233. ref2d1_tok = None
  234. ref2d2_tok = None
  235. ref3d_ref2d = None
  236. ref3d_ref2d2 = None
  237. name_tok = None
  238. func_tok = None
  239. la1 = self.LA(1)
  240. if False:
  241. pass
  242. elif la1 and la1 in [TRUE_CONST]:
  243. pass
  244. self.match(TRUE_CONST)
  245. self.rpn += struct.pack("2B", ptgBool, 1)
  246. elif la1 and la1 in [FALSE_CONST]:
  247. pass
  248. self.match(FALSE_CONST)
  249. self.rpn += struct.pack("2B", ptgBool, 0)
  250. elif la1 and la1 in [STR_CONST]:
  251. pass
  252. str_tok = self.LT(1)
  253. self.match(STR_CONST)
  254. self.rpn += struct.pack("B", ptgStr) + upack1(str_tok.text[1:-1].replace("\"\"", "\""))
  255. elif la1 and la1 in [NUM_CONST]:
  256. pass
  257. num_tok = self.LT(1)
  258. self.match(NUM_CONST)
  259. self.rpn += struct.pack("<Bd", ptgNum, float(num_tok.text))
  260. elif la1 and la1 in [FUNC_IF]:
  261. pass
  262. self.match(FUNC_IF)
  263. self.match(LP)
  264. self.expr("V")
  265. la1 = self.LA(1)
  266. if False:
  267. pass
  268. elif la1 and la1 in [SEMICOLON]:
  269. pass
  270. self.match(SEMICOLON)
  271. elif la1 and la1 in [COMMA]:
  272. pass
  273. self.match(COMMA)
  274. else:
  275. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  276. self.rpn += struct.pack("<BBH", ptgAttr, 0x02, 0) # tAttrIf
  277. pos0 = len(self.rpn) - 2
  278. self.expr(arg_type)
  279. la1 = self.LA(1)
  280. if False:
  281. pass
  282. elif la1 and la1 in [SEMICOLON]:
  283. pass
  284. self.match(SEMICOLON)
  285. elif la1 and la1 in [COMMA]:
  286. pass
  287. self.match(COMMA)
  288. else:
  289. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  290. self.rpn += struct.pack("<BBH", ptgAttr, 0x08, 0) # tAttrSkip
  291. pos1 = len(self.rpn) - 2
  292. self.rpn = self.rpn[:pos0] + struct.pack("<H", pos1-pos0) + self.rpn[pos0+2:]
  293. self.expr(arg_type)
  294. self.match(RP)
  295. self.rpn += struct.pack("<BBH", ptgAttr, 0x08, 3) # tAttrSkip
  296. self.rpn += struct.pack("<BBH", ptgFuncVarR, 3, 1) # 3 = nargs, 1 = IF func
  297. pos2 = len(self.rpn)
  298. self.rpn = self.rpn[:pos1] + struct.pack("<H", pos2-(pos1+2)-1) + self.rpn[pos1+2:]
  299. elif la1 and la1 in [FUNC_CHOOSE]:
  300. pass
  301. self.match(FUNC_CHOOSE)
  302. arg_type = "R"
  303. rpn_chunks = []
  304. self.match(LP)
  305. self.expr("V")
  306. rpn_start = len(self.rpn)
  307. ref_markers = [len(self.sheet_references)]
  308. while True:
  309. if (self.LA(1)==COMMA or self.LA(1)==SEMICOLON):
  310. pass
  311. la1 = self.LA(1)
  312. if False:
  313. pass
  314. elif la1 and la1 in [SEMICOLON]:
  315. pass
  316. self.match(SEMICOLON)
  317. elif la1 and la1 in [COMMA]:
  318. pass
  319. self.match(COMMA)
  320. else:
  321. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  322. mark = len(self.rpn)
  323. la1 = self.LA(1)
  324. if False:
  325. pass
  326. elif la1 and la1 in [TRUE_CONST,FALSE_CONST,STR_CONST,NUM_CONST,INT_CONST,FUNC_IF,FUNC_CHOOSE,NAME,QUOTENAME,SUB,LP,REF2D]:
  327. pass
  328. self.expr(arg_type)
  329. elif la1 and la1 in [RP,COMMA,SEMICOLON]:
  330. pass
  331. self.rpn += struct.pack("B", ptgMissArg)
  332. else:
  333. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  334. rpn_chunks.append(self.rpn[mark:])
  335. ref_markers.append(len(self.sheet_references))
  336. else:
  337. break
  338. self.match(RP)
  339. self.rpn = self.rpn[:rpn_start]
  340. nc = len(rpn_chunks)
  341. chunklens = [len(chunk) for chunk in rpn_chunks]
  342. skiplens = [0] * nc
  343. skiplens[-1] = 3
  344. for ic in xrange(nc-1, 0, -1):
  345. skiplens[ic-1] = skiplens[ic] + chunklens[ic] + 4
  346. jump_pos = [2 * nc + 2]
  347. for ic in xrange(nc):
  348. jump_pos.append(jump_pos[-1] + chunklens[ic] + 4)
  349. chunk_shift = 2 * nc + 6 # size of tAttrChoose
  350. for ic in xrange(nc):
  351. for refx in xrange(ref_markers[ic], ref_markers[ic+1]):
  352. ref = self.sheet_references[refx]
  353. self.sheet_references[refx] = (ref[0], ref[1], ref[2] + chunk_shift)
  354. chunk_shift += 4 # size of tAttrSkip
  355. choose_rpn = []
  356. choose_rpn.append(struct.pack("<BBH", ptgAttr, 0x04, nc)) # 0x04 is tAttrChoose
  357. choose_rpn.append(struct.pack("<%dH" % (nc+1), *jump_pos))
  358. for ic in xrange(nc):
  359. choose_rpn.append(rpn_chunks[ic])
  360. choose_rpn.append(struct.pack("<BBH", ptgAttr, 0x08, skiplens[ic])) # 0x08 is tAttrSkip
  361. choose_rpn.append(struct.pack("<BBH", ptgFuncVarV, nc+1, 100)) # 100 is CHOOSE fn
  362. self.rpn += "".join(choose_rpn)
  363. elif la1 and la1 in [LP]:
  364. pass
  365. self.match(LP)
  366. self.expr(arg_type)
  367. self.match(RP)
  368. self.rpn += struct.pack("B", ptgParen)
  369. else:
  370. if (self.LA(1)==INT_CONST) and (_tokenSet_0.member(self.LA(2))):
  371. pass
  372. int_tok = self.LT(1)
  373. self.match(INT_CONST)
  374. # print "**int_const", int_tok.text
  375. int_value = int(int_tok.text)
  376. if int_value <= 65535:
  377. self.rpn += struct.pack("<BH", ptgInt, int_value)
  378. else:
  379. self.rpn += struct.pack("<Bd", ptgNum, float(int_value))
  380. elif (self.LA(1)==REF2D) and (_tokenSet_0.member(self.LA(2))):
  381. pass
  382. ref2d_tok = self.LT(1)
  383. self.match(REF2D)
  384. # print "**ref2d %s %s" % (ref2d_tok.text, arg_type)
  385. r, c = Utils.cell_to_packed_rowcol(ref2d_tok.text)
  386. ptg = ptgRefR + _RVAdeltaRef[arg_type]
  387. self.rpn += struct.pack("<B2H", ptg, r, c)
  388. elif (self.LA(1)==REF2D) and (self.LA(2)==COLON):
  389. pass
  390. ref2d1_tok = self.LT(1)
  391. self.match(REF2D)
  392. self.match(COLON)
  393. ref2d2_tok = self.LT(1)
  394. self.match(REF2D)
  395. r1, c1 = Utils.cell_to_packed_rowcol(ref2d1_tok.text)
  396. r2, c2 = Utils.cell_to_packed_rowcol(ref2d2_tok.text)
  397. ptg = ptgAreaR + _RVAdeltaArea[arg_type]
  398. self.rpn += struct.pack("<B4H", ptg, r1, r2, c1, c2)
  399. elif (self.LA(1)==INT_CONST or self.LA(1)==NAME or self.LA(1)==QUOTENAME) and (self.LA(2)==COLON or self.LA(2)==BANG):
  400. pass
  401. sheet1=self.sheet()
  402. sheet2 = sheet1
  403. la1 = self.LA(1)
  404. if False:
  405. pass
  406. elif la1 and la1 in [COLON]:
  407. pass
  408. self.match(COLON)
  409. sheet2=self.sheet()
  410. elif la1 and la1 in [BANG]:
  411. pass
  412. else:
  413. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  414. self.match(BANG)
  415. ref3d_ref2d = self.LT(1)
  416. self.match(REF2D)
  417. ptg = ptgRef3dR + _RVAdeltaRef[arg_type]
  418. rpn_ref2d = ""
  419. r1, c1 = Utils.cell_to_packed_rowcol(ref3d_ref2d.text)
  420. rpn_ref2d = struct.pack("<3H", 0x0000, r1, c1)
  421. la1 = self.LA(1)
  422. if False:
  423. pass
  424. elif la1 and la1 in [COLON]:
  425. pass
  426. self.match(COLON)
  427. ref3d_ref2d2 = self.LT(1)
  428. self.match(REF2D)
  429. ptg = ptgArea3dR + _RVAdeltaArea[arg_type]
  430. r2, c2 = Utils.cell_to_packed_rowcol(ref3d_ref2d2.text)
  431. rpn_ref2d = struct.pack("<5H", 0x0000, r1, r2, c1, c2)
  432. elif la1 and la1 in [EOF,EQ,NE,GT,LT,GE,LE,ADD,SUB,MUL,DIV,POWER,PERCENT,RP,COMMA,SEMICOLON,CONCAT]:
  433. pass
  434. else:
  435. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  436. self.rpn += struct.pack("<B", ptg)
  437. self.sheet_references.append((sheet1, sheet2, len(self.rpn)))
  438. self.rpn += rpn_ref2d
  439. elif (self.LA(1)==NAME) and (_tokenSet_0.member(self.LA(2))):
  440. pass
  441. name_tok = self.LT(1)
  442. self.match(NAME)
  443. raise Exception("[formula] found unexpected NAME token (%r)" % name_tok.txt)
  444. # #### TODO: handle references to defined names here
  445. elif (self.LA(1)==NAME) and (self.LA(2)==LP):
  446. pass
  447. func_tok = self.LT(1)
  448. self.match(NAME)
  449. func_toku = func_tok.text.upper()
  450. if func_toku in all_funcs_by_name:
  451. (opcode,
  452. min_argc,
  453. max_argc,
  454. func_type,
  455. arg_type_str) = all_funcs_by_name[func_toku]
  456. arg_type_list = list(arg_type_str)
  457. else:
  458. raise Exception("[formula] unknown function (%s)" % func_tok.text)
  459. # print "**func_tok1 %s %s" % (func_toku, func_type)
  460. xcall = opcode < 0
  461. if xcall:
  462. # The name of the add-in function is passed as the 1st arg
  463. # of the hidden XCALL function
  464. self.xcall_references.append((func_toku, len(self.rpn) + 1))
  465. self.rpn += struct.pack("<BHHH",
  466. ptgNameXR,
  467. 0xadde, # ##PATCHME## index to REF entry in EXTERNSHEET record
  468. 0xefbe, # ##PATCHME## one-based index to EXTERNNAME record
  469. 0x0000) # unused
  470. self.match(LP)
  471. arg_count=self.expr_list(arg_type_list, min_argc, max_argc)
  472. self.match(RP)
  473. if arg_count > max_argc or arg_count < min_argc:
  474. raise Exception("%d parameters for function: %s" % (arg_count, func_tok.text))
  475. if xcall:
  476. func_ptg = ptgFuncVarR + _RVAdelta[func_type]
  477. self.rpn += struct.pack("<2BH", func_ptg, arg_count + 1, 255) # 255 is magic XCALL function
  478. elif min_argc == max_argc:
  479. func_ptg = ptgFuncR + _RVAdelta[func_type]
  480. self.rpn += struct.pack("<BH", func_ptg, opcode)
  481. elif arg_count == 1 and func_tok.text.upper() == "SUM":
  482. self.rpn += struct.pack("<BBH", ptgAttr, 0x10, 0) # tAttrSum
  483. else:
  484. func_ptg = ptgFuncVarR + _RVAdelta[func_type]
  485. self.rpn += struct.pack("<2BH", func_ptg, arg_count, opcode)
  486. else:
  487. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  488. def sheet(self):
  489. ref = None
  490. sheet_ref_name = None
  491. sheet_ref_int = None
  492. sheet_ref_quote = None
  493. la1 = self.LA(1)
  494. if False:
  495. pass
  496. elif la1 and la1 in [NAME]:
  497. pass
  498. sheet_ref_name = self.LT(1)
  499. self.match(NAME)
  500. ref = sheet_ref_name.text
  501. elif la1 and la1 in [INT_CONST]:
  502. pass
  503. sheet_ref_int = self.LT(1)
  504. self.match(INT_CONST)
  505. ref = sheet_ref_int.text
  506. elif la1 and la1 in [QUOTENAME]:
  507. pass
  508. sheet_ref_quote = self.LT(1)
  509. self.match(QUOTENAME)
  510. ref = sheet_ref_quote.text[1:-1].replace("''", "'")
  511. else:
  512. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  513. return ref
  514. def expr_list(self,
  515. arg_type_list, min_argc, max_argc
  516. ):
  517. arg_cnt = None
  518. arg_cnt = 0
  519. arg_type = arg_type_list[arg_cnt]
  520. # print "**expr_list1[%d] req=%s" % (arg_cnt, arg_type)
  521. la1 = self.LA(1)
  522. if False:
  523. pass
  524. elif la1 and la1 in [TRUE_CONST,FALSE_CONST,STR_CONST,NUM_CONST,INT_CONST,FUNC_IF,FUNC_CHOOSE,NAME,QUOTENAME,SUB,LP,REF2D]:
  525. pass
  526. self.expr(arg_type)
  527. arg_cnt += 1
  528. while True:
  529. if (self.LA(1)==COMMA or self.LA(1)==SEMICOLON):
  530. pass
  531. if arg_cnt < len(arg_type_list):
  532. arg_type = arg_type_list[arg_cnt]
  533. else:
  534. arg_type = arg_type_list[-1]
  535. if arg_type == "+":
  536. arg_type = arg_type_list[-2]
  537. # print "**expr_list2[%d] req=%s" % (arg_cnt, arg_type)
  538. la1 = self.LA(1)
  539. if False:
  540. pass
  541. elif la1 and la1 in [SEMICOLON]:
  542. pass
  543. self.match(SEMICOLON)
  544. elif la1 and la1 in [COMMA]:
  545. pass
  546. self.match(COMMA)
  547. else:
  548. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  549. la1 = self.LA(1)
  550. if False:
  551. pass
  552. elif la1 and la1 in [TRUE_CONST,FALSE_CONST,STR_CONST,NUM_CONST,INT_CONST,FUNC_IF,FUNC_CHOOSE,NAME,QUOTENAME,SUB,LP,REF2D]:
  553. pass
  554. self.expr(arg_type)
  555. elif la1 and la1 in [RP,COMMA,SEMICOLON]:
  556. pass
  557. self.rpn += struct.pack("B", ptgMissArg)
  558. else:
  559. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  560. arg_cnt += 1
  561. else:
  562. break
  563. elif la1 and la1 in [RP]:
  564. pass
  565. else:
  566. raise antlr.NoViableAltException(self.LT(1), self.getFilename())
  567. return arg_cnt
  568. _tokenNames = [
  569. "<0>",
  570. "EOF",
  571. "<2>",
  572. "NULL_TREE_LOOKAHEAD",
  573. "TRUE_CONST",
  574. "FALSE_CONST",
  575. "STR_CONST",
  576. "NUM_CONST",
  577. "INT_CONST",
  578. "FUNC_IF",
  579. "FUNC_CHOOSE",
  580. "NAME",
  581. "QUOTENAME",
  582. "EQ",
  583. "NE",
  584. "GT",
  585. "LT",
  586. "GE",
  587. "LE",
  588. "ADD",
  589. "SUB",
  590. "MUL",
  591. "DIV",
  592. "POWER",
  593. "PERCENT",
  594. "LP",
  595. "RP",
  596. "LB",
  597. "RB",
  598. "COLON",
  599. "COMMA",
  600. "SEMICOLON",
  601. "REF2D",
  602. "REF2D_R1C1",
  603. "BANG",
  604. "CONCAT"
  605. ]
  606. ### generate bit set
  607. def mk_tokenSet_0():
  608. ### var1
  609. data = [ 37681618946, 0]
  610. return data
  611. _tokenSet_0 = antlr.BitSet(mk_tokenSet_0())