Parser.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
  3. * All rights reserved.
  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. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "Parser.h"
  27. #include <AK/HashMap.h>
  28. #include <AK/StdLibExtras.h>
  29. #include <stdio.h>
  30. namespace JS {
  31. static HashMap<TokenType, int> g_operator_precedence;
  32. Parser::Parser(Lexer lexer)
  33. : m_lexer(move(lexer))
  34. , m_current_token(m_lexer.next())
  35. {
  36. if (g_operator_precedence.is_empty()) {
  37. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
  38. g_operator_precedence.set(TokenType::Period, 20);
  39. g_operator_precedence.set(TokenType::BracketOpen, 20);
  40. g_operator_precedence.set(TokenType::ParenOpen, 20);
  41. g_operator_precedence.set(TokenType::QuestionMarkPeriod, 20);
  42. g_operator_precedence.set(TokenType::New, 19);
  43. g_operator_precedence.set(TokenType::PlusPlus, 18);
  44. g_operator_precedence.set(TokenType::MinusMinus, 18);
  45. g_operator_precedence.set(TokenType::ExclamationMark, 17);
  46. g_operator_precedence.set(TokenType::Tilde, 17);
  47. g_operator_precedence.set(TokenType::Typeof, 17);
  48. g_operator_precedence.set(TokenType::Void, 17);
  49. g_operator_precedence.set(TokenType::Delete, 17);
  50. g_operator_precedence.set(TokenType::Await, 17);
  51. g_operator_precedence.set(TokenType::DoubleAsterisk, 16);
  52. g_operator_precedence.set(TokenType::Asterisk, 15);
  53. g_operator_precedence.set(TokenType::Slash, 15);
  54. g_operator_precedence.set(TokenType::Percent, 15);
  55. g_operator_precedence.set(TokenType::Plus, 14);
  56. g_operator_precedence.set(TokenType::Minus, 14);
  57. g_operator_precedence.set(TokenType::ShiftLeft, 13);
  58. g_operator_precedence.set(TokenType::ShiftRight, 13);
  59. g_operator_precedence.set(TokenType::UnsignedShiftRight, 13);
  60. g_operator_precedence.set(TokenType::LessThan, 12);
  61. g_operator_precedence.set(TokenType::LessThanEquals, 12);
  62. g_operator_precedence.set(TokenType::GreaterThan, 12);
  63. g_operator_precedence.set(TokenType::GreaterThanEquals, 12);
  64. g_operator_precedence.set(TokenType::In, 12);
  65. g_operator_precedence.set(TokenType::Instanceof, 12);
  66. g_operator_precedence.set(TokenType::EqualsEquals, 11);
  67. g_operator_precedence.set(TokenType::ExclamationMarkEquals, 11);
  68. g_operator_precedence.set(TokenType::EqualsEqualsEquals, 11);
  69. g_operator_precedence.set(TokenType::ExclamationMarkEqualsEquals, 11);
  70. g_operator_precedence.set(TokenType::Ampersand, 10);
  71. g_operator_precedence.set(TokenType::Caret, 9);
  72. g_operator_precedence.set(TokenType::Pipe, 8);
  73. g_operator_precedence.set(TokenType::DoubleQuestionMark, 7);
  74. g_operator_precedence.set(TokenType::DoubleAmpersand, 6);
  75. g_operator_precedence.set(TokenType::DoublePipe, 5);
  76. g_operator_precedence.set(TokenType::QuestionMark, 4);
  77. g_operator_precedence.set(TokenType::Equals, 3);
  78. g_operator_precedence.set(TokenType::PlusEquals, 3);
  79. g_operator_precedence.set(TokenType::MinusEquals, 3);
  80. g_operator_precedence.set(TokenType::AsteriskAsteriskEquals, 3);
  81. g_operator_precedence.set(TokenType::AsteriskEquals, 3);
  82. g_operator_precedence.set(TokenType::SlashEquals, 3);
  83. g_operator_precedence.set(TokenType::PercentEquals, 3);
  84. g_operator_precedence.set(TokenType::ShiftLeftEquals, 3);
  85. g_operator_precedence.set(TokenType::ShiftRightEquals, 3);
  86. g_operator_precedence.set(TokenType::UnsignedShiftRightEquals, 3);
  87. g_operator_precedence.set(TokenType::PipeEquals, 3);
  88. g_operator_precedence.set(TokenType::Yield, 2);
  89. g_operator_precedence.set(TokenType::Comma, 1);
  90. }
  91. }
  92. int Parser::operator_precedence(TokenType type) const
  93. {
  94. auto it = g_operator_precedence.find(type);
  95. if (it == g_operator_precedence.end()) {
  96. fprintf(stderr, "No precedence for operator %s\n", Token::name(type));
  97. ASSERT_NOT_REACHED();
  98. return -1;
  99. }
  100. return it->value;
  101. }
  102. Associativity Parser::operator_associativity(TokenType type) const
  103. {
  104. switch (type) {
  105. case TokenType::Period:
  106. case TokenType::BracketOpen:
  107. case TokenType::ParenOpen:
  108. case TokenType::QuestionMarkPeriod:
  109. case TokenType::Asterisk:
  110. case TokenType::Slash:
  111. case TokenType::Percent:
  112. case TokenType::Plus:
  113. case TokenType::Minus:
  114. case TokenType::ShiftLeft:
  115. case TokenType::ShiftRight:
  116. case TokenType::UnsignedShiftRight:
  117. case TokenType::LessThan:
  118. case TokenType::LessThanEquals:
  119. case TokenType::GreaterThan:
  120. case TokenType::GreaterThanEquals:
  121. case TokenType::In:
  122. case TokenType::Instanceof:
  123. case TokenType::EqualsEquals:
  124. case TokenType::ExclamationMarkEquals:
  125. case TokenType::EqualsEqualsEquals:
  126. case TokenType::ExclamationMarkEqualsEquals:
  127. case TokenType::Ampersand:
  128. case TokenType::Caret:
  129. case TokenType::Pipe:
  130. case TokenType::DoubleQuestionMark:
  131. case TokenType::DoubleAmpersand:
  132. case TokenType::DoublePipe:
  133. case TokenType::Comma:
  134. return Associativity::Left;
  135. default:
  136. return Associativity::Right;
  137. }
  138. }
  139. NonnullOwnPtr<Program> Parser::parse_program()
  140. {
  141. auto program = make<Program>();
  142. while (!done()) {
  143. if (match(TokenType::Semicolon)) {
  144. consume();
  145. } else if (match_statement()) {
  146. program->append(parse_statement());
  147. } else {
  148. expected("statement");
  149. consume();
  150. }
  151. }
  152. return program;
  153. }
  154. NonnullOwnPtr<Statement> Parser::parse_statement()
  155. {
  156. if (match_expression()) {
  157. return make<JS::ExpressionStatement>(parse_expression(0));
  158. }
  159. switch (m_current_token.type()) {
  160. case TokenType::Function:
  161. return parse_function_declaration();
  162. case TokenType::CurlyOpen:
  163. return parse_block_statement();
  164. case TokenType::Return:
  165. return parse_return_statement();
  166. case TokenType::Var:
  167. case TokenType::Let:
  168. case TokenType::Const:
  169. return parse_variable_declaration();
  170. case TokenType::For:
  171. return parse_for_statement();
  172. default:
  173. m_has_errors = true;
  174. expected("statement (missing switch case)");
  175. consume();
  176. return make<ErrorStatement>();
  177. }
  178. }
  179. NonnullOwnPtr<Expression> Parser::parse_primary_expression()
  180. {
  181. switch (m_current_token.type()) {
  182. case TokenType::ParenOpen: {
  183. consume(TokenType::ParenOpen);
  184. auto expression = parse_expression(0);
  185. consume(TokenType::ParenClose);
  186. return expression;
  187. }
  188. case TokenType::Identifier:
  189. return make<Identifier>(consume().value());
  190. case TokenType::NumericLiteral:
  191. return make<NumericLiteral>(consume().double_value());
  192. case TokenType::BoolLiteral:
  193. return make<BooleanLiteral>(consume().bool_value());
  194. case TokenType::StringLiteral:
  195. return make<StringLiteral>(consume().string_value());
  196. case TokenType::NullLiteral:
  197. consume();
  198. return make<NullLiteral>();
  199. case TokenType::UndefinedLiteral:
  200. consume();
  201. return make<UndefinedLiteral>();
  202. case TokenType::CurlyOpen:
  203. return parse_object_expression();
  204. default:
  205. m_has_errors = true;
  206. expected("primary expression (missing switch case)");
  207. consume();
  208. return make<ErrorExpression>();
  209. }
  210. }
  211. NonnullOwnPtr<Expression> Parser::parse_unary_prefixed_expression()
  212. {
  213. switch (m_current_token.type()) {
  214. case TokenType::PlusPlus:
  215. consume();
  216. return make<UpdateExpression>(UpdateOp::Increment, parse_primary_expression(), true);
  217. case TokenType::MinusMinus:
  218. consume();
  219. return make<UpdateExpression>(UpdateOp::Decrement, parse_primary_expression(), true);
  220. case TokenType::ExclamationMark:
  221. consume();
  222. return make<UnaryExpression>(UnaryOp::Not, parse_primary_expression());
  223. case TokenType::Tilde:
  224. consume();
  225. return make<UnaryExpression>(UnaryOp::BitwiseNot, parse_primary_expression());
  226. default:
  227. m_has_errors = true;
  228. expected("primary expression (missing switch case)");
  229. consume();
  230. return make<ErrorExpression>();
  231. }
  232. }
  233. NonnullOwnPtr<ObjectExpression> Parser::parse_object_expression()
  234. {
  235. // FIXME: Parse actual object expression
  236. consume(TokenType::CurlyOpen);
  237. consume(TokenType::CurlyClose);
  238. return make<ObjectExpression>();
  239. }
  240. NonnullOwnPtr<Expression> Parser::parse_expression(int min_precedence, Associativity associativity)
  241. {
  242. if (match_unary_prefixed_expression())
  243. return parse_unary_prefixed_expression();
  244. auto expression = parse_primary_expression();
  245. while (match_secondary_expression()) {
  246. int new_precedence = operator_precedence(m_current_token.type());
  247. if (new_precedence < min_precedence)
  248. break;
  249. if (new_precedence == min_precedence && associativity == Associativity::Left)
  250. break;
  251. Associativity new_associativity = operator_associativity(m_current_token.type());
  252. expression = parse_secondary_expression(move(expression), new_precedence, new_associativity);
  253. }
  254. return expression;
  255. }
  256. NonnullOwnPtr<Expression> Parser::parse_secondary_expression(NonnullOwnPtr<Expression> lhs, int min_precedence, Associativity associativity)
  257. {
  258. switch (m_current_token.type()) {
  259. case TokenType::Plus:
  260. consume();
  261. return make<BinaryExpression>(BinaryOp::Plus, move(lhs), parse_expression(min_precedence, associativity));
  262. case TokenType::PlusEquals:
  263. consume();
  264. return make<AssignmentExpression>(AssignmentOp::AdditionAssignment, move(lhs), parse_expression(min_precedence, associativity));
  265. case TokenType::Minus:
  266. consume();
  267. return make<BinaryExpression>(BinaryOp::Minus, move(lhs), parse_expression(min_precedence, associativity));
  268. case TokenType::MinusEquals:
  269. consume();
  270. return make<AssignmentExpression>(AssignmentOp::SubtractionAssignment, move(lhs), parse_expression(min_precedence, associativity));
  271. case TokenType::Asterisk:
  272. consume();
  273. return make<BinaryExpression>(BinaryOp::Asterisk, move(lhs), parse_expression(min_precedence, associativity));
  274. case TokenType::AsteriskEquals:
  275. consume();
  276. return make<AssignmentExpression>(AssignmentOp::MultiplicationAssignment, move(lhs), parse_expression(min_precedence, associativity));
  277. case TokenType::Slash:
  278. consume();
  279. return make<BinaryExpression>(BinaryOp::Slash, move(lhs), parse_expression(min_precedence, associativity));
  280. case TokenType::SlashEquals:
  281. consume();
  282. return make<AssignmentExpression>(AssignmentOp::DivisionAssignment, move(lhs), parse_expression(min_precedence, associativity));
  283. case TokenType::GreaterThan:
  284. consume();
  285. return make<BinaryExpression>(BinaryOp::GreaterThan, move(lhs), parse_expression(min_precedence, associativity));
  286. case TokenType::GreaterThanEquals:
  287. consume();
  288. return make<BinaryExpression>(BinaryOp::GreaterThanEquals, move(lhs), parse_expression(min_precedence, associativity));
  289. case TokenType::LessThan:
  290. consume();
  291. return make<BinaryExpression>(BinaryOp::LessThan, move(lhs), parse_expression(min_precedence, associativity));
  292. case TokenType::LessThanEquals:
  293. consume();
  294. return make<BinaryExpression>(BinaryOp::LessThanEquals, move(lhs), parse_expression(min_precedence, associativity));
  295. case TokenType::EqualsEqualsEquals:
  296. consume();
  297. return make<BinaryExpression>(BinaryOp::TypedEquals, move(lhs), parse_expression(min_precedence, associativity));
  298. case TokenType::ExclamationMarkEqualsEquals:
  299. consume();
  300. return make<BinaryExpression>(BinaryOp::TypedInequals, move(lhs), parse_expression(min_precedence, associativity));
  301. case TokenType::ParenOpen:
  302. return parse_call_expression(move(lhs));
  303. case TokenType::Equals:
  304. consume();
  305. return make<AssignmentExpression>(AssignmentOp::Assignment, move(lhs), parse_expression(min_precedence, associativity));
  306. case TokenType::Period:
  307. consume();
  308. return make<MemberExpression>(move(lhs), parse_expression(min_precedence, associativity));
  309. case TokenType::PlusPlus:
  310. consume();
  311. return make<UpdateExpression>(UpdateOp::Increment, move(lhs));
  312. case TokenType::MinusMinus:
  313. consume();
  314. return make<UpdateExpression>(UpdateOp::Decrement, move(lhs));
  315. default:
  316. m_has_errors = true;
  317. expected("secondary expression (missing switch case)");
  318. consume();
  319. return make<ErrorExpression>();
  320. }
  321. }
  322. NonnullOwnPtr<CallExpression> Parser::parse_call_expression(NonnullOwnPtr<Expression> lhs)
  323. {
  324. consume(TokenType::ParenOpen);
  325. NonnullOwnPtrVector<Expression> arguments;
  326. while (match_expression()) {
  327. arguments.append(parse_expression(0));
  328. if (!match(TokenType::Comma))
  329. break;
  330. consume();
  331. }
  332. consume(TokenType::ParenClose);
  333. return make<CallExpression>(move(lhs), move(arguments));
  334. }
  335. NonnullOwnPtr<ReturnStatement> Parser::parse_return_statement()
  336. {
  337. consume(TokenType::Return);
  338. if (match_expression()) {
  339. return make<ReturnStatement>(parse_expression(0));
  340. }
  341. return make<ReturnStatement>(nullptr);
  342. }
  343. NonnullOwnPtr<BlockStatement> Parser::parse_block_statement()
  344. {
  345. auto block = make<BlockStatement>();
  346. consume(TokenType::CurlyOpen);
  347. while (!done() && !match(TokenType::CurlyClose)) {
  348. if (match(TokenType::Semicolon)) {
  349. consume();
  350. } else if (match_statement()) {
  351. block->append(parse_statement());
  352. } else {
  353. expected("statement");
  354. consume();
  355. }
  356. }
  357. consume(TokenType::CurlyClose);
  358. return block;
  359. }
  360. NonnullOwnPtr<FunctionDeclaration> Parser::parse_function_declaration()
  361. {
  362. consume(TokenType::Function);
  363. auto name = consume(TokenType::Identifier).value();
  364. consume(TokenType::ParenOpen);
  365. Vector<String> parameters;
  366. while (match(TokenType::Identifier)) {
  367. auto parameter = consume(TokenType::Identifier).value();
  368. parameters.append(parameter);
  369. if (match(TokenType::ParenClose)) {
  370. break;
  371. }
  372. consume(TokenType::Comma);
  373. }
  374. consume(TokenType::ParenClose);
  375. auto body = parse_block_statement();
  376. return make<FunctionDeclaration>(name, move(body), move(parameters));
  377. }
  378. NonnullOwnPtr<VariableDeclaration> Parser::parse_variable_declaration()
  379. {
  380. DeclarationType declaration_type;
  381. switch (m_current_token.type()) {
  382. case TokenType::Var:
  383. declaration_type = DeclarationType::Var;
  384. consume(TokenType::Var);
  385. break;
  386. case TokenType::Let:
  387. declaration_type = DeclarationType::Let;
  388. consume(TokenType::Let);
  389. break;
  390. case TokenType::Const:
  391. declaration_type = DeclarationType::Const;
  392. consume(TokenType::Const);
  393. break;
  394. default:
  395. ASSERT_NOT_REACHED();
  396. }
  397. auto name = consume(TokenType::Identifier).value();
  398. OwnPtr<Expression> initializer;
  399. if (match(TokenType::Equals)) {
  400. consume();
  401. initializer = parse_expression(0);
  402. }
  403. return make<VariableDeclaration>(make<Identifier>(name), move(initializer), declaration_type);
  404. }
  405. NonnullOwnPtr<ForStatement> Parser::parse_for_statement()
  406. {
  407. consume(TokenType::For);
  408. consume(TokenType::ParenOpen);
  409. OwnPtr<Statement> init = nullptr;
  410. switch (m_current_token.type()) {
  411. case TokenType::Semicolon:
  412. break;
  413. default:
  414. init = parse_statement();
  415. break;
  416. }
  417. consume(TokenType::Semicolon);
  418. OwnPtr<Expression> test = nullptr;
  419. switch (m_current_token.type()) {
  420. case TokenType::Semicolon:
  421. break;
  422. default:
  423. test = parse_expression(0);
  424. break;
  425. }
  426. consume(TokenType::Semicolon);
  427. OwnPtr<Expression> update = nullptr;
  428. switch (m_current_token.type()) {
  429. case TokenType::Semicolon:
  430. break;
  431. default:
  432. update = parse_expression(0);
  433. break;
  434. }
  435. consume(TokenType::ParenClose);
  436. auto body = parse_block_statement();
  437. return make<ForStatement>(move(init), move(test), move(update), move(body));
  438. }
  439. bool Parser::match(TokenType type) const
  440. {
  441. return m_current_token.type() == type;
  442. }
  443. bool Parser::match_expression() const
  444. {
  445. auto type = m_current_token.type();
  446. return type == TokenType::BoolLiteral
  447. || type == TokenType::NumericLiteral
  448. || type == TokenType::StringLiteral
  449. || type == TokenType::UndefinedLiteral
  450. || type == TokenType::NullLiteral
  451. || type == TokenType::Identifier
  452. || type == TokenType::New
  453. || type == TokenType::CurlyOpen
  454. || type == TokenType::BracketOpen
  455. || type == TokenType::ParenOpen
  456. || match_unary_prefixed_expression();
  457. }
  458. bool Parser::match_unary_prefixed_expression() const
  459. {
  460. auto type = m_current_token.type();
  461. return type == TokenType::PlusPlus
  462. || type == TokenType::MinusMinus
  463. || type == TokenType::ExclamationMark
  464. || type == TokenType::Tilde;
  465. }
  466. bool Parser::match_secondary_expression() const
  467. {
  468. auto type = m_current_token.type();
  469. return type == TokenType::Plus
  470. || type == TokenType::PlusEquals
  471. || type == TokenType::Minus
  472. || type == TokenType::MinusEquals
  473. || type == TokenType::Asterisk
  474. || type == TokenType::AsteriskEquals
  475. || type == TokenType::Slash
  476. || type == TokenType::SlashEquals
  477. || type == TokenType::Equals
  478. || type == TokenType::EqualsEqualsEquals
  479. || type == TokenType::ExclamationMarkEqualsEquals
  480. || type == TokenType::GreaterThan
  481. || type == TokenType::GreaterThanEquals
  482. || type == TokenType::LessThan
  483. || type == TokenType::LessThanEquals
  484. || type == TokenType::ParenOpen
  485. || type == TokenType::Period
  486. || type == TokenType::PlusPlus
  487. || type == TokenType::MinusMinus;
  488. }
  489. bool Parser::match_statement() const
  490. {
  491. auto type = m_current_token.type();
  492. return match_expression()
  493. || type == TokenType::Function
  494. || type == TokenType::Return
  495. || type == TokenType::Let
  496. || type == TokenType::Catch
  497. || type == TokenType::Class
  498. || type == TokenType::Delete
  499. || type == TokenType::Do
  500. || type == TokenType::If
  501. || type == TokenType::Try
  502. || type == TokenType::While
  503. || type == TokenType::For
  504. || type == TokenType::Const
  505. || type == TokenType::CurlyOpen
  506. || type == TokenType::Var;
  507. }
  508. bool Parser::done() const
  509. {
  510. return match(TokenType::Eof);
  511. }
  512. Token Parser::consume()
  513. {
  514. auto old_token = m_current_token;
  515. m_current_token = m_lexer.next();
  516. return old_token;
  517. }
  518. Token Parser::consume(TokenType type)
  519. {
  520. if (m_current_token.type() != type) {
  521. m_has_errors = true;
  522. fprintf(stderr, "Error: Unexpected token %s. Expected %s\n", m_current_token.name(), Token::name(type));
  523. }
  524. return consume();
  525. }
  526. void Parser::expected(const char* what)
  527. {
  528. m_has_errors = true;
  529. fprintf(stderr, "Error: Unexpected token %s. Expected %s\n", m_current_token.name(), what);
  530. }
  531. }