PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/V_2_2_1/sdcc/src/SDCC.y

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