PageRenderTime 81ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/sdcc-230/sdcc/src/SDCC.y

#
Happy | 1363 lines | 1234 code | 129 blank | 0 comment | 0 complexity | 07bde2dc71f03aa75097a6843b5a4063 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, GPL-3.0
  1. /*-----------------------------------------------------------------------
  2. SDCC.y - parser definition file for sdcc :
  3. Written By : Sandeep Dutta . sandeep.dutta@usa.net (1997)
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. In other words, you are welcome to use, share and improve this program.
  16. You are forbidden to forbid anyone else to use, share and improve
  17. what you give them. Help stamp out software-hoarding!
  18. -------------------------------------------------------------------------*/
  19. %{
  20. #include <stdio.h>
  21. #include <stdarg.h>
  22. #include <string.h>
  23. #include "SDCCglobl.h"
  24. #include "SDCCsymt.h"
  25. #include "SDCChasht.h"
  26. #include "SDCCval.h"
  27. #include "SDCCmem.h"
  28. #include "SDCCast.h"
  29. #include "port.h"
  30. #include "newalloc.h"
  31. #include "SDCCerr.h"
  32. extern int yyerror (char *);
  33. extern FILE *yyin;
  34. int NestLevel = 0 ; /* current NestLevel */
  35. int stackPtr = 1 ; /* stack pointer */
  36. int xstackPtr = 0 ; /* xstack pointer */
  37. int reentrant = 0 ;
  38. int blockNo = 0 ; /* sequential block number */
  39. int currBlockno=0 ;
  40. extern int yylex();
  41. int yyparse(void);
  42. extern int noLineno ;
  43. char lbuff[1024]; /* local buffer */
  44. /* break & continue stacks */
  45. STACK_DCL(continueStack ,symbol *,MAX_NEST_LEVEL)
  46. STACK_DCL(breakStack ,symbol *,MAX_NEST_LEVEL)
  47. STACK_DCL(forStack ,symbol *,MAX_NEST_LEVEL)
  48. STACK_DCL(swStk ,ast *,MAX_NEST_LEVEL)
  49. STACK_DCL(blockNum,int,MAX_NEST_LEVEL*3)
  50. value *cenum = NULL ; /* current enumeration type chain*/
  51. %}
  52. %expect 6
  53. %union {
  54. symbol *sym ; /* symbol table pointer */
  55. structdef *sdef; /* structure definition */
  56. char yychar[SDCC_NAME_MAX+1];
  57. sym_link *lnk ; /* declarator or specifier */
  58. int yyint; /* integer value returned */
  59. value *val ; /* for integer constant */
  60. initList *ilist; /* initial list */
  61. char *yyinline; /* inlined assembler code */
  62. ast *asts; /* expression tree */
  63. }
  64. %token <yychar> IDENTIFIER TYPE_NAME
  65. %token <val> CONSTANT STRING_LITERAL
  66. %token SIZEOF
  67. %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
  68. %token AND_OP OR_OP
  69. %token <yyint> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
  70. %token <yyint> SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
  71. %token <yyint> XOR_ASSIGN OR_ASSIGN
  72. %token TYPEDEF EXTERN STATIC AUTO REGISTER CODE EEPROM INTERRUPT SFR AT SBIT
  73. %token REENTRANT USING XDATA DATA IDATA PDATA VAR_ARGS CRITICAL NONBANKED BANKED
  74. %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID BIT
  75. %token STRUCT UNION ENUM ELIPSIS RANGE FAR
  76. %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
  77. %token NAKED
  78. %token <yyinline> INLINEASM
  79. %token IFX ADDRESS_OF GET_VALUE_AT_ADDRESS SPIL UNSPIL GETHBIT
  80. %token BITWISEAND UNARYMINUS IPUSH IPOP PCALL ENDFUNCTION JUMPTABLE
  81. %token RRC RLC
  82. %token CAST CALL PARAM NULLOP BLOCK LABEL RECEIVE SEND ARRAYINIT
  83. %type <yyint> Interrupt_storage
  84. %type <sym> identifier declarator declarator2 enumerator_list enumerator
  85. %type <sym> struct_declarator
  86. %type <sym> struct_declarator_list struct_declaration struct_declaration_list
  87. %type <sym> declaration init_declarator_list init_declarator
  88. %type <sym> declaration_list identifier_list parameter_identifier_list
  89. %type <sym> declarator2_using_reentrant while do for
  90. %type <lnk> pointer type_specifier_list type_specifier type_name
  91. %type <lnk> storage_class_specifier struct_or_union_specifier
  92. %type <lnk> declaration_specifiers sfr_reg_bit type_specifier2
  93. %type <lnk> using_reentrant using_reentrant_interrupt enum_specifier
  94. %type <lnk> abstract_declarator abstract_declarator2 unqualified_pointer
  95. %type <val> parameter_type_list parameter_list parameter_declaration opt_assign_expr
  96. %type <sdef> stag opt_stag
  97. %type <asts> primary_expr
  98. %type <asts> postfix_expr unary_expr cast_expr multiplicative_expr
  99. %type <asts> additive_expr shift_expr relational_expr equality_expr
  100. %type <asts> and_expr exclusive_or_expr inclusive_or_expr logical_or_expr
  101. %type <asts> logical_and_expr conditional_expr assignment_expr constant_expr
  102. %type <asts> expr argument_expr_list function_definition expr_opt
  103. %type <asts> statement_list statement labeled_statement compound_statement
  104. %type <asts> expression_statement selection_statement iteration_statement
  105. %type <asts> jump_statement function_body else_statement string_literal
  106. %type <ilist> initializer initializer_list
  107. %type <yyint> unary_operator assignment_operator struct_or_union
  108. %start file
  109. %%
  110. file
  111. : external_definition
  112. | file external_definition
  113. ;
  114. external_definition
  115. : function_definition { blockNo=0;}
  116. | declaration {
  117. if ($1 && $1->type
  118. && IS_FUNC($1->type))
  119. {
  120. /* The only legal storage classes for
  121. * a function prototype (declaration)
  122. * are extern and static. extern is the
  123. * default. Thus, if this function isn't
  124. * explicitly marked static, mark it
  125. * extern.
  126. */
  127. if ($1->etype
  128. && IS_SPEC($1->etype)
  129. && !SPEC_STAT($1->etype))
  130. {
  131. SPEC_EXTR($1->etype) = 1;
  132. }
  133. }
  134. addSymChain ($1);
  135. allocVariables ($1) ;
  136. cleanUpLevel (SymbolTab,1);
  137. }
  138. ;
  139. function_definition
  140. : declarator function_body { /* function type not specified */
  141. /* assume it to be 'int' */
  142. addDecl($1,0,newIntLink());
  143. $$ = createFunction($1,$2);
  144. }
  145. | declaration_specifiers declarator function_body
  146. {
  147. pointerTypes($2->type,copyLinkChain($1));
  148. addDecl($2,0,$1);
  149. $$ = createFunction($2,$3);
  150. }
  151. ;
  152. using_reentrant
  153. : using_reentrant_interrupt
  154. | using_reentrant_interrupt using_reentrant { $$ = mergeSpec($1,$2,"using_reentrant"); }
  155. ;
  156. using_reentrant_interrupt
  157. : USING CONSTANT {
  158. $$ = newLink() ;
  159. $$->class = SPECIFIER ;
  160. SPEC_BNKF($$) = 1;
  161. SPEC_BANK($$) = (int) floatFromVal($2);
  162. }
  163. | REENTRANT { $$ = newLink ();
  164. $$->class = SPECIFIER ;
  165. SPEC_RENT($$) = 1;
  166. }
  167. | CRITICAL { $$ = newLink ();
  168. $$->class = SPECIFIER ;
  169. SPEC_CRTCL($$) = 1;
  170. }
  171. | NAKED { $$ = newLink ();
  172. $$->class = SPECIFIER ;
  173. SPEC_NAKED($$) = 1;
  174. }
  175. | NONBANKED {$$ = newLink ();
  176. $$->class = SPECIFIER ;
  177. SPEC_NONBANKED($$) = 1;
  178. if (SPEC_BANKED($$)) {
  179. werror(W_BANKED_WITH_NONBANKED);
  180. }
  181. }
  182. | BANKED {$$ = newLink ();
  183. $$->class = SPECIFIER ;
  184. SPEC_BANKED($$) = 1;
  185. if (SPEC_NONBANKED($$)) {
  186. werror(W_BANKED_WITH_NONBANKED);
  187. }
  188. if (SPEC_STAT($$)) {
  189. werror(W_BANKED_WITH_STATIC);
  190. }
  191. }
  192. | Interrupt_storage
  193. {
  194. $$ = newLink () ;
  195. $$->class = SPECIFIER ;
  196. SPEC_INTN($$) = $1 ;
  197. SPEC_INTRTN($$) = 1;
  198. }
  199. ;
  200. function_body
  201. : compound_statement
  202. | declaration_list compound_statement
  203. {
  204. werror(E_OLD_STYLE,($1 ? $1->name: "")) ;
  205. exit(1);
  206. }
  207. ;
  208. primary_expr
  209. : identifier { $$ = newAst_VALUE(symbolVal($1)); }
  210. | CONSTANT { $$ = newAst_VALUE($1); }
  211. | string_literal
  212. | '(' expr ')' { $$ = $2 ; }
  213. ;
  214. string_literal
  215. : STRING_LITERAL { $$ = newAst_VALUE($1); }
  216. ;
  217. postfix_expr
  218. : primary_expr
  219. | postfix_expr '[' expr ']' { $$ = newNode ('[', $1, $3) ; }
  220. | postfix_expr '(' ')' { $$ = newNode (CALL,$1,NULL);
  221. $$->left->funcName = 1;}
  222. | postfix_expr '(' argument_expr_list ')'
  223. {
  224. $$ = newNode (CALL,$1,$3) ; $$->left->funcName = 1;
  225. }
  226. | postfix_expr '.' identifier
  227. {
  228. $3 = newSymbol($3->name,NestLevel);
  229. $3->implicit = 1;
  230. $$ = newNode(PTR_OP,newNode('&',$1,NULL),newAst_VALUE(symbolVal($3)));
  231. /* $$ = newNode('.',$1,newAst(EX_VALUE,symbolVal($3))) ; */
  232. }
  233. | postfix_expr PTR_OP identifier
  234. {
  235. $3 = newSymbol($3->name,NestLevel);
  236. $3->implicit = 1;
  237. $$ = newNode(PTR_OP,$1,newAst_VALUE(symbolVal($3)));
  238. }
  239. | postfix_expr INC_OP
  240. { $$ = newNode(INC_OP,$1,NULL);}
  241. | postfix_expr DEC_OP
  242. { $$ = newNode(DEC_OP,$1,NULL); }
  243. ;
  244. argument_expr_list
  245. : assignment_expr
  246. | assignment_expr ',' argument_expr_list { $$ = newNode(PARAM,$1,$3); }
  247. ;
  248. unary_expr
  249. : postfix_expr
  250. | INC_OP unary_expr { $$ = newNode(INC_OP,NULL,$2); }
  251. | DEC_OP unary_expr { $$ = newNode(DEC_OP,NULL,$2); }
  252. | unary_operator cast_expr { $$ = newNode($1,$2,NULL) ; }
  253. | SIZEOF unary_expr { $$ = newNode(SIZEOF,NULL,$2); }
  254. | SIZEOF '(' type_name ')' { $$ = newAst_VALUE(sizeofOp($3)); }
  255. ;
  256. unary_operator
  257. : '&' { $$ = '&' ;}
  258. | '*' { $$ = '*' ;}
  259. | '+' { $$ = '+' ;}
  260. | '-' { $$ = '-' ;}
  261. | '~' { $$ = '~' ;}
  262. | '!' { $$ = '!' ;}
  263. ;
  264. cast_expr
  265. : unary_expr
  266. | '(' type_name ')' cast_expr { $$ = newNode(CAST,newAst_LINK($2),$4); }
  267. ;
  268. multiplicative_expr
  269. : cast_expr
  270. | multiplicative_expr '*' cast_expr { $$ = newNode('*',$1,$3);}
  271. | multiplicative_expr '/' cast_expr { $$ = newNode('/',$1,$3);}
  272. | multiplicative_expr '%' cast_expr { $$ = newNode('%',$1,$3);}
  273. ;
  274. additive_expr
  275. : multiplicative_expr
  276. | additive_expr '+' multiplicative_expr { $$=newNode('+',$1,$3);}
  277. | additive_expr '-' multiplicative_expr { $$=newNode('-',$1,$3);}
  278. ;
  279. shift_expr
  280. : additive_expr
  281. | shift_expr LEFT_OP additive_expr { $$ = newNode(LEFT_OP,$1,$3); }
  282. | shift_expr RIGHT_OP additive_expr { $$ = newNode(RIGHT_OP,$1,$3); }
  283. ;
  284. relational_expr
  285. : shift_expr
  286. | relational_expr '<' shift_expr {
  287. $$ = (port->lt_nge ?
  288. newNode('!',newNode(GE_OP,$1,$3),NULL) :
  289. newNode('<', $1,$3));
  290. }
  291. | relational_expr '>' shift_expr {
  292. $$ = (port->gt_nle ?
  293. newNode('!',newNode(LE_OP,$1,$3),NULL) :
  294. newNode('>',$1,$3));
  295. }
  296. | relational_expr LE_OP shift_expr {
  297. $$ = (port->le_ngt ?
  298. newNode('!', newNode('>', $1 , $3 ), NULL) :
  299. newNode(LE_OP,$1,$3));
  300. }
  301. | relational_expr GE_OP shift_expr {
  302. $$ = (port->ge_nlt ?
  303. newNode('!', newNode('<', $1 , $3 ), NULL) :
  304. newNode(GE_OP,$1,$3));
  305. }
  306. ;
  307. equality_expr
  308. : relational_expr
  309. | equality_expr EQ_OP relational_expr {
  310. $$ = (port->eq_nne ?
  311. newNode('!',newNode(NE_OP,$1,$3),NULL) :
  312. newNode(EQ_OP,$1,$3));
  313. }
  314. | equality_expr NE_OP relational_expr {
  315. $$ = (port->ne_neq ?
  316. newNode('!', newNode(EQ_OP,$1,$3), NULL) :
  317. newNode(NE_OP,$1,$3));
  318. }
  319. ;
  320. and_expr
  321. : equality_expr
  322. | and_expr '&' equality_expr { $$ = newNode('&',$1,$3);}
  323. ;
  324. exclusive_or_expr
  325. : and_expr
  326. | exclusive_or_expr '^' and_expr { $$ = newNode('^',$1,$3);}
  327. ;
  328. inclusive_or_expr
  329. : exclusive_or_expr
  330. | inclusive_or_expr '|' exclusive_or_expr { $$ = newNode('|',$1,$3);}
  331. ;
  332. logical_and_expr
  333. : inclusive_or_expr
  334. | logical_and_expr AND_OP inclusive_or_expr
  335. { $$ = newNode(AND_OP,$1,$3);}
  336. ;
  337. logical_or_expr
  338. : logical_and_expr
  339. | logical_or_expr OR_OP logical_and_expr
  340. { $$ = newNode(OR_OP,$1,$3); }
  341. ;
  342. conditional_expr
  343. : logical_or_expr
  344. | logical_or_expr '?' logical_or_expr ':' conditional_expr
  345. {
  346. $$ = newNode(':',$3,$5) ;
  347. $$ = newNode('?',$1,$$) ;
  348. }
  349. ;
  350. assignment_expr
  351. : conditional_expr
  352. | unary_expr assignment_operator assignment_expr
  353. {
  354. switch ($2) {
  355. case '=':
  356. $$ = newNode($2,$1,$3);
  357. break;
  358. case MUL_ASSIGN:
  359. $$ = newNode('=',$1,newNode('*',copyAst($1),$3));
  360. break;
  361. case DIV_ASSIGN:
  362. $$ = newNode('=',$1,newNode('/',copyAst($1),$3));
  363. break;
  364. case MOD_ASSIGN:
  365. $$ = newNode('=',$1,newNode('%',copyAst($1),$3));
  366. break;
  367. case ADD_ASSIGN:
  368. $$ = newNode('=',$1,newNode('+',copyAst($1),$3));
  369. break;
  370. case SUB_ASSIGN:
  371. $$ = newNode('=',$1,newNode('-',copyAst($1),$3));
  372. break;
  373. case LEFT_ASSIGN:
  374. $$ = newNode('=',$1,newNode(LEFT_OP,copyAst($1),$3));
  375. break;
  376. case RIGHT_ASSIGN:
  377. $$ = newNode('=',$1,newNode(RIGHT_OP,copyAst($1),$3));
  378. break;
  379. case AND_ASSIGN:
  380. $$ = newNode('=',$1,newNode('&',copyAst($1),$3));
  381. break;
  382. case XOR_ASSIGN:
  383. $$ = newNode('=',$1,newNode('^',copyAst($1),$3));
  384. break;
  385. case OR_ASSIGN:
  386. $$ = newNode('=',$1,newNode('|',copyAst($1),$3));
  387. break;
  388. default :
  389. $$ = NULL;
  390. }
  391. }
  392. ;
  393. assignment_operator
  394. : '=' { $$ = '=' ;}
  395. | MUL_ASSIGN
  396. | DIV_ASSIGN
  397. | MOD_ASSIGN
  398. | ADD_ASSIGN
  399. | SUB_ASSIGN
  400. | LEFT_ASSIGN
  401. | RIGHT_ASSIGN
  402. | AND_ASSIGN
  403. | XOR_ASSIGN
  404. | OR_ASSIGN
  405. ;
  406. expr
  407. : assignment_expr
  408. | expr ',' assignment_expr { $$ = newNode(',',$1,$3);}
  409. ;
  410. constant_expr
  411. : conditional_expr
  412. ;
  413. declaration
  414. : declaration_specifiers ';' { $$ = NULL ; }
  415. | declaration_specifiers init_declarator_list ';'
  416. {
  417. /* add the specifier list to the id */
  418. symbol *sym , *sym1;
  419. for (sym1 = sym = reverseSyms($2);sym != NULL;sym = sym->next) {
  420. sym_link *lnk = copyLinkChain($1);
  421. /* do the pointer stuff */
  422. pointerTypes(sym->type,lnk);
  423. addDecl (sym,0,lnk) ;
  424. }
  425. $$ = sym1 ;
  426. }
  427. ;
  428. declaration_specifiers
  429. : storage_class_specifier { $$ = $1; }
  430. | storage_class_specifier declaration_specifiers {
  431. /* if the decl $2 is not a specifier */
  432. /* find the spec and replace it */
  433. if ( !IS_SPEC($2)) {
  434. sym_link *lnk = $2 ;
  435. while (lnk && !IS_SPEC(lnk->next))
  436. lnk = lnk->next;
  437. lnk->next = mergeSpec($1,lnk->next, yytext);
  438. $$ = $2 ;
  439. }
  440. else
  441. $$ = mergeSpec($1,$2, yytext);
  442. }
  443. | type_specifier { $$ = $1; }
  444. | type_specifier declaration_specifiers {
  445. /* if the decl $2 is not a specifier */
  446. /* find the spec and replace it */
  447. if ( !IS_SPEC($2)) {
  448. sym_link *lnk = $2 ;
  449. while (lnk && !IS_SPEC(lnk->next))
  450. lnk = lnk->next;
  451. lnk->next = mergeSpec($1,lnk->next, yytext);
  452. $$ = $2 ;
  453. }
  454. else
  455. $$ = mergeSpec($1,$2, yytext);
  456. }
  457. ;
  458. init_declarator_list
  459. : init_declarator
  460. | init_declarator_list ',' init_declarator { $3->next = $1 ; $$ = $3;}
  461. ;
  462. init_declarator
  463. : declarator { $1->ival = NULL ; }
  464. | declarator '=' initializer { $1->ival = $3 ; }
  465. ;
  466. storage_class_specifier
  467. : TYPEDEF {
  468. $$ = newLink () ;
  469. $$->class = SPECIFIER ;
  470. SPEC_TYPEDEF($$) = 1 ;
  471. }
  472. | EXTERN {
  473. $$ = newLink();
  474. $$->class = SPECIFIER ;
  475. SPEC_EXTR($$) = 1 ;
  476. }
  477. | STATIC {
  478. $$ = newLink ();
  479. $$->class = SPECIFIER ;
  480. SPEC_STAT($$) = 1 ;
  481. }
  482. | AUTO {
  483. $$ = newLink () ;
  484. $$->class = SPECIFIER ;
  485. SPEC_SCLS($$) = S_AUTO ;
  486. }
  487. | REGISTER {
  488. $$ = newLink ();
  489. $$->class = SPECIFIER ;
  490. SPEC_SCLS($$) = S_REGISTER ;
  491. }
  492. ;
  493. Interrupt_storage
  494. : INTERRUPT CONSTANT { $$ = (int) floatFromVal($2) ; }
  495. ;
  496. type_specifier
  497. : type_specifier2
  498. | type_specifier2 AT constant_expr
  499. {
  500. /* add this to the storage class specifier */
  501. SPEC_ABSA($1) = 1; /* set the absolute addr flag */
  502. /* now get the abs addr from value */
  503. SPEC_ADDR($1) = (int) floatFromVal(constExprValue($3,TRUE)) ;
  504. }
  505. ;
  506. type_specifier2
  507. : CHAR {
  508. $$=newLink();
  509. $$->class = SPECIFIER ;
  510. SPEC_NOUN($$) = V_CHAR ;
  511. }
  512. | SHORT {
  513. $$=newLink();
  514. $$->class = SPECIFIER ;
  515. $$->select.s._short = 1 ;
  516. }
  517. | INT {
  518. $$=newLink();
  519. $$->class = SPECIFIER ;
  520. SPEC_NOUN($$) = V_INT ;
  521. }
  522. | LONG {
  523. $$=newLink();
  524. $$->class = SPECIFIER ;
  525. SPEC_LONG($$) = 1 ;
  526. }
  527. | SIGNED {
  528. $$=newLink();
  529. $$->class = SPECIFIER ;
  530. $$->select.s._signed = 1;
  531. }
  532. | UNSIGNED {
  533. $$=newLink();
  534. $$->class = SPECIFIER ;
  535. SPEC_USIGN($$) = 1 ;
  536. }
  537. | VOID {
  538. $$=newLink();
  539. $$->class = SPECIFIER ;
  540. SPEC_NOUN($$) = V_VOID ;
  541. }
  542. | CONST {
  543. $$=newLink();
  544. $$->class = SPECIFIER ;
  545. SPEC_CONST($$) = 1;
  546. }
  547. | VOLATILE {
  548. $$=newLink();
  549. $$->class = SPECIFIER ;
  550. SPEC_VOLATILE($$) = 1 ;
  551. }
  552. | FLOAT {
  553. $$=newLink();
  554. SPEC_NOUN($$) = V_FLOAT;
  555. $$->class = SPECIFIER ;
  556. }
  557. | XDATA {
  558. $$ = newLink ();
  559. $$->class = SPECIFIER ;
  560. SPEC_SCLS($$) = S_XDATA ;
  561. }
  562. | CODE {
  563. $$ = newLink () ;
  564. $$->class = SPECIFIER ;
  565. SPEC_SCLS($$) = S_CODE ;
  566. }
  567. | EEPROM {
  568. $$ = newLink () ;
  569. $$->class = SPECIFIER ;
  570. SPEC_SCLS($$) = S_EEPROM ;
  571. }
  572. | DATA {
  573. $$ = newLink ();
  574. $$->class = SPECIFIER ;
  575. SPEC_SCLS($$) = S_DATA ;
  576. }
  577. | IDATA {
  578. $$ = newLink ();
  579. $$->class = SPECIFIER ;
  580. SPEC_SCLS($$) = S_IDATA ;
  581. }
  582. | PDATA {
  583. $$ = newLink ();
  584. $$->class = SPECIFIER ;
  585. SPEC_SCLS($$) = S_PDATA ;
  586. }
  587. | BIT {
  588. $$=newLink();
  589. $$->class = SPECIFIER ;
  590. SPEC_NOUN($$) = V_BIT ;
  591. SPEC_SCLS($$) = S_BIT ;
  592. SPEC_BLEN($$) = 1;
  593. SPEC_BSTR($$) = 0;
  594. }
  595. | struct_or_union_specifier
  596. | enum_specifier {
  597. cenum = NULL ;
  598. $$ = $1 ;
  599. }
  600. | TYPE_NAME
  601. {
  602. symbol *sym;
  603. sym_link *p ;
  604. sym = findSym(TypedefTab,NULL,$1) ;
  605. $$ = p = copyLinkChain(sym->type);
  606. SPEC_TYPEDEF(getSpec(p)) = 0;
  607. }
  608. | sfr_reg_bit
  609. ;
  610. sfr_reg_bit
  611. : SBIT {
  612. $$ = newLink() ;
  613. $$->class = SPECIFIER ;
  614. SPEC_NOUN($$) = V_SBIT;
  615. SPEC_SCLS($$) = S_SBIT;
  616. }
  617. | SFR {
  618. $$ = newLink() ;
  619. $$->class = SPECIFIER ;
  620. SPEC_NOUN($$) = V_CHAR;
  621. SPEC_SCLS($$) = S_SFR ;
  622. SPEC_USIGN($$) = 1 ;
  623. }
  624. ;
  625. struct_or_union_specifier
  626. : struct_or_union opt_stag '{' struct_declaration_list '}'
  627. {
  628. structdef *sdef ;
  629. /* Create a structdef */
  630. sdef = $2 ;
  631. sdef->fields = reverseSyms($4) ; /* link the fields */
  632. sdef->size = compStructSize($1,sdef); /* update size of */
  633. /* Create the specifier */
  634. $$ = newLink () ;
  635. $$->class = SPECIFIER ;
  636. SPEC_NOUN($$) = V_STRUCT;
  637. SPEC_STRUCT($$)= sdef ;
  638. }
  639. | struct_or_union stag
  640. {
  641. $$ = newLink() ;
  642. $$->class = SPECIFIER ;
  643. SPEC_NOUN($$) = V_STRUCT;
  644. SPEC_STRUCT($$) = $2 ;
  645. }
  646. ;
  647. struct_or_union
  648. : STRUCT { $$ = STRUCT ; }
  649. | UNION { $$ = UNION ; }
  650. ;
  651. opt_stag
  652. : stag
  653. | { /* synthesize a name add to structtable */
  654. $$ = newStruct(genSymName(NestLevel)) ;
  655. $$->level = NestLevel ;
  656. addSym (StructTab, $$, $$->tag,$$->level,currBlockno, 0);
  657. };
  658. stag
  659. : identifier { /* add name to structure table */
  660. $$ = findSymWithBlock (StructTab,$1,currBlockno);
  661. if (! $$ ) {
  662. $$ = newStruct($1->name) ;
  663. $$->level = NestLevel ;
  664. addSym (StructTab, $$, $$->tag,$$->level,currBlockno,0);
  665. }
  666. };
  667. struct_declaration_list
  668. : struct_declaration
  669. | struct_declaration_list struct_declaration
  670. {
  671. symbol *sym = $2;
  672. /* go to the end of the chain */
  673. while (sym->next) sym = sym->next;
  674. sym->next = $1 ;
  675. $$ = $2;
  676. }
  677. ;
  678. struct_declaration
  679. : type_specifier_list struct_declarator_list ';'
  680. {
  681. /* add this type to all the symbols */
  682. symbol *sym ;
  683. for ( sym = $2 ; sym != NULL ; sym = sym->next ) {
  684. /* make the symbol one level up */
  685. sym->level-- ;
  686. pointerTypes(sym->type,copyLinkChain($1));
  687. if (!sym->type) {
  688. sym->type = copyLinkChain($1);
  689. sym->etype = getSpec(sym->type);
  690. /* make sure the type is complete and sane */
  691. checkTypeSanity(sym->etype, sym->name);
  692. }
  693. else
  694. addDecl (sym,0,cloneSpec($1));
  695. }
  696. $$ = $2;
  697. }
  698. ;
  699. struct_declarator_list
  700. : struct_declarator
  701. | struct_declarator_list ',' struct_declarator
  702. {
  703. $3->next = $1 ;
  704. $$ = $3 ;
  705. }
  706. ;
  707. struct_declarator
  708. : declarator
  709. | ':' constant_expr {
  710. $$ = newSymbol (genSymName(NestLevel),NestLevel) ;
  711. $$->bitVar = (int) floatFromVal(constExprValue($2,TRUE));
  712. }
  713. | declarator ':' constant_expr
  714. {
  715. $1->bitVar = (int) floatFromVal(constExprValue($3,TRUE));
  716. }
  717. ;
  718. enum_specifier
  719. : ENUM '{' enumerator_list '}' {
  720. addSymChain ($3);
  721. allocVariables(reverseSyms($3)) ;
  722. $$ = copyLinkChain(cenum->type);
  723. }
  724. | ENUM identifier '{' enumerator_list '}' {
  725. symbol *csym ;
  726. $2->type = copyLinkChain(cenum->type);
  727. $2->etype = getSpec($2->type);
  728. /* add this to the enumerator table */
  729. if (!(csym=findSym(enumTab,$2,$2->name)) &&
  730. (csym && csym->level == $2->level))
  731. werror(E_DUPLICATE_TYPEDEF,csym->name);
  732. addSym ( enumTab,$2,$2->name,$2->level,$2->block, 0);
  733. addSymChain ($4);
  734. allocVariables (reverseSyms($4));
  735. $$ = copyLinkChain(cenum->type);
  736. SPEC_SCLS(getSpec($$)) = 0 ;
  737. }
  738. | ENUM identifier {
  739. symbol *csym ;
  740. /* check the enumerator table */
  741. if ((csym = findSym(enumTab,$2,$2->name)))
  742. $$ = copyLinkChain(csym->type);
  743. else {
  744. $$ = newLink() ;
  745. $$->class = SPECIFIER ;
  746. SPEC_NOUN($$) = V_INT ;
  747. }
  748. SPEC_SCLS(getSpec($$)) = 0 ;
  749. }
  750. ;
  751. enumerator_list
  752. : enumerator
  753. | enumerator_list ',' {
  754. }
  755. | enumerator_list ',' enumerator {
  756. $3->next = $1 ;
  757. $$ = $3 ;
  758. }
  759. ;
  760. enumerator
  761. : identifier opt_assign_expr {
  762. /* make the symbol one level up */
  763. $1->level-- ;
  764. $1->type = copyLinkChain($2->type);
  765. $1->etype= getSpec($1->type);
  766. SPEC_ENUM($1->etype) = 1;
  767. $$ = $1 ;
  768. }
  769. ;
  770. opt_assign_expr
  771. : '=' constant_expr {
  772. value *val ;
  773. val = constExprValue($2,TRUE);
  774. $$ = cenum = val ;
  775. }
  776. | {
  777. if (cenum) {
  778. sprintf(lbuff,"%d",(int) floatFromVal(cenum)+1);
  779. $$ = cenum = constVal(lbuff);
  780. }
  781. else {
  782. sprintf(lbuff,"%d",0);
  783. $$ = cenum = constVal(lbuff);
  784. }
  785. }
  786. ;
  787. declarator
  788. : declarator2_using_reentrant { $$ = $1; }
  789. | pointer declarator2_using_reentrant
  790. {
  791. addDecl ($2,0,reverseLink($1));
  792. $$ = $2 ;
  793. }
  794. ;
  795. declarator2_using_reentrant
  796. : declarator2 { $$ = $1 ; }
  797. | declarator2 using_reentrant { addDecl ($1,0,$2); }
  798. ;
  799. declarator2
  800. : identifier
  801. | '(' declarator ')' { $$ = $2; }
  802. | declarator2 '[' ']'
  803. {
  804. sym_link *p;
  805. p = newLink ();
  806. DCL_TYPE(p) = ARRAY ;
  807. DCL_ELEM(p) = 0 ;
  808. addDecl($1,0,p);
  809. }
  810. | declarator2 '[' constant_expr ']'
  811. {
  812. sym_link *p ;
  813. value *tval;
  814. p = (tval = constExprValue($3,TRUE))->etype;
  815. /* if it is not a constant then Error */
  816. if ( SPEC_SCLS(p) != S_LITERAL)
  817. werror(E_CONST_EXPECTED) ;
  818. else {
  819. p = newLink ();
  820. DCL_TYPE(p) = ARRAY ;
  821. DCL_ELEM(p) = (int) floatFromVal(tval) ;
  822. addDecl($1,0,p);
  823. }
  824. }
  825. | declarator2 '(' ')' { addDecl ($1,FUNCTION,NULL) ; }
  826. | declarator2 '(' { NestLevel++ ; currBlockno++; } parameter_type_list ')'
  827. {
  828. addDecl ($1,FUNCTION,NULL) ;
  829. $1->hasVargs = IS_VARG($4);
  830. $1->args = reverseVal($4) ;
  831. /* nest level was incremented to take care of the parms */
  832. NestLevel-- ;
  833. currBlockno--;
  834. $$ = $1;
  835. }
  836. | declarator2 '(' parameter_identifier_list ')'
  837. {
  838. werror(E_OLD_STYLE,$1->name) ;
  839. /* assume it returns an int */
  840. $1->type = $1->etype = newIntLink();
  841. $$ = $1 ;
  842. }
  843. ;
  844. pointer
  845. : unqualified_pointer { $$ = $1 ;}
  846. | unqualified_pointer type_specifier_list
  847. {
  848. $$ = $1 ;
  849. DCL_TSPEC($1) = $2;
  850. }
  851. | unqualified_pointer pointer
  852. {
  853. $$ = $1 ;
  854. $$->next = $2 ;
  855. }
  856. | unqualified_pointer type_specifier_list pointer
  857. {
  858. $$ = $1 ;
  859. if (IS_SPEC($2) && DCL_TYPE($3) == UPOINTER) {
  860. DCL_PTR_CONST($1) = SPEC_CONST($2);
  861. DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2);
  862. switch (SPEC_SCLS($2)) {
  863. case S_XDATA:
  864. DCL_TYPE($3) = FPOINTER;
  865. break;
  866. case S_IDATA:
  867. DCL_TYPE($3) = IPOINTER ;
  868. break;
  869. case S_PDATA:
  870. DCL_TYPE($3) = PPOINTER ;
  871. break;
  872. case S_DATA:
  873. DCL_TYPE($3) = POINTER ;
  874. break;
  875. case S_CODE:
  876. DCL_PTR_CONST($3) = 1;
  877. DCL_TYPE($3) = CPOINTER ;
  878. break;
  879. case S_EEPROM:
  880. DCL_TYPE($3) = EEPPOINTER;
  881. break;
  882. default:
  883. werror(W_PTR_TYPE_INVALID);
  884. }
  885. }
  886. else
  887. werror (W_PTR_TYPE_INVALID);
  888. $$->next = $3 ;
  889. }
  890. ;
  891. unqualified_pointer
  892. : '*'
  893. {
  894. $$ = newLink();
  895. DCL_TYPE($$)=UPOINTER;
  896. }
  897. ;
  898. type_specifier_list
  899. : type_specifier
  900. | type_specifier_list type_specifier { $$ = mergeSpec ($1,$2, "type_specifier_list"); }
  901. ;
  902. parameter_identifier_list
  903. : identifier_list
  904. | identifier_list ',' ELIPSIS
  905. ;
  906. identifier_list
  907. : identifier
  908. | identifier_list ',' identifier
  909. {
  910. $3->next = $1;
  911. $$ = $3 ;
  912. }
  913. ;
  914. parameter_type_list
  915. : parameter_list
  916. | parameter_list ',' VAR_ARGS { $1->vArgs = 1;}
  917. ;
  918. parameter_list
  919. : parameter_declaration
  920. | parameter_list ',' parameter_declaration
  921. {
  922. $3->next = $1 ;
  923. $$ = $3 ;
  924. }
  925. ;
  926. parameter_declaration
  927. : type_specifier_list declarator
  928. {
  929. symbol *loop ;
  930. pointerTypes($2->type,$1);
  931. addDecl ($2,0,$1);
  932. for (loop=$2;loop;loop->_isparm=1,loop=loop->next);
  933. addSymChain ($2);
  934. $$ = symbolVal($2);
  935. }
  936. | type_name {
  937. $$ = newValue() ;
  938. $$->type = $1;
  939. $$->etype = getSpec($$->type);
  940. }
  941. ;
  942. type_name
  943. : type_specifier_list { $$ = $1 ;}
  944. | type_specifier_list abstract_declarator
  945. {
  946. /* go to the end of the list */
  947. sym_link *p;
  948. pointerTypes($2,$1);
  949. for ( p = $2 ; p->next ; p=p->next);
  950. p->next = $1 ;
  951. $$ = $2 ;
  952. }
  953. ;
  954. abstract_declarator
  955. : pointer { $$ = reverseLink($1); }
  956. | abstract_declarator2
  957. | pointer abstract_declarator2 { $1 = reverseLink($1); $1->next = $2 ; $$ = $1;}
  958. ;
  959. abstract_declarator2
  960. : '(' abstract_declarator ')' { $$ = $2 ; }
  961. | '[' ']' {
  962. $$ = newLink ();
  963. DCL_TYPE($$) = ARRAY ;
  964. DCL_ELEM($$) = 0 ;
  965. }
  966. | '[' constant_expr ']' {
  967. value *val ;
  968. $$ = newLink ();
  969. DCL_TYPE($$) = ARRAY ;
  970. DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($2,TRUE));
  971. }
  972. | abstract_declarator2 '[' ']' {
  973. $$ = newLink ();
  974. DCL_TYPE($$) = ARRAY ;
  975. DCL_ELEM($$) = 0 ;
  976. $$->next = $1 ;
  977. }
  978. | abstract_declarator2 '[' constant_expr ']'
  979. {
  980. value *val ;
  981. $$ = newLink ();
  982. DCL_TYPE($$) = ARRAY ;
  983. DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($3,TRUE));
  984. $$->next = $1 ;
  985. }
  986. | '(' ')' { $$ = NULL;}
  987. | '(' parameter_type_list ')' { $$ = NULL;}
  988. | abstract_declarator2 '(' ')' {
  989. // $1 must be a pointer to a function
  990. sym_link *p=newLink();
  991. DCL_TYPE(p) = FUNCTION;
  992. $1->next=p;
  993. }
  994. | abstract_declarator2 '(' parameter_type_list ')' {
  995. if (!IS_VOID($3->type)) {
  996. // this is nonsense, so let's just burp something
  997. werror(E_TOO_FEW_PARMS);
  998. } else {
  999. // $1 must be a pointer to a function
  1000. sym_link *p=newLink();
  1001. DCL_TYPE(p) = FUNCTION;
  1002. $1->next=p;
  1003. }
  1004. }
  1005. initializer
  1006. : assignment_expr { $$ = newiList(INIT_NODE,$1); }
  1007. | '{' initializer_list '}' { $$ = newiList(INIT_DEEP,revinit($2)); }
  1008. | '{' initializer_list ',' '}' { $$ = newiList(INIT_DEEP,revinit($2)); }
  1009. ;
  1010. initializer_list
  1011. : initializer
  1012. | initializer_list ',' initializer { $3->next = $1; $$ = $3; }
  1013. ;
  1014. statement
  1015. : labeled_statement
  1016. | compound_statement
  1017. | expression_statement
  1018. | selection_statement
  1019. | iteration_statement
  1020. | jump_statement
  1021. | INLINEASM ';' {
  1022. ast *ex = newNode(INLINEASM,NULL,NULL);
  1023. ex->values.inlineasm = Safe_calloc(1,strlen($1)+1);
  1024. strcpy(ex->values.inlineasm,$1);
  1025. $$ = ex;
  1026. }
  1027. ;
  1028. labeled_statement
  1029. : identifier ':' statement { $$ = createLabel($1,$3); }
  1030. | CASE constant_expr ':' statement { $$ = createCase(STACK_PEEK(swStk),$2,$4); }
  1031. | DEFAULT ':' statement { $$ = createDefault(STACK_PEEK(swStk),$3); }
  1032. ;
  1033. start_block : '{' { STACK_PUSH(blockNum,currBlockno); currBlockno = ++blockNo ; }
  1034. ;
  1035. end_block : '}' { currBlockno = STACK_POP(blockNum); }
  1036. ;
  1037. compound_statement
  1038. : start_block end_block { $$ = createBlock(NULL,NULL); }
  1039. | start_block statement_list end_block { $$ = createBlock(NULL,$2) ; }
  1040. | start_block
  1041. declaration_list { addSymChain($2); }
  1042. end_block { $$ = createBlock($2,NULL) ; }
  1043. | start_block
  1044. declaration_list { addSymChain ($2); }
  1045. statement_list
  1046. end_block {$$ = createBlock($2,$4) ; }
  1047. | error ';' { $$ = NULL ; }
  1048. ;
  1049. declaration_list
  1050. : declaration
  1051. {
  1052. /* if this is typedef declare it immediately */
  1053. if ( $1 && IS_TYPEDEF($1->etype)) {
  1054. allocVariables ($1);
  1055. $$ = NULL ;
  1056. }
  1057. else
  1058. $$ = $1 ;
  1059. }
  1060. | declaration_list declaration
  1061. {
  1062. symbol *sym;
  1063. /* if this is a typedef */
  1064. if ($2 && IS_TYPEDEF($2->etype)) {
  1065. allocVariables ($2);
  1066. $$ = $1 ;
  1067. }
  1068. else {
  1069. /* get to the end of the previous decl */
  1070. if ( $1 ) {
  1071. $$ = sym = $1 ;
  1072. while (sym->next)
  1073. sym = sym->next ;
  1074. sym->next = $2;
  1075. }
  1076. else
  1077. $$ = $2 ;
  1078. }
  1079. }
  1080. ;
  1081. statement_list
  1082. : statement
  1083. | statement_list statement { $$ = newNode(NULLOP,$1,$2) ;}
  1084. ;
  1085. expression_statement
  1086. : ';' { $$ = NULL;}
  1087. | expr ';'
  1088. ;
  1089. else_statement
  1090. : ELSE statement { $$ = $2 ; }
  1091. | { $$ = NULL;}
  1092. ;
  1093. selection_statement
  1094. : IF '(' expr ')' statement else_statement { noLineno++ ; $$ = createIf ($3, $5, $6 ); noLineno--;}
  1095. | SWITCH '(' expr ')' {
  1096. ast *ex ;
  1097. static int swLabel = 0 ;
  1098. /* create a node for expression */
  1099. ex = newNode(SWITCH,$3,NULL);
  1100. STACK_PUSH(swStk,ex); /* save it in the stack */
  1101. ex->values.switchVals.swNum = swLabel ;
  1102. /* now create the label */
  1103. sprintf(lbuff,"_swBrk_%d",swLabel++);
  1104. $<sym>$ = newSymbol(lbuff,NestLevel);
  1105. /* put label in the break stack */
  1106. STACK_PUSH(breakStack,$<sym>$);
  1107. }
  1108. statement {
  1109. /* get back the switch form the stack */
  1110. $$ = STACK_POP(swStk) ;
  1111. $$->right = newNode (NULLOP,$6,createLabel($<sym>5,NULL));
  1112. STACK_POP(breakStack);
  1113. }
  1114. ;
  1115. while : WHILE { /* create and push the continue , break & body labels */
  1116. static int Lblnum = 0 ;
  1117. /* continue */
  1118. sprintf (lbuff,"_whilecontinue_%d",Lblnum);
  1119. STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
  1120. /* break */
  1121. sprintf (lbuff,"_whilebreak_%d",Lblnum);
  1122. STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
  1123. /* body */
  1124. sprintf (lbuff,"_whilebody_%d",Lblnum++);
  1125. $$ = newSymbol(lbuff,NestLevel);
  1126. }
  1127. do : DO { /* create and push the continue , break & body Labels */
  1128. static int Lblnum = 0 ;
  1129. /* continue */
  1130. sprintf(lbuff,"_docontinue_%d",Lblnum);
  1131. STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
  1132. /* break */
  1133. sprintf (lbuff,"_dobreak_%d",Lblnum);
  1134. STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
  1135. /* do body */
  1136. sprintf (lbuff,"_dobody_%d",Lblnum++);
  1137. $$ = newSymbol (lbuff,NestLevel);
  1138. }
  1139. for : FOR { /* create & push continue, break & body labels */
  1140. static int Lblnum = 0 ;
  1141. /* continue */
  1142. sprintf (lbuff,"_forcontinue_%d",Lblnum);
  1143. STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel));
  1144. /* break */
  1145. sprintf (lbuff,"_forbreak_%d",Lblnum);
  1146. STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel));
  1147. /* body */
  1148. sprintf (lbuff,"_forbody_%d",Lblnum);
  1149. $$ = newSymbol(lbuff,NestLevel);
  1150. /* condition */
  1151. sprintf (lbuff,"_forcond_%d",Lblnum++);
  1152. STACK_PUSH(forStack,newSymbol(lbuff,NestLevel));
  1153. }
  1154. iteration_statement
  1155. : while '(' expr ')' statement
  1156. {
  1157. noLineno++ ;
  1158. $$ = createWhile ( $1, STACK_POP(continueStack),
  1159. STACK_POP(breakStack), $3, $5 );
  1160. $$->lineno = $1->lineDef ;
  1161. noLineno-- ;
  1162. }
  1163. | do statement WHILE '(' expr ')' ';'
  1164. {
  1165. noLineno++ ;
  1166. $$ = createDo ( $1 , STACK_POP(continueStack),
  1167. STACK_POP(breakStack), $5, $2);
  1168. $$->lineno = $1->lineDef ;
  1169. noLineno-- ;
  1170. }
  1171. | for '(' expr_opt ';' expr_opt ';' expr_opt ')' statement
  1172. {
  1173. noLineno++ ;
  1174. /* if break or continue statement present
  1175. then create a general case loop */
  1176. if (STACK_PEEK(continueStack)->isref ||
  1177. STACK_PEEK(breakStack)->isref) {
  1178. $$ = createFor ($1, STACK_POP(continueStack),
  1179. STACK_POP(breakStack) ,
  1180. STACK_POP(forStack) ,
  1181. $3 , $5 , $7, $9 );
  1182. } else {
  1183. $$ = newNode(FOR,$9,NULL);
  1184. AST_FOR($$,trueLabel) = $1;
  1185. AST_FOR($$,continueLabel) = STACK_POP(continueStack);
  1186. AST_FOR($$,falseLabel) = STACK_POP(breakStack);
  1187. AST_FOR($$,condLabel) = STACK_POP(forStack) ;
  1188. AST_FOR($$,initExpr) = $3;
  1189. AST_FOR($$,condExpr) = $5;
  1190. AST_FOR($$,loopExpr) = $7;
  1191. }
  1192. noLineno-- ;
  1193. }
  1194. ;
  1195. expr_opt
  1196. : { $$ = NULL ; }
  1197. | expr
  1198. ;
  1199. jump_statement
  1200. : GOTO identifier ';' {
  1201. $2->islbl = 1;
  1202. $$ = newAst_VALUE(symbolVal($2));
  1203. $$ = newNode(GOTO,$$,NULL);
  1204. }
  1205. | CONTINUE ';' {
  1206. /* make sure continue is in context */
  1207. if (STACK_PEEK(continueStack) == NULL) {
  1208. werror(E_BREAK_CONTEXT);
  1209. $$ = NULL;
  1210. }
  1211. else {
  1212. $$ = newAst_VALUE(symbolVal(STACK_PEEK(continueStack)));
  1213. $$ = newNode(GOTO,$$,NULL);
  1214. /* mark the continue label as referenced */
  1215. STACK_PEEK(continueStack)->isref = 1;
  1216. }
  1217. }
  1218. | BREAK ';' {
  1219. if (STACK_PEEK(breakStack) == NULL) {
  1220. werror(E_BREAK_CONTEXT);
  1221. $$ = NULL;
  1222. } else {
  1223. $$ = newAst_VALUE(symbolVal(STACK_PEEK(breakStack)));
  1224. $$ = newNode(GOTO,$$,NULL);
  1225. STACK_PEEK(breakStack)->isref = 1;
  1226. }
  1227. }
  1228. | RETURN ';' { $$ = newNode(RETURN,NULL,NULL) ; }
  1229. | RETURN expr ';' { $$ = newNode(RETURN,NULL,$2) ; }
  1230. ;
  1231. identifier
  1232. : IDENTIFIER { $$ = newSymbol ($1,NestLevel) ; }
  1233. ;
  1234. %%