parser.ypp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. // -----------------------------------------------------------------------------
  5. // Bison Configuration
  6. // -----------------------------------------------------------------------------
  7. %require "3.2"
  8. %language "c++"
  9. // We don't need a separate header for Bison locations.
  10. %define api.location.file none
  11. // Use a type-safe C++ variant for semantic values
  12. %define api.value.type variant
  13. // Have Bison generate the functions ‘make_TEXT’ and ‘make_NUMBER’, but also
  14. // ‘make_YYEOF’, for the end of input.
  15. %define api.token.constructor
  16. // Generate the parser as `::Carbon::Parser`.
  17. %define api.namespace { Carbon }
  18. %define api.parser.class { Parser }
  19. // Make parse error messages more detailed
  20. %define parse.error verbose
  21. // Enable support for parser debugging
  22. %define parse.trace true
  23. //
  24. // Parameters to the parser and lexer
  25. //
  26. // Parameters to the parser are stored therein as protected data members, and
  27. // thus available to its methods.
  28. // "out" parameter passed to the parser, where the AST is written.
  29. %parse-param {std::optional<AST>& parsed_program}
  30. // "inout" parameter passed to both the parser and the lexer.
  31. %param {ParseAndLexContext& context}
  32. // No shift-reduce conflicts are expected.
  33. %expect 0
  34. // -----------------------------------------------------------------------------
  35. %code top {
  36. #include <algorithm>
  37. #include <cstdarg>
  38. #include <cstdio>
  39. #include <cstdlib>
  40. #include <list>
  41. #include <vector>
  42. #include "common/check.h"
  43. #include "executable_semantics/syntax/syntax_helpers.h"
  44. #include "executable_semantics/syntax/parse_and_lex_context.h"
  45. #include "llvm/ADT/StringExtras.h"
  46. } // %code top
  47. %code requires {
  48. #include <optional>
  49. #include "executable_semantics/ast/abstract_syntax_tree.h"
  50. #include "executable_semantics/ast/declaration.h"
  51. #include "executable_semantics/ast/expression.h"
  52. #include "executable_semantics/ast/function_definition.h"
  53. #include "executable_semantics/ast/pattern.h"
  54. #include "executable_semantics/common/arena.h"
  55. #include "executable_semantics/syntax/paren_contents.h"
  56. namespace Carbon {
  57. class ParseAndLexContext;
  58. } // namespace Carbon
  59. } // %code requires
  60. %code {
  61. extern int yylineno;
  62. void Carbon::Parser::error(const location_type&, const std::string& message) {
  63. context.PrintDiagnostic(message, yylineno);
  64. }
  65. } // %code
  66. %token <int> integer_literal
  67. %token <std::string> identifier
  68. %token <std::string> sized_type_literal
  69. %type <std::string> designator
  70. %type <const Declaration*> declaration
  71. %type <FunctionDefinition> function_declaration
  72. %type <FunctionDefinition> function_definition
  73. %type <std::list<const Declaration*>> declaration_list
  74. %type <const Statement*> statement
  75. %type <const Statement*> if_statement
  76. %type <const Statement*> optional_else
  77. %type <std::pair<const Expression*, bool>> return_expression
  78. %type <const Statement*> block
  79. %type <const Statement*> statement_list
  80. %type <const Expression*> expression
  81. %type <GenericBinding> generic_binding
  82. %type <std::vector<GenericBinding>> deduced_params
  83. %type <std::vector<GenericBinding>> deduced_param_list
  84. %type <const Pattern*> pattern
  85. %type <const Pattern*> non_expression_pattern
  86. %type <std::pair<const Expression*, bool>> return_type
  87. %type <const Expression*> paren_expression
  88. %type <const Expression*> tuple
  89. %type <std::optional<std::string>> binding_lhs
  90. %type <const BindingPattern*> variable_declaration
  91. %type <Member*> member
  92. %type <std::list<Member*>> member_list
  93. %type <ParenContents<Expression>::Element> paren_expression_element
  94. %type <ParenContents<Expression>> paren_expression_base
  95. %type <ParenContents<Expression>> paren_expression_contents
  96. %type <const Pattern*> paren_pattern
  97. %type <const TuplePattern*> tuple_pattern
  98. %type <const TuplePattern*> maybe_empty_tuple_pattern
  99. %type <ParenContents<Pattern>> paren_pattern_base
  100. %type <ParenContents<Pattern>::Element> paren_pattern_element
  101. %type <ParenContents<Pattern>> paren_pattern_contents
  102. %type <std::pair<std::string, const Expression*>> alternative
  103. %type <std::list<std::pair<std::string, const Expression*>>> alternative_list
  104. %type <std::pair<const Pattern*, const Statement*>*> clause
  105. %type <std::list<std::pair<const Pattern*, const Statement*>>*> clause_list
  106. %token END_OF_FILE 0
  107. %token AND
  108. %token OR
  109. %token NOT
  110. %token BOOL
  111. %token TYPE
  112. %token FN
  113. %token FNTY
  114. %token ARROW "->"
  115. %token FNARROW "-> in return type"
  116. %token VAR
  117. %token EQUAL_EQUAL
  118. %token IF
  119. %token ELSE
  120. %token WHILE
  121. %token CONTINUATION_TYPE
  122. %token CONTINUATION
  123. %token RUN
  124. %token AWAIT
  125. %token BREAK
  126. %token CONTINUE
  127. %token RETURN
  128. %token TRUE
  129. %token FALSE
  130. %token STRUCT
  131. %token CHOICE
  132. %token MATCH
  133. %token CASE
  134. %token DBLARROW "=>"
  135. %token DEFAULT
  136. %token AUTO
  137. %token UNDERSCORE
  138. %token
  139. EQUAL "="
  140. MINUS "-"
  141. PLUS "+"
  142. // The lexer determines the arity and fixity of each `*` based on whitespace
  143. // and adjacent tokens. UNARY_STAR indicates that the operator is unary but
  144. // could be either prefix or postfix.
  145. UNARY_STAR "unary *"
  146. PREFIX_STAR "prefix *"
  147. POSTFIX_STAR "postfix *"
  148. BINARY_STAR "binary *"
  149. SLASH "/"
  150. LEFT_PARENTHESIS "("
  151. RIGHT_PARENTHESIS ")"
  152. LEFT_CURLY_BRACE "{"
  153. RIGHT_CURLY_BRACE "}"
  154. LEFT_SQUARE_BRACKET "["
  155. RIGHT_SQUARE_BRACKET "]"
  156. PERIOD "."
  157. COMMA ","
  158. SEMICOLON ";"
  159. COLON_BANG ":!"
  160. COLON ":"
  161. ;
  162. %precedence FNARROW
  163. %precedence "{" "}"
  164. %precedence ":!" ":" "," DBLARROW
  165. %left OR AND
  166. %nonassoc EQUAL_EQUAL
  167. %left "+" "-"
  168. %left BINARY_STAR
  169. %precedence NOT UNARY_MINUS PREFIX_STAR
  170. // We need to give the `UNARY_STAR` token a precedence, rather than overriding
  171. // the precedence of the `expression UNARY_STAR` rule below, because bison
  172. // compares the precedence of the final token (for a shift) to the precedence
  173. // of the other rule (for a reduce) when attempting to resolve a shift-reduce
  174. // conflict. See https://stackoverflow.com/a/26188429/1041090. When UNARY_STAR
  175. // is the final token of a rule, it must be a postfix usage, so we give it the
  176. // same precedence as POSTFIX_STAR.
  177. %precedence POSTFIX_STAR UNARY_STAR
  178. %left "." ARROW
  179. %precedence "(" ")" "[" "]"
  180. %start input
  181. %locations
  182. %%
  183. input: declaration_list
  184. { parsed_program = $1; }
  185. ;
  186. expression:
  187. identifier
  188. { $$ = global_arena->New<IdentifierExpression>(yylineno, $1); }
  189. | expression designator
  190. { $$ = global_arena->New<FieldAccessExpression>(yylineno, $1, $2); }
  191. | expression "[" expression "]"
  192. { $$ = global_arena->New<IndexExpression>(yylineno, $1, $3); }
  193. | integer_literal
  194. { $$ = global_arena->New<IntLiteral>(yylineno, $1); }
  195. | TRUE
  196. { $$ = global_arena->New<BoolLiteral>(yylineno, true); }
  197. | FALSE
  198. { $$ = global_arena->New<BoolLiteral>(yylineno, false); }
  199. | sized_type_literal
  200. {
  201. int val;
  202. CHECK(llvm::to_integer(llvm::StringRef($1).substr(1), val));
  203. CHECK($1[0] == 'i' && val == 32) << "Only i32 is supported for now: " << $1;
  204. $$ = global_arena->New<IntTypeLiteral>(yylineno);
  205. }
  206. | BOOL
  207. { $$ = global_arena->New<BoolTypeLiteral>(yylineno); }
  208. | TYPE
  209. { $$ = global_arena->New<TypeTypeLiteral>(yylineno); }
  210. | CONTINUATION_TYPE
  211. { $$ = global_arena->New<ContinuationTypeLiteral>(yylineno); }
  212. | paren_expression { $$ = $1; }
  213. | expression EQUAL_EQUAL expression
  214. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  215. yylineno, Operator::Eq, std::vector<const Expression*>({$1, $3})); }
  216. | expression "+" expression
  217. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  218. yylineno, Operator::Add, std::vector<const Expression*>({$1, $3})); }
  219. | expression "-" expression
  220. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  221. yylineno, Operator::Sub, std::vector<const Expression*>({$1, $3})); }
  222. | expression BINARY_STAR expression
  223. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  224. yylineno, Operator::Mul, std::vector<const Expression*>({$1, $3})); }
  225. | expression AND expression
  226. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  227. yylineno, Operator::And, std::vector<const Expression*>({$1, $3})); }
  228. | expression OR expression
  229. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  230. yylineno, Operator::Or, std::vector<const Expression*>({$1, $3})); }
  231. | NOT expression
  232. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  233. yylineno, Operator::Not, std::vector<const Expression*>({$2})); }
  234. | "-" expression %prec UNARY_MINUS
  235. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  236. yylineno, Operator::Neg, std::vector<const Expression*>({$2})); }
  237. | PREFIX_STAR expression
  238. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  239. yylineno, Operator::Deref, std::vector<const Expression*>({$2})); }
  240. | UNARY_STAR expression %prec PREFIX_STAR
  241. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  242. yylineno, Operator::Deref, std::vector<const Expression*>({$2})); }
  243. | expression tuple
  244. { $$ = global_arena->New<CallExpression>(yylineno, $1, $2); }
  245. | expression POSTFIX_STAR
  246. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  247. yylineno, Operator::Ptr, std::vector<const Expression*>({$1})); }
  248. | expression UNARY_STAR
  249. { $$ = global_arena->New<PrimitiveOperatorExpression>(
  250. yylineno, Operator::Ptr, std::vector<const Expression*>({$1})); }
  251. | FNTY tuple return_type
  252. { $$ = global_arena->New<FunctionTypeLiteral>(
  253. yylineno, $2, $3.first, $3.second); }
  254. ;
  255. designator: "." identifier { $$ = $2; }
  256. ;
  257. paren_expression: paren_expression_base
  258. { $$ = ExpressionFromParenContents(yylineno, $1); }
  259. ;
  260. tuple: paren_expression_base
  261. { $$ = TupleExpressionFromParenContents(yylineno, $1); }
  262. ;
  263. paren_expression_element:
  264. expression
  265. { $$ = {.name = std::nullopt, .term = $1}; }
  266. | designator "=" expression
  267. { $$ = {.name = $1, .term = $3}; }
  268. ;
  269. paren_expression_base:
  270. "(" ")"
  271. { $$ = {.elements = {}, .has_trailing_comma = false}; }
  272. | "(" paren_expression_contents ")"
  273. { $$ = $2; }
  274. | "(" paren_expression_contents "," ")"
  275. {
  276. $$ = $2;
  277. $$.has_trailing_comma = true;
  278. }
  279. ;
  280. paren_expression_contents:
  281. paren_expression_element
  282. { $$ = {.elements = {$1}, .has_trailing_comma = false}; }
  283. | paren_expression_contents "," paren_expression_element
  284. {
  285. $$ = $1;
  286. $$.elements.push_back($3);
  287. }
  288. ;
  289. // In many cases, using `pattern` recursively will result in ambiguities.
  290. // When that happens, it's necessary to factor out two separate productions,
  291. // one for when the sub-pattern is an expression, and one for when it is not.
  292. // To facilitate this, non-terminals besides `pattern` whose names contain
  293. // `pattern` are structured to be disjoint from `expression`, unless otherwise
  294. // specified.
  295. pattern:
  296. non_expression_pattern
  297. { $$ = $1; }
  298. | expression
  299. { $$ = global_arena->New<ExpressionPattern>($1); }
  300. ;
  301. non_expression_pattern:
  302. AUTO
  303. { $$ = global_arena->New<AutoPattern>(yylineno); }
  304. | binding_lhs ":" pattern
  305. { $$ = global_arena->New<BindingPattern>(yylineno, $1, $3); }
  306. | paren_pattern
  307. { $$ = $1; }
  308. | expression tuple_pattern
  309. { $$ = global_arena->New<AlternativePattern>(yylineno, $1, $2); }
  310. ;
  311. binding_lhs:
  312. identifier { $$ = $1; }
  313. | UNDERSCORE { $$ = std::nullopt; }
  314. ;
  315. paren_pattern: paren_pattern_base
  316. { $$ = PatternFromParenContents(yylineno, $1); }
  317. ;
  318. paren_pattern_base:
  319. "(" paren_pattern_contents ")"
  320. { $$ = $2; }
  321. | "(" paren_pattern_contents "," ")"
  322. {
  323. $$ = $2;
  324. $$.has_trailing_comma = true;
  325. }
  326. ;
  327. // paren_pattern is analogous to paren_expression, but in order to avoid
  328. // ambiguities, it must be disjoint from paren_expression, meaning it must
  329. // contain at least one non_expression_pattern. The structure of this rule
  330. // is very different from the corresponding expression rule because is has to
  331. // enforce that requirement.
  332. paren_pattern_contents:
  333. paren_pattern_element
  334. { $$ = {.elements = {$1}, .has_trailing_comma = false }; }
  335. | paren_expression_contents "," paren_pattern_element
  336. {
  337. $$ = ParenExpressionToParenPattern($1);
  338. $$.elements.push_back($3);
  339. }
  340. | paren_pattern_contents "," paren_expression_element
  341. {
  342. $$ = $1;
  343. $$.elements.push_back({.name = $3.name, .term = global_arena->New<ExpressionPattern>($3.term)});
  344. }
  345. | paren_pattern_contents "," paren_pattern_element
  346. {
  347. $$ = $1;
  348. $$.elements.push_back($3);
  349. }
  350. ;
  351. paren_pattern_element:
  352. non_expression_pattern
  353. { $$ = {.name = std::nullopt, .term = $1}; }
  354. | designator "=" non_expression_pattern
  355. { $$ = {.name = $1, .term = $3}; }
  356. ;
  357. tuple_pattern: paren_pattern_base
  358. { $$ = TuplePatternFromParenContents(yylineno, $1); }
  359. ;
  360. // Unlike most `pattern` nonterminals, this one overlaps with `expression`,
  361. // so it should be used only when prior context (such as an introducer)
  362. // rules out the possibility of an `expression` at this point.
  363. maybe_empty_tuple_pattern:
  364. "(" ")"
  365. { $$ = global_arena->New<TuplePattern>(yylineno, std::vector<TuplePattern::Field>()); }
  366. | tuple_pattern
  367. { $$ = $1; }
  368. ;
  369. clause:
  370. CASE pattern DBLARROW statement
  371. { $$ = global_arena->New<std::pair<const Pattern*, const Statement*>>($2, $4); }
  372. | DEFAULT DBLARROW statement
  373. {
  374. auto vp = global_arena->New<BindingPattern>(
  375. yylineno, std::nullopt, global_arena->New<AutoPattern>(yylineno));
  376. $$ = global_arena->New<std::pair<const Pattern*, const Statement*>>(vp, $3);
  377. }
  378. ;
  379. clause_list:
  380. // Empty
  381. {
  382. $$ = global_arena->New<std::list<
  383. std::pair<const Pattern*, const Statement*>>>();
  384. }
  385. | clause clause_list
  386. { $$ = $2; $$->push_front(*$1); }
  387. ;
  388. statement:
  389. expression "=" expression ";"
  390. { $$ = Statement::MakeAssign(yylineno, $1, $3); }
  391. | VAR pattern "=" expression ";"
  392. { $$ = Statement::MakeVariableDefinition(yylineno, $2, $4); }
  393. | expression ";"
  394. { $$ = Statement::MakeExpressionStatement(yylineno, $1); }
  395. | if_statement
  396. { $$ = $1; }
  397. | WHILE "(" expression ")" block
  398. { $$ = Statement::MakeWhile(yylineno, $3, $5); }
  399. | BREAK ";"
  400. { $$ = Statement::MakeBreak(yylineno); }
  401. | CONTINUE ";"
  402. { $$ = Statement::MakeContinue(yylineno); }
  403. | RETURN return_expression ";"
  404. { $$ = Statement::MakeReturn(yylineno, $2.first, $2.second); }
  405. | block
  406. { $$ = $1; }
  407. | MATCH "(" expression ")" "{" clause_list "}"
  408. { $$ = Statement::MakeMatch(yylineno, $3, $6); }
  409. | CONTINUATION identifier statement
  410. { $$ = Statement::MakeContinuation(yylineno, $2, $3); }
  411. | RUN expression ";"
  412. { $$ = Statement::MakeRun(yylineno, $2); }
  413. | AWAIT ";"
  414. { $$ = Statement::MakeAwait(yylineno); }
  415. ;
  416. if_statement:
  417. IF "(" expression ")" block optional_else
  418. { $$ = Statement::MakeIf(yylineno, $3, $5, $6); }
  419. ;
  420. optional_else:
  421. // Empty
  422. { $$ = 0; }
  423. | ELSE if_statement
  424. { $$ = $2; }
  425. | ELSE block
  426. { $$ = $2; }
  427. ;
  428. return_expression:
  429. // Empty
  430. { $$ = {global_arena->New<TupleLiteral>(yylineno), true}; }
  431. | expression
  432. { $$ = {$1, false}; }
  433. ;
  434. statement_list:
  435. // Empty
  436. { $$ = 0; }
  437. | statement statement_list
  438. { $$ = Statement::MakeSequence(yylineno, $1, $2); }
  439. ;
  440. block:
  441. "{" statement_list "}"
  442. { $$ = Statement::MakeBlock(yylineno, $2); }
  443. ;
  444. return_type:
  445. // Empty
  446. { $$ = {global_arena->New<TupleLiteral>(yylineno), true}; }
  447. | ARROW expression %prec FNARROW
  448. { $$ = {$2, false}; }
  449. ;
  450. generic_binding:
  451. identifier ":!" expression
  452. {
  453. $$ = GenericBinding({.name = std::move($1), .type = $3});
  454. }
  455. ;
  456. deduced_param_list:
  457. // Empty
  458. { $$ = std::vector<GenericBinding>(); }
  459. | generic_binding
  460. {
  461. $$ = std::vector<GenericBinding>();
  462. $$.push_back($1);
  463. }
  464. | generic_binding "," deduced_param_list
  465. {
  466. $$ = $3;
  467. $$.push_back($1);
  468. }
  469. ;
  470. deduced_params:
  471. // Empty
  472. { $$ = std::vector<GenericBinding>(); }
  473. | "[" deduced_param_list "]"
  474. { $$ = $2; }
  475. ;
  476. function_definition:
  477. FN identifier deduced_params maybe_empty_tuple_pattern return_type block
  478. {
  479. $$ = FunctionDefinition(
  480. yylineno, $2, $3, $4,
  481. global_arena->New<ExpressionPattern>($5.first),
  482. $5.second, $6);
  483. }
  484. | FN identifier deduced_params maybe_empty_tuple_pattern DBLARROW expression ";"
  485. {
  486. // The return type is not considered "omitted" because it's automatic from
  487. // the expression.
  488. $$ = FunctionDefinition(
  489. yylineno, $2, $3, $4,
  490. global_arena->New<AutoPattern>(yylineno), true,
  491. Statement::MakeReturn(yylineno, $6, true));
  492. }
  493. ;
  494. function_declaration:
  495. FN identifier deduced_params maybe_empty_tuple_pattern return_type ";"
  496. {
  497. $$ = FunctionDefinition(
  498. yylineno, $2, $3, $4,
  499. global_arena->New<ExpressionPattern>($5.first),
  500. $5.second, nullptr); }
  501. ;
  502. variable_declaration: identifier ":" pattern
  503. { $$ = global_arena->New<BindingPattern>(yylineno, $1, $3); }
  504. ;
  505. member: VAR variable_declaration ";"
  506. { $$ = global_arena->New<FieldMember>(yylineno, $2); }
  507. ;
  508. member_list:
  509. // Empty
  510. { $$ = std::list<Member*>(); }
  511. | member member_list
  512. { $$ = $2; $$.push_front($1); }
  513. ;
  514. alternative:
  515. identifier tuple
  516. { $$ = std::pair<std::string, const Expression*>($1, $2); }
  517. | identifier
  518. {
  519. $$ = std::pair<std::string, const Expression*>(
  520. $1, global_arena->New<TupleLiteral>(yylineno));
  521. }
  522. ;
  523. alternative_list:
  524. // Empty
  525. { $$ = std::list<std::pair<std::string, const Expression*>>(); }
  526. | alternative
  527. {
  528. $$ = std::list<std::pair<std::string, const Expression*>>();
  529. $$.push_front($1);
  530. }
  531. | alternative "," alternative_list
  532. { $$ = std::move($3); $$.push_front($1); }
  533. ;
  534. declaration:
  535. function_definition
  536. { $$ = global_arena->New<FunctionDeclaration>(std::move($1)); }
  537. | function_declaration
  538. { $$ = global_arena->New<FunctionDeclaration>(std::move($1)); }
  539. | STRUCT identifier "{" member_list "}"
  540. {
  541. $$ = global_arena->New<StructDeclaration>(yylineno, $2, $4);
  542. }
  543. | CHOICE identifier "{" alternative_list "}"
  544. {
  545. $$ = global_arena->New<ChoiceDeclaration>(yylineno, $2, $4);
  546. }
  547. | VAR variable_declaration "=" expression ";"
  548. {
  549. $$ = global_arena->New<VariableDeclaration>(yylineno, $2, $4);
  550. }
  551. ;
  552. declaration_list:
  553. // Empty
  554. { $$ = std::list<const Declaration*>(); }
  555. | declaration declaration_list
  556. {
  557. $$ = $2;
  558. $$.push_front($1);
  559. }
  560. ;
  561. %%