Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glsl_parser.ypp 32KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. %{
  2. /*
  3. * Copyright © 2008, 2009 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <assert.h>
  28. #include "ast.h"
  29. #include "glsl_parser_extras.h"
  30. #include "glsl_types.h"
  31. #define YYLEX_PARAM state->scanner
  32. %}
  33. %pure-parser
  34. %locations
  35. %error-verbose
  36. %lex-param {void *scanner}
  37. %parse-param {struct _mesa_glsl_parse_state *state}
  38. %name-prefix "_mesa_glsl_"
  39. %union {
  40. int n;
  41. float real;
  42. char *identifier;
  43. union {
  44. struct ast_type_qualifier q;
  45. unsigned i;
  46. } type_qualifier;
  47. struct ast_node *node;
  48. struct ast_type_specifier *type_specifier;
  49. struct ast_fully_specified_type *fully_specified_type;
  50. struct ast_function *function;
  51. struct ast_parameter_declarator *parameter_declarator;
  52. struct ast_function_definition *function_definition;
  53. struct ast_compound_statement *compound_statement;
  54. struct ast_expression *expression;
  55. struct ast_declarator_list *declarator_list;
  56. struct ast_struct_specifier *struct_specifier;
  57. struct ast_declaration *declaration;
  58. struct {
  59. struct ast_node *cond;
  60. struct ast_expression *rest;
  61. } for_rest_statement;
  62. }
  63. %token ATTRIBUTE CONST BOOL FLOAT INT UINT
  64. %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
  65. %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
  66. %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
  67. %token NOPERSPECTIVE FLAT SMOOTH
  68. %token MAT2X2 MAT2X3 MAT2X4
  69. %token MAT3X2 MAT3X3 MAT3X4
  70. %token MAT4X2 MAT4X3 MAT4X4
  71. %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
  72. %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
  73. %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
  74. %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
  75. %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
  76. %token STRUCT VOID WHILE
  77. %token <identifier> IDENTIFIER TYPE_NAME
  78. %token <real> FLOATCONSTANT
  79. %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
  80. %token <identifier> FIELD_SELECTION
  81. %token LEFT_OP RIGHT_OP
  82. %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
  83. %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
  84. %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
  85. %token SUB_ASSIGN
  86. %token INVARIANT
  87. %token HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
  88. %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
  89. /* Reserved words that are not actually used in the grammar.
  90. */
  91. %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
  92. %token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
  93. %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
  94. %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
  95. %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
  96. %token SIZEOF CAST NAMESPACE USING LOWP MEDIUMP HIGHP
  97. %type <identifier> variable_identifier
  98. %type <node> statement
  99. %type <node> statement_list
  100. %type <node> simple_statement
  101. %type <node> statement_matched
  102. %type <node> statement_unmatched
  103. %type <n> precision_qualifier
  104. %type <type_qualifier> type_qualifier
  105. %type <type_qualifier> storage_qualifier
  106. %type <type_qualifier> interpolation_qualifier
  107. %type <type_specifier> type_specifier
  108. %type <type_specifier> type_specifier_no_prec
  109. %type <type_specifier> type_specifier_nonarray
  110. %type <n> basic_type_specifier_nonarray
  111. %type <fully_specified_type> fully_specified_type
  112. %type <function> function_prototype
  113. %type <function> function_header
  114. %type <function> function_header_with_parameters
  115. %type <function> function_declarator
  116. %type <parameter_declarator> parameter_declarator
  117. %type <parameter_declarator> parameter_declaration
  118. %type <type_qualifier> parameter_qualifier
  119. %type <type_qualifier> parameter_type_qualifier
  120. %type <type_specifier> parameter_type_specifier
  121. %type <function_definition> function_definition
  122. %type <compound_statement> compound_statement_no_new_scope
  123. %type <compound_statement> compound_statement
  124. %type <node> statement_no_new_scope
  125. %type <node> expression_statement
  126. %type <expression> expression
  127. %type <expression> primary_expression
  128. %type <expression> assignment_expression
  129. %type <expression> conditional_expression
  130. %type <expression> logical_or_expression
  131. %type <expression> logical_xor_expression
  132. %type <expression> logical_and_expression
  133. %type <expression> inclusive_or_expression
  134. %type <expression> exclusive_or_expression
  135. %type <expression> and_expression
  136. %type <expression> equality_expression
  137. %type <expression> relational_expression
  138. %type <expression> shift_expression
  139. %type <expression> additive_expression
  140. %type <expression> multiplicative_expression
  141. %type <expression> unary_expression
  142. %type <expression> constant_expression
  143. %type <expression> integer_expression
  144. %type <expression> postfix_expression
  145. %type <expression> function_call_header_with_parameters
  146. %type <expression> function_call_header_no_parameters
  147. %type <expression> function_call_header
  148. %type <expression> function_call_generic
  149. %type <expression> function_call_or_method
  150. %type <expression> function_call
  151. %type <n> assignment_operator
  152. %type <n> unary_operator
  153. %type <expression> function_identifier
  154. %type <node> external_declaration
  155. %type <declarator_list> init_declarator_list
  156. %type <declarator_list> single_declaration
  157. %type <expression> initializer
  158. %type <node> declaration
  159. %type <node> declaration_statement
  160. %type <node> jump_statement
  161. %type <struct_specifier> struct_specifier
  162. %type <node> struct_declaration_list
  163. %type <declarator_list> struct_declaration
  164. %type <declaration> struct_declarator
  165. %type <declaration> struct_declarator_list
  166. %type <node> selection_statement_matched
  167. %type <node> selection_statement_unmatched
  168. %type <node> iteration_statement
  169. %type <node> condition
  170. %type <node> conditionopt
  171. %type <node> for_init_statement
  172. %type <for_rest_statement> for_rest_statement
  173. %%
  174. translation_unit:
  175. version_statement
  176. {
  177. _mesa_glsl_initialize_types(state);
  178. }
  179. extension_statement_list external_declaration_list
  180. |
  181. {
  182. state->language_version = 110;
  183. _mesa_glsl_initialize_types(state);
  184. }
  185. extension_statement_list external_declaration_list
  186. ;
  187. version_statement:
  188. VERSION INTCONSTANT EOL
  189. {
  190. switch ($2) {
  191. case 110:
  192. case 120:
  193. case 130:
  194. /* FINISHME: Check against implementation support versions. */
  195. state->language_version = $2;
  196. break;
  197. default:
  198. _mesa_glsl_error(& @2, state, "Shading language version"
  199. "%u is not supported\n", $2);
  200. break;
  201. }
  202. }
  203. ;
  204. extension_statement_list:
  205. | extension_statement_list extension_statement
  206. ;
  207. extension_statement:
  208. EXTENSION IDENTIFIER COLON IDENTIFIER EOL
  209. {
  210. if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
  211. YYERROR;
  212. }
  213. }
  214. ;
  215. external_declaration_list:
  216. external_declaration
  217. {
  218. insert_at_tail(& state->translation_unit,
  219. (struct simple_node *) $1);
  220. }
  221. | external_declaration_list external_declaration
  222. {
  223. insert_at_tail(& state->translation_unit,
  224. (struct simple_node *) $2);
  225. }
  226. ;
  227. variable_identifier:
  228. IDENTIFIER
  229. ;
  230. primary_expression:
  231. variable_identifier
  232. {
  233. $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
  234. $$->set_location(yylloc);
  235. $$->primary_expression.identifier = $1;
  236. }
  237. | INTCONSTANT
  238. {
  239. $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
  240. $$->set_location(yylloc);
  241. $$->primary_expression.int_constant = $1;
  242. }
  243. | UINTCONSTANT
  244. {
  245. $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
  246. $$->set_location(yylloc);
  247. $$->primary_expression.uint_constant = $1;
  248. }
  249. | FLOATCONSTANT
  250. {
  251. $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
  252. $$->set_location(yylloc);
  253. $$->primary_expression.float_constant = $1;
  254. }
  255. | BOOLCONSTANT
  256. {
  257. $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
  258. $$->set_location(yylloc);
  259. $$->primary_expression.bool_constant = $1;
  260. }
  261. | '(' expression ')'
  262. {
  263. $$ = $2;
  264. }
  265. ;
  266. postfix_expression:
  267. primary_expression
  268. | postfix_expression '[' integer_expression ']'
  269. {
  270. $$ = new ast_expression(ast_array_index, $1, $3, NULL);
  271. $$->set_location(yylloc);
  272. }
  273. | function_call
  274. {
  275. $$ = $1;
  276. }
  277. | postfix_expression '.' IDENTIFIER
  278. {
  279. $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
  280. $$->set_location(yylloc);
  281. $$->primary_expression.identifier = $3;
  282. }
  283. | postfix_expression INC_OP
  284. {
  285. $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
  286. $$->set_location(yylloc);
  287. }
  288. | postfix_expression DEC_OP
  289. {
  290. $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
  291. $$->set_location(yylloc);
  292. }
  293. ;
  294. integer_expression:
  295. expression
  296. ;
  297. function_call:
  298. function_call_or_method
  299. ;
  300. function_call_or_method:
  301. function_call_generic
  302. | postfix_expression '.' function_call_generic
  303. {
  304. $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
  305. $$->set_location(yylloc);
  306. }
  307. ;
  308. function_call_generic:
  309. function_call_header_with_parameters ')'
  310. | function_call_header_no_parameters ')'
  311. ;
  312. function_call_header_no_parameters:
  313. function_call_header VOID
  314. | function_call_header
  315. ;
  316. function_call_header_with_parameters:
  317. function_call_header assignment_expression
  318. {
  319. $$ = $1;
  320. $$->set_location(yylloc);
  321. $$->subexpressions[1] = $2;
  322. }
  323. | function_call_header_with_parameters ',' assignment_expression
  324. {
  325. $$ = $1;
  326. $$->set_location(yylloc);
  327. insert_at_tail((struct simple_node *) $$->subexpressions[1],
  328. (struct simple_node *) $3);
  329. }
  330. ;
  331. // Grammar Note: Constructors look like functions, but lexical
  332. // analysis recognized most of them as keywords. They are now
  333. // recognized through "type_specifier".
  334. function_call_header:
  335. function_identifier '('
  336. ;
  337. function_identifier:
  338. type_specifier
  339. {
  340. $$ = new ast_function_expression($1);
  341. $$->set_location(yylloc);
  342. }
  343. | IDENTIFIER
  344. {
  345. ast_expression *callee = new ast_expression($1);
  346. $$ = new ast_function_expression(callee);
  347. $$->set_location(yylloc);
  348. }
  349. | FIELD_SELECTION
  350. {
  351. ast_expression *callee = new ast_expression($1);
  352. $$ = new ast_function_expression(callee);
  353. $$->set_location(yylloc);
  354. }
  355. ;
  356. // Grammar Note: No traditional style type casts.
  357. unary_expression:
  358. postfix_expression
  359. | INC_OP unary_expression
  360. {
  361. $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
  362. $$->set_location(yylloc);
  363. }
  364. | DEC_OP unary_expression
  365. {
  366. $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
  367. $$->set_location(yylloc);
  368. }
  369. | unary_operator unary_expression
  370. {
  371. $$ = new ast_expression($1, $2, NULL, NULL);
  372. $$->set_location(yylloc);
  373. }
  374. ;
  375. // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
  376. unary_operator:
  377. '+' { $$ = ast_plus; }
  378. | '-' { $$ = ast_neg; }
  379. | '!' { $$ = ast_logic_not; }
  380. | '~' { $$ = ast_bit_not; }
  381. ;
  382. multiplicative_expression:
  383. unary_expression
  384. | multiplicative_expression '*' unary_expression
  385. {
  386. $$ = new ast_expression_bin(ast_mul, $1, $3);
  387. $$->set_location(yylloc);
  388. }
  389. | multiplicative_expression '/' unary_expression
  390. {
  391. $$ = new ast_expression_bin(ast_div, $1, $3);
  392. $$->set_location(yylloc);
  393. }
  394. | multiplicative_expression '%' unary_expression
  395. {
  396. $$ = new ast_expression_bin(ast_mod, $1, $3);
  397. $$->set_location(yylloc);
  398. }
  399. ;
  400. additive_expression:
  401. multiplicative_expression
  402. | additive_expression '+' multiplicative_expression
  403. {
  404. $$ = new ast_expression_bin(ast_add, $1, $3);
  405. $$->set_location(yylloc);
  406. }
  407. | additive_expression '-' multiplicative_expression
  408. {
  409. $$ = new ast_expression_bin(ast_sub, $1, $3);
  410. $$->set_location(yylloc);
  411. }
  412. ;
  413. shift_expression:
  414. additive_expression
  415. | shift_expression LEFT_OP additive_expression
  416. {
  417. $$ = new ast_expression_bin(ast_lshift, $1, $3);
  418. $$->set_location(yylloc);
  419. }
  420. | shift_expression RIGHT_OP additive_expression
  421. {
  422. $$ = new ast_expression_bin(ast_rshift, $1, $3);
  423. $$->set_location(yylloc);
  424. }
  425. ;
  426. relational_expression:
  427. shift_expression
  428. | relational_expression '<' shift_expression
  429. {
  430. $$ = new ast_expression_bin(ast_less, $1, $3);
  431. $$->set_location(yylloc);
  432. }
  433. | relational_expression '>' shift_expression
  434. {
  435. $$ = new ast_expression_bin(ast_greater, $1, $3);
  436. $$->set_location(yylloc);
  437. }
  438. | relational_expression LE_OP shift_expression
  439. {
  440. $$ = new ast_expression_bin(ast_lequal, $1, $3);
  441. $$->set_location(yylloc);
  442. }
  443. | relational_expression GE_OP shift_expression
  444. {
  445. $$ = new ast_expression_bin(ast_gequal, $1, $3);
  446. $$->set_location(yylloc);
  447. }
  448. ;
  449. equality_expression:
  450. relational_expression
  451. | equality_expression EQ_OP relational_expression
  452. {
  453. $$ = new ast_expression_bin(ast_equal, $1, $3);
  454. $$->set_location(yylloc);
  455. }
  456. | equality_expression NE_OP relational_expression
  457. {
  458. $$ = new ast_expression_bin(ast_nequal, $1, $3);
  459. $$->set_location(yylloc);
  460. }
  461. ;
  462. and_expression:
  463. equality_expression
  464. | and_expression '&' equality_expression
  465. {
  466. $$ = new ast_expression_bin(ast_bit_or, $1, $3);
  467. $$->set_location(yylloc);
  468. }
  469. ;
  470. exclusive_or_expression:
  471. and_expression
  472. | exclusive_or_expression '^' and_expression
  473. {
  474. $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
  475. $$->set_location(yylloc);
  476. }
  477. ;
  478. inclusive_or_expression:
  479. exclusive_or_expression
  480. | inclusive_or_expression '|' exclusive_or_expression
  481. {
  482. $$ = new ast_expression_bin(ast_bit_or, $1, $3);
  483. $$->set_location(yylloc);
  484. }
  485. ;
  486. logical_and_expression:
  487. inclusive_or_expression
  488. | logical_and_expression AND_OP inclusive_or_expression
  489. {
  490. $$ = new ast_expression_bin(ast_logic_and, $1, $3);
  491. $$->set_location(yylloc);
  492. }
  493. ;
  494. logical_xor_expression:
  495. logical_and_expression
  496. | logical_xor_expression XOR_OP logical_and_expression
  497. {
  498. $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
  499. $$->set_location(yylloc);
  500. }
  501. ;
  502. logical_or_expression:
  503. logical_xor_expression
  504. | logical_or_expression OR_OP logical_xor_expression
  505. {
  506. $$ = new ast_expression_bin(ast_logic_or, $1, $3);
  507. $$->set_location(yylloc);
  508. }
  509. ;
  510. conditional_expression:
  511. logical_or_expression
  512. | logical_or_expression '?' expression ':' assignment_expression
  513. {
  514. $$ = new ast_expression(ast_conditional, $1, $3, $5);
  515. $$->set_location(yylloc);
  516. }
  517. ;
  518. assignment_expression:
  519. conditional_expression
  520. | unary_expression assignment_operator assignment_expression
  521. {
  522. $$ = new ast_expression($2, $1, $3, NULL);
  523. $$->set_location(yylloc);
  524. }
  525. ;
  526. assignment_operator:
  527. '=' { $$ = ast_assign; }
  528. | MUL_ASSIGN { $$ = ast_mul_assign; }
  529. | DIV_ASSIGN { $$ = ast_div_assign; }
  530. | MOD_ASSIGN { $$ = ast_mod_assign; }
  531. | ADD_ASSIGN { $$ = ast_add_assign; }
  532. | SUB_ASSIGN { $$ = ast_sub_assign; }
  533. | LEFT_ASSIGN { $$ = ast_ls_assign; }
  534. | RIGHT_ASSIGN { $$ = ast_rs_assign; }
  535. | AND_ASSIGN { $$ = ast_and_assign; }
  536. | XOR_ASSIGN { $$ = ast_xor_assign; }
  537. | OR_ASSIGN { $$ = ast_or_assign; }
  538. ;
  539. expression:
  540. assignment_expression
  541. {
  542. $$ = $1;
  543. }
  544. | expression ',' assignment_expression
  545. {
  546. if ($1->oper != ast_sequence) {
  547. $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
  548. $$->set_location(yylloc);
  549. insert_at_tail(& $$->expressions, $1);
  550. } else {
  551. $$ = $1;
  552. }
  553. insert_at_tail(& $$->expressions, $3);
  554. }
  555. ;
  556. constant_expression:
  557. conditional_expression
  558. ;
  559. declaration:
  560. function_prototype ';'
  561. {
  562. $$ = $1;
  563. }
  564. | init_declarator_list ';'
  565. {
  566. $$ = $1;
  567. }
  568. | PRECISION precision_qualifier type_specifier_no_prec ';'
  569. {
  570. $$ = NULL; /* FINISHME */
  571. }
  572. ;
  573. function_prototype:
  574. function_declarator ')'
  575. ;
  576. function_declarator:
  577. function_header
  578. | function_header_with_parameters
  579. ;
  580. function_header_with_parameters:
  581. function_header parameter_declaration
  582. {
  583. $$ = $1;
  584. insert_at_tail(& $$->parameters,
  585. (struct simple_node *) $2);
  586. }
  587. | function_header_with_parameters ',' parameter_declaration
  588. {
  589. $$ = $1;
  590. insert_at_tail(& $$->parameters,
  591. (struct simple_node *) $3);
  592. }
  593. ;
  594. function_header:
  595. fully_specified_type IDENTIFIER '('
  596. {
  597. $$ = new ast_function();
  598. $$->set_location(yylloc);
  599. $$->return_type = $1;
  600. $$->identifier = $2;
  601. }
  602. ;
  603. parameter_declarator:
  604. type_specifier IDENTIFIER
  605. {
  606. $$ = new ast_parameter_declarator();
  607. $$->set_location(yylloc);
  608. $$->type = new ast_fully_specified_type();
  609. $$->type->set_location(yylloc);
  610. $$->type->specifier = $1;
  611. $$->identifier = $2;
  612. }
  613. | type_specifier IDENTIFIER '[' constant_expression ']'
  614. {
  615. $$ = new ast_parameter_declarator();
  616. $$->set_location(yylloc);
  617. $$->type = new ast_fully_specified_type();
  618. $$->type->set_location(yylloc);
  619. $$->type->specifier = $1;
  620. $$->identifier = $2;
  621. $$->is_array = true;
  622. $$->array_size = $4;
  623. }
  624. ;
  625. parameter_declaration:
  626. parameter_type_qualifier parameter_qualifier parameter_declarator
  627. {
  628. $1.i |= $2.i;
  629. $$ = $3;
  630. $$->type->qualifier = $1.q;
  631. }
  632. | parameter_qualifier parameter_declarator
  633. {
  634. $$ = $2;
  635. $$->type->qualifier = $1.q;
  636. }
  637. | parameter_type_qualifier parameter_qualifier parameter_type_specifier
  638. {
  639. $1.i |= $2.i;
  640. $$ = new ast_parameter_declarator();
  641. $$->set_location(yylloc);
  642. $$->type = new ast_fully_specified_type();
  643. $$->type->qualifier = $1.q;
  644. $$->type->specifier = $3;
  645. }
  646. | parameter_qualifier parameter_type_specifier
  647. {
  648. $$ = new ast_parameter_declarator();
  649. $$->set_location(yylloc);
  650. $$->type = new ast_fully_specified_type();
  651. $$->type->qualifier = $1.q;
  652. $$->type->specifier = $2;
  653. }
  654. ;
  655. parameter_qualifier:
  656. /* empty */ { $$.i = 0; }
  657. | IN { $$.i = 0; $$.q.in = 1; }
  658. | OUT { $$.i = 0; $$.q.out = 1; }
  659. | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
  660. ;
  661. parameter_type_specifier:
  662. type_specifier
  663. ;
  664. init_declarator_list:
  665. single_declaration
  666. | init_declarator_list ',' IDENTIFIER
  667. {
  668. ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
  669. decl->set_location(yylloc);
  670. $$ = $1;
  671. insert_at_tail(& $$->declarations,
  672. (struct simple_node *) decl);
  673. }
  674. | init_declarator_list ',' IDENTIFIER '[' ']'
  675. {
  676. ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
  677. decl->set_location(yylloc);
  678. $$ = $1;
  679. insert_at_tail(& $$->declarations,
  680. (struct simple_node *) decl);
  681. }
  682. | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
  683. {
  684. ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
  685. decl->set_location(yylloc);
  686. $$ = $1;
  687. insert_at_tail(& $$->declarations,
  688. (struct simple_node *) decl);
  689. }
  690. | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
  691. {
  692. ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
  693. decl->set_location(yylloc);
  694. $$ = $1;
  695. insert_at_tail(& $$->declarations,
  696. (struct simple_node *) decl);
  697. }
  698. | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
  699. {
  700. ast_declaration *decl = new ast_declaration($3, true, $5, $8);
  701. decl->set_location(yylloc);
  702. $$ = $1;
  703. insert_at_tail(& $$->declarations,
  704. (struct simple_node *) decl);
  705. }
  706. | init_declarator_list ',' IDENTIFIER '=' initializer
  707. {
  708. ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
  709. decl->set_location(yylloc);
  710. $$ = $1;
  711. insert_at_tail(& $$->declarations,
  712. (struct simple_node *) decl);
  713. }
  714. ;
  715. // Grammar Note: No 'enum', or 'typedef'.
  716. single_declaration:
  717. fully_specified_type
  718. {
  719. $$ = new ast_declarator_list($1);
  720. $$->set_location(yylloc);
  721. }
  722. | fully_specified_type IDENTIFIER
  723. {
  724. ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
  725. $$ = new ast_declarator_list($1);
  726. $$->set_location(yylloc);
  727. insert_at_tail(& $$->declarations,
  728. (struct simple_node *) decl);
  729. }
  730. | fully_specified_type IDENTIFIER '[' ']'
  731. {
  732. ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
  733. $$ = new ast_declarator_list($1);
  734. $$->set_location(yylloc);
  735. insert_at_tail(& $$->declarations,
  736. (struct simple_node *) decl);
  737. }
  738. | fully_specified_type IDENTIFIER '[' constant_expression ']'
  739. {
  740. ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
  741. $$ = new ast_declarator_list($1);
  742. $$->set_location(yylloc);
  743. insert_at_tail(& $$->declarations,
  744. (struct simple_node *) decl);
  745. }
  746. | fully_specified_type IDENTIFIER '[' ']' '=' initializer
  747. {
  748. ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
  749. $$ = new ast_declarator_list($1);
  750. $$->set_location(yylloc);
  751. insert_at_tail(& $$->declarations,
  752. (struct simple_node *) decl);
  753. }
  754. | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
  755. {
  756. ast_declaration *decl = new ast_declaration($2, true, $4, $7);
  757. $$ = new ast_declarator_list($1);
  758. $$->set_location(yylloc);
  759. insert_at_tail(& $$->declarations,
  760. (struct simple_node *) decl);
  761. }
  762. | fully_specified_type IDENTIFIER '=' initializer
  763. {
  764. ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
  765. $$ = new ast_declarator_list($1);
  766. $$->set_location(yylloc);
  767. insert_at_tail(& $$->declarations,
  768. (struct simple_node *) decl);
  769. }
  770. | INVARIANT IDENTIFIER // Vertex only.
  771. {
  772. ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
  773. $$ = new ast_declarator_list(NULL);
  774. $$->set_location(yylloc);
  775. $$->invariant = true;
  776. insert_at_tail(& $$->declarations,
  777. (struct simple_node *) decl);
  778. }
  779. ;
  780. fully_specified_type:
  781. type_specifier
  782. {
  783. $$ = new ast_fully_specified_type();
  784. $$->set_location(yylloc);
  785. $$->specifier = $1;
  786. }
  787. | type_qualifier type_specifier
  788. {
  789. $$ = new ast_fully_specified_type();
  790. $$->set_location(yylloc);
  791. $$->qualifier = $1.q;
  792. $$->specifier = $2;
  793. }
  794. ;
  795. interpolation_qualifier:
  796. SMOOTH { $$.i = 0; $$.q.smooth = 1; }
  797. | FLAT { $$.i = 0; $$.q.flat = 1; }
  798. | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
  799. ;
  800. parameter_type_qualifier:
  801. CONST { $$.i = 0; $$.q.constant = 1; }
  802. ;
  803. type_qualifier:
  804. storage_qualifier
  805. | interpolation_qualifier type_qualifier
  806. {
  807. $$.i = $1.i | $2.i;
  808. }
  809. | INVARIANT type_qualifier
  810. {
  811. $$ = $2;
  812. $$.q.invariant = 1;
  813. }
  814. ;
  815. storage_qualifier:
  816. CONST { $$.i = 0; $$.q.constant = 1; }
  817. | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
  818. | VARYING { $$.i = 0; $$.q.varying = 1; }
  819. | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
  820. | IN { $$.i = 0; $$.q.in = 1; }
  821. | OUT { $$.i = 0; $$.q.out = 1; }
  822. | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
  823. | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
  824. | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
  825. ;
  826. type_specifier:
  827. type_specifier_no_prec
  828. | precision_qualifier type_specifier_no_prec
  829. {
  830. $$ = $2;
  831. $$->precision = $1;
  832. }
  833. ;
  834. type_specifier_no_prec:
  835. type_specifier_nonarray
  836. | type_specifier_nonarray '[' ']'
  837. {
  838. $$ = $1;
  839. $$->is_array = true;
  840. $$->array_size = NULL;
  841. }
  842. | type_specifier_nonarray '[' constant_expression ']'
  843. {
  844. $$ = $1;
  845. $$->is_array = true;
  846. $$->array_size = $3;
  847. }
  848. ;
  849. type_specifier_nonarray:
  850. basic_type_specifier_nonarray
  851. {
  852. $$ = new ast_type_specifier($1);
  853. $$->set_location(yylloc);
  854. }
  855. | struct_specifier
  856. {
  857. $$ = new ast_type_specifier($1);
  858. $$->set_location(yylloc);
  859. }
  860. | TYPE_NAME
  861. {
  862. $$ = new ast_type_specifier($1);
  863. $$->set_location(yylloc);
  864. }
  865. ;
  866. basic_type_specifier_nonarray:
  867. VOID { $$ = ast_void; }
  868. | FLOAT { $$ = ast_float; }
  869. | INT { $$ = ast_int; }
  870. | UINT { $$ = ast_uint; }
  871. | BOOL { $$ = ast_bool; }
  872. | VEC2 { $$ = ast_vec2; }
  873. | VEC3 { $$ = ast_vec3; }
  874. | VEC4 { $$ = ast_vec4; }
  875. | BVEC2 { $$ = ast_bvec2; }
  876. | BVEC3 { $$ = ast_bvec3; }
  877. | BVEC4 { $$ = ast_bvec4; }
  878. | IVEC2 { $$ = ast_ivec2; }
  879. | IVEC3 { $$ = ast_ivec3; }
  880. | IVEC4 { $$ = ast_ivec4; }
  881. | UVEC2 { $$ = ast_uvec2; }
  882. | UVEC3 { $$ = ast_uvec3; }
  883. | UVEC4 { $$ = ast_uvec4; }
  884. | MAT2 { $$ = ast_mat2; }
  885. | MAT3 { $$ = ast_mat3; }
  886. | MAT4 { $$ = ast_mat4; }
  887. | MAT2X2 { $$ = ast_mat2; }
  888. | MAT2X3 { $$ = ast_mat2x3; }
  889. | MAT2X4 { $$ = ast_mat2x4; }
  890. | MAT3X2 { $$ = ast_mat3x2; }
  891. | MAT3X3 { $$ = ast_mat3; }
  892. | MAT3X4 { $$ = ast_mat3x4; }
  893. | MAT4X2 { $$ = ast_mat4x2; }
  894. | MAT4X3 { $$ = ast_mat4x3; }
  895. | MAT4X4 { $$ = ast_mat4; }
  896. | SAMPLER1D { $$ = ast_sampler1d; }
  897. | SAMPLER2D { $$ = ast_sampler2d; }
  898. | SAMPLER2DRECT { $$ = ast_sampler2drect; }
  899. | SAMPLER3D { $$ = ast_sampler3d; }
  900. | SAMPLERCUBE { $$ = ast_samplercube; }
  901. | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
  902. | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
  903. | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
  904. | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
  905. | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
  906. | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
  907. | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
  908. | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
  909. | ISAMPLER1D { $$ = ast_isampler1d; }
  910. | ISAMPLER2D { $$ = ast_isampler2d; }
  911. | ISAMPLER3D { $$ = ast_isampler3d; }
  912. | ISAMPLERCUBE { $$ = ast_isamplercube; }
  913. | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
  914. | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
  915. | USAMPLER1D { $$ = ast_usampler1d; }
  916. | USAMPLER2D { $$ = ast_usampler2d; }
  917. | USAMPLER3D { $$ = ast_usampler3d; }
  918. | USAMPLERCUBE { $$ = ast_usamplercube; }
  919. | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
  920. | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
  921. ;
  922. precision_qualifier:
  923. HIGH_PRECISION { $$ = ast_precision_high; }
  924. | MEDIUM_PRECISION { $$ = ast_precision_medium; }
  925. | LOW_PRECISION { $$ = ast_precision_low; }
  926. ;
  927. struct_specifier:
  928. STRUCT IDENTIFIER '{' struct_declaration_list '}'
  929. {
  930. $$ = new ast_struct_specifier($2, $4);
  931. $$->set_location(yylloc);
  932. }
  933. | STRUCT '{' struct_declaration_list '}'
  934. {
  935. $$ = new ast_struct_specifier(NULL, $3);
  936. $$->set_location(yylloc);
  937. }
  938. ;
  939. struct_declaration_list:
  940. struct_declaration
  941. {
  942. $$ = (struct ast_node *) $1;
  943. }
  944. | struct_declaration_list struct_declaration
  945. {
  946. $$ = (struct ast_node *) $1;
  947. insert_at_tail((struct simple_node *) $$,
  948. (struct simple_node *) $2);
  949. }
  950. ;
  951. struct_declaration:
  952. type_specifier struct_declarator_list ';'
  953. {
  954. ast_fully_specified_type *type = new ast_fully_specified_type();
  955. type->set_location(yylloc);
  956. type->specifier = $1;
  957. $$ = new ast_declarator_list(type);
  958. $$->set_location(yylloc);
  959. insert_at_tail((struct simple_node *) $2,
  960. & $$->declarations);
  961. }
  962. ;
  963. struct_declarator_list:
  964. struct_declarator
  965. | struct_declarator_list ',' struct_declarator
  966. {
  967. $$ = $1;
  968. insert_at_tail((struct simple_node *) $$,
  969. (struct simple_node *) $3);
  970. }
  971. ;
  972. struct_declarator:
  973. IDENTIFIER
  974. {
  975. $$ = new ast_declaration($1, false, NULL, NULL);
  976. $$->set_location(yylloc);
  977. }
  978. | IDENTIFIER '[' constant_expression ']'
  979. {
  980. $$ = new ast_declaration($1, true, $3, NULL);
  981. $$->set_location(yylloc);
  982. }
  983. ;
  984. initializer:
  985. assignment_expression
  986. ;
  987. declaration_statement:
  988. declaration
  989. ;
  990. // Grammar Note: labeled statements for SWITCH only; 'goto' is not
  991. // supported.
  992. statement:
  993. statement_matched
  994. | statement_unmatched
  995. ;
  996. statement_matched:
  997. compound_statement { $$ = (struct ast_node *) $1; }
  998. | simple_statement
  999. ;
  1000. statement_unmatched:
  1001. selection_statement_unmatched
  1002. ;
  1003. simple_statement:
  1004. declaration_statement
  1005. | expression_statement
  1006. | selection_statement_matched
  1007. | switch_statement { $$ = NULL; }
  1008. | case_label { $$ = NULL; }
  1009. | iteration_statement
  1010. | jump_statement
  1011. ;
  1012. compound_statement:
  1013. '{' '}'
  1014. {
  1015. $$ = new ast_compound_statement(true, NULL);
  1016. $$->set_location(yylloc);
  1017. }
  1018. | '{' statement_list '}'
  1019. {
  1020. $$ = new ast_compound_statement(true, $2);
  1021. $$->set_location(yylloc);
  1022. }
  1023. ;
  1024. statement_no_new_scope:
  1025. compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
  1026. | simple_statement
  1027. ;
  1028. compound_statement_no_new_scope:
  1029. '{' '}'
  1030. {
  1031. $$ = new ast_compound_statement(false, NULL);
  1032. $$->set_location(yylloc);
  1033. }
  1034. | '{' statement_list '}'
  1035. {
  1036. $$ = new ast_compound_statement(false, $2);
  1037. $$->set_location(yylloc);
  1038. }
  1039. ;
  1040. statement_list:
  1041. statement
  1042. {
  1043. if ($1 == NULL) {
  1044. _mesa_glsl_error(& @1, state, "<nil> statement\n");
  1045. assert($1 != NULL);
  1046. }
  1047. $$ = $1;
  1048. make_empty_list((struct simple_node *) $$);
  1049. }
  1050. | statement_list statement
  1051. {
  1052. if ($2 == NULL) {
  1053. _mesa_glsl_error(& @2, state, "<nil> statement\n");
  1054. assert($2 != NULL);
  1055. }
  1056. $$ = $1;
  1057. insert_at_tail((struct simple_node *) $$,
  1058. (struct simple_node *) $2);
  1059. }
  1060. ;
  1061. expression_statement:
  1062. ';'
  1063. {
  1064. $$ = new ast_expression_statement(NULL);
  1065. $$->set_location(yylloc);
  1066. }
  1067. | expression ';'
  1068. {
  1069. $$ = new ast_expression_statement($1);
  1070. $$->set_location(yylloc);
  1071. }
  1072. ;
  1073. selection_statement_matched:
  1074. IF '(' expression ')' statement_matched ELSE statement_matched
  1075. {
  1076. $$ = new ast_selection_statement($3, $5, $7);
  1077. $$->set_location(yylloc);
  1078. }
  1079. ;
  1080. selection_statement_unmatched:
  1081. IF '(' expression ')' statement_matched
  1082. {
  1083. $$ = new ast_selection_statement($3, $5, NULL);
  1084. $$->set_location(yylloc);
  1085. }
  1086. | IF '(' expression ')' statement_unmatched
  1087. {
  1088. $$ = new ast_selection_statement($3, $5, NULL);
  1089. $$->set_location(yylloc);
  1090. }
  1091. | IF '(' expression ')' statement_matched ELSE statement_unmatched
  1092. {
  1093. $$ = new ast_selection_statement($3, $5, $7);
  1094. $$->set_location(yylloc);
  1095. }
  1096. ;
  1097. condition:
  1098. expression
  1099. {
  1100. $$ = (struct ast_node *) $1;
  1101. }
  1102. | fully_specified_type IDENTIFIER '=' initializer
  1103. {
  1104. ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
  1105. ast_declarator_list *declarator = new ast_declarator_list($1);
  1106. decl->set_location(yylloc);
  1107. declarator->set_location(yylloc);
  1108. insert_at_tail(& declarator->declarations,
  1109. (struct simple_node *) decl);
  1110. $$ = declarator;
  1111. }
  1112. ;
  1113. switch_statement:
  1114. SWITCH '(' expression ')' compound_statement
  1115. ;
  1116. case_label:
  1117. CASE expression ':'
  1118. | DEFAULT ':'
  1119. ;
  1120. iteration_statement:
  1121. WHILE '(' condition ')' statement_no_new_scope
  1122. {
  1123. $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
  1124. NULL, $3, NULL, $5);
  1125. $$->set_location(yylloc);
  1126. }
  1127. | DO statement WHILE '(' expression ')' ';'
  1128. {
  1129. $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
  1130. NULL, $5, NULL, $2);
  1131. $$->set_location(yylloc);
  1132. }
  1133. | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
  1134. {
  1135. $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
  1136. $3, $4.cond, $4.rest, $6);
  1137. $$->set_location(yylloc);
  1138. }
  1139. ;
  1140. for_init_statement:
  1141. expression_statement
  1142. | declaration_statement
  1143. ;
  1144. conditionopt:
  1145. condition
  1146. | /* empty */
  1147. {
  1148. $$ = NULL;
  1149. }
  1150. ;
  1151. for_rest_statement:
  1152. conditionopt ';'
  1153. {
  1154. $$.cond = $1;
  1155. $$.rest = NULL;
  1156. }
  1157. | conditionopt ';' expression
  1158. {
  1159. $$.cond = $1;
  1160. $$.rest = $3;
  1161. }
  1162. ;
  1163. // Grammar Note: No 'goto'. Gotos are not supported.
  1164. jump_statement:
  1165. CONTINUE ';'
  1166. {
  1167. $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
  1168. $$->set_location(yylloc);
  1169. }
  1170. | BREAK ';'
  1171. {
  1172. $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
  1173. $$->set_location(yylloc);
  1174. }
  1175. | RETURN ';'
  1176. {
  1177. $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
  1178. $$->set_location(yylloc);
  1179. }
  1180. | RETURN expression ';'
  1181. {
  1182. $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
  1183. $$->set_location(yylloc);
  1184. }
  1185. | DISCARD ';' // Fragment shader only.
  1186. {
  1187. $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
  1188. $$->set_location(yylloc);
  1189. }
  1190. ;
  1191. external_declaration:
  1192. function_definition { $$ = $1; }
  1193. | declaration { $$ = $1; }
  1194. ;
  1195. function_definition:
  1196. function_prototype compound_statement_no_new_scope
  1197. {
  1198. $$ = new ast_function_definition();
  1199. $$->set_location(yylloc);
  1200. $$->prototype = $1;
  1201. $$->body = $2;
  1202. }
  1203. ;