/* $VER: vbcc (parse_expr.c) V0.8 */ #include "vbcc_cpp.h"#include "vbc.h" static char FILE_[]=__FILE__; np new_node(void){ np p=mymalloc(NODES); p->flags=0; p->lvalue=0; p->sidefx=0; p->ntyp=0; p->left=0; p->right=0; p->alist=0; p->identifier=0; p->o.flags=0; return p;} np expression(void)/* Komma-Ausdruecke */{ np left,right,new; left=assignment_expression(); if(!left->flags) return 0; killsp(); while(ctok->type==COMMA){#ifdef HAVE_MISRA/* removed */#endif next_token(); killsp(); right=assignment_expression(); new=new_node(); new->left=left; new->right=right; new->ntyp=0; new->flags=KOMMA; left=new; killsp(); } return left;}np assignment_expression(void)/* Zuweisungsausdruecke */{ np left,new;int c=ASSIGNOP,op; left=conditional_expression(); killsp(); switch(ctok->type){ case ASGN: c=ASSIGN;break; case ASSTAR: op=MULT;break; case ASSLASH: op=DIV;break; case ASPCT: op=MOD;break; case ASPLUS: op=ADD;break; case ASMINUS: op=SUB;break; case ASAND: op=AND;break; case ASCIRC: op=XOR;break; case ASOR: op=OR;break; case ASLSH: op=LSHIFT;break; case ASRSH: op=RSHIFT;break; default: return left; } next_token(); new=new_node(); new->left=left; new->ntyp=0; if(c==ASSIGN){ new->right=assignment_expression(); new->flags=ASSIGN; }else{ /* ASSIGNOP(a,b)->ASSIGN(a,OP(a,b)) */ new->flags=ASSIGNOP; /* nur um zum Merken, dass nur einmal */ /* ausgewertet werden darf */ new->right=new_node(); new->right->left=left; new->right->right=assignment_expression(); new->right->ntyp=0; new->right->flags=op; } return new;}np conditional_expression(void)/* Erledigt ? : */{ np left,new; left=logical_or_expression(); killsp(); if(ctok->type==QUEST){ next_token();killsp(); new=new_node(); new->flags=COND; new->ntyp=0; new->left=left; new->right=new_node(); new->right->flags=COLON; new->right->ntyp=0; new->right->left=expression(); killsp(); if(ctok->type==T_COLON){next_token();killsp();} else error(70); new->right->right=conditional_expression(); left=new; killsp(); } return left;}np logical_or_expression(void)/* Erledigt || */{ np left,right,new;int bra; if(ctok->type==LPAR) bra=1; else bra=0; left=logical_and_expression(); killsp(); while(ctok->type==T_LOR){#ifdef HAVE_MISRA/* removed */#endif next_token(); killsp(); if(ctok->type==LPAR) bra=1; else bra=0; right=logical_and_expression();#ifdef HAVE_MISRA/* removed */#endif new=new_node(); new->left=left; new->right=right; new->flags=LOR; new->ntyp=0; left=new; killsp(); if(ctok->type==T_LAND) error(222); } return left;}np logical_and_expression(void)/* Erledigt && */{ np left,right,new;int bra; if(ctok->type==LPAR) bra=1; else bra=0; left=inclusive_or_expression(); killsp(); while(ctok->type==T_LAND){#ifdef HAVE_MISRA/* removed */#endif next_token(); killsp(); if(ctok->type==LPAR) bra=1; else bra=0; right=inclusive_or_expression();#ifdef HAVE_MISRA/* removed */#endif new=new_node(); new->left=left; new->right=right; new->flags=LAND; new->ntyp=0; left=new; killsp(); if(ctok->type==T_LOR) error(222); } return left;}np inclusive_or_expression(void)/* Erledigt | */{ np left,right,new; left=exclusive_or_expression(); killsp(); while(ctok->type==T_OR){ next_token(); killsp(); right=exclusive_or_expression(); new=new_node(); new->left=left; new->right=right; new->flags=OR; new->ntyp=0; left=new; killsp(); } return left;}np exclusive_or_expression(void)/* Erledigt ^ */{ np left,right,new; left=and_expression(); killsp(); while(ctok->type==CIRC){ next_token(); killsp(); right=and_expression(); new=new_node(); new->left=left; new->right=right; new->flags=XOR; new->ntyp=0; left=new; killsp(); } return left;}np and_expression(void) /* Erledigt & */{ np left,right,new; left=equality_expression(); killsp(); while(ctok->type==T_AND){ next_token(); killsp(); right=equality_expression(); new=new_node(); new->left=left; new->right=right; new->flags=AND; new->ntyp=0; left=new; killsp(); } return left;}np equality_expression(void)/* Erledigt == und != */{ np left,right,new;int c; left=relational_expression(); killsp(); while(ctok->type==SAME||ctok->type==NEQ){ if(ctok->type==NEQ) c=INEQUAL; else c=EQUAL; next_token(); killsp(); right=relational_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left;}np relational_expression(void)/* Erledigt <,>,<=,>= */{ np left,right,new;int c; left=shift_expression(); killsp(); while(ctok->type==LT||ctok->type==GT||ctok->type==LEQ||ctok->type==GEQ){ if(ctok->type==LT) c=LESS; else if(ctok->type==GT) c=GREATER; else if(ctok->type==LEQ) c=LESSEQ; else c=GREATEREQ; next_token(); killsp(); right=shift_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left;}np shift_expression(void)/* Erledigt <<,>> */{ np left,right,new;int c; left=additive_expression(); killsp(); while(ctok->type==LSH||ctok->type==RSH){ if(ctok->type==LSH) c=LSHIFT; else c=RSHIFT; next_token(); killsp(); right=additive_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left;}np additive_expression(void)/* Erledigt +,- */{ np left,right,new;int c; left=multiplicative_expression(); killsp(); while(ctok->type==PLUS||ctok->type==T_MINUS){ if(ctok->type==PLUS) c=ADD; else c=SUB; next_token();killsp(); right=multiplicative_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left;}np multiplicative_expression(void)/* Erledigt *,/,% */{ np left,right,new;int c; left=cast_expression(); killsp(); while(ctok->type==STAR||ctok->type==SLASH||ctok->type==PCT){ if(ctok->type==STAR) c=MULT; else if(ctok->type==SLASH) c=DIV; else c=MOD; next_token();killsp(); right=cast_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left;}np cast_expression(void)/* Erledigt (typ) */{ np new;char *imerk,buff[MAXI]; killsp(); if(ctok->type!=LPAR||!declaration(1)) return unary_expression(); next_token();killsp(); new=new_node(); new->right=0; buff[0]=0; imerk=ident;ident=buff; new->ntyp=declarator(declaration_specifiers()); ident=imerk; if(buff[0]) error(356); killsp(); if(ctok->type!=RPAR) error(59); else next_token(); killsp(); if(c99&&ctok->type==LBRA){ /* compund literals */ init_dyn_cnt=0; new->cl=initialization(new->ntyp,nesting!=0,0,0,0,0); killsp(); if(new->cl){ if(ISARRAY(new->ntyp->flags)&&zmeqto(new->ntyp->size,l2zm(0L))){ struct const_list *p=new->cl; while(p){new->ntyp->size=zmadd(p->idx,l2zm(1L));p=p->next;} } } new->flags=LITERAL; new->left=0; new->val.vmax=l2zm((long)init_dyn_cnt); }else{ new->flags=CAST; new->left=cast_expression(); } return new;}np unary_expression(void)/* Erledigt !,~,++,--,+,-,*,&,sizeof,__typeof */{ np new;char *merk; killsp(); if(ctok->type!=NAME&&ctok->type!=PLUS&&ctok->type!=PPLUS&&ctok->type!=T_MINUS&&ctok->type!=MMINUS&&ctok->type!=T_AND&&ctok->type!=STAR&&ctok->type!=NOT&&ctok->type!=LNOT) return postfix_expression(); if(ctok->type==NAME){ enum {SIZEOF,TYPEOF,ALIGNOF,OFFSETOF} op; if(strcmp("sizeof",ctok->name)&&strcmp("__typeof",ctok->name)&&strcmp("__alignof",ctok->name)&&strcmp("__offsetof",ctok->name)){ return postfix_expression(); }else{ if(*ctok->name=='s') op=SIZEOF; else if(ctok->name[2]=='a') op=ALIGNOF; else if(ctok->name[2]=='t') op=TYPEOF; else op=OFFSETOF; next_token(); killsp(); new=new_node(); new->flags=CEXPR; new->ntyp=new_typ(); if(op==SIZEOF||op==OFFSETOF){ if(HAVE_INT_SIZET) new->ntyp->flags=(UNSIGNED|INT); else new->ntyp->flags=(UNSIGNED|LONG); }else new->ntyp->flags=INT; new->right=0; new->left=0; if(ctok->type==LPAR&&declaration(1)){ struct Typ *t; next_token();killsp(); buff[0]=0; merk=ident;ident=buff; t=declarator(declaration_specifiers()); if(type_uncomplete(t)) error(176); ident=merk; if(buff[0]) error(356); if(op==OFFSETOF){ if(ctok->type==COMMA) next_token(); else error(57); if(ctok->type!=NAME) error(76); if(t->flags!=STRUCT){ error(310); vumax=ul2zum(0UL); }else vumax=zm2zum(struct_offset(t->exact,ctok->name)); next_token(); if(HAVE_INT_SIZET) new->val.vuint=zum2zui(vumax); else new->val.vulong=zum2zul(vumax); }else if(op==SIZEOF){ if(is_vlength(t)){ new->dsize=vlength_szof(t); new->flags=IDENTIFIER; new->val.vmax=l2zm(0L); new->sidefx=0; new->identifier=empty; }else{ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(zm2zum(szof(t))); else new->val.vulong=zum2zul(zm2zum(szof(t))); } }else if(op==ALIGNOF){ new->val.vint=zm2zi(falign(t)); }else if(op==TYPEOF){ new->val.vint=zm2zi(l2zm(t->flags)); } freetyp(t); killsp(); if(ctok->type!=RPAR) error(59); else next_token(); }else{ np tree; if(op==OFFSETOF) error(0); killsp(); tree=unary_expression(); if(!tree||!type_expression(tree)){ if(op==SIZEOF){ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(ul2zum(0UL)); else new->val.vulong=zum2zul(ul2zum(0UL)); error(73); }else{ new->val.vint=zm2zi(l2zm(-1L)); } }else{ if(op==SIZEOF){#ifdef HAVE_MISRA/* removed */#endif if(type_uncomplete(tree->ntyp)) error(176); if(is_vlength(tree->ntyp)){ new->dsize=vlength_szof(tree->ntyp); new->flags=IDENTIFIER; new->val.vmax=l2zm(0L); new->sidefx=0; new->identifier=empty; }else{ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(zm2zum(szof(tree->ntyp))); else new->val.vulong=zum2zul(zm2zum(szof(tree->ntyp))); } }else{ if(op==ALIGNOF) new->val.vint=zm2zi(falign(tree->ntyp)); else new->val.vint=zm2zi(l2zm(tree->ntyp->flags)); } } if(tree) free_expression(tree);killsp(); }Lines 1–500 of 1032. Load more
/* $VER: vbcc (parse_expr.c) V0.8 */ #include "vbcc_cpp.h" #include "vbc.h" static char FILE_[]=__FILE__; np new_node(void) { np p=mymalloc(NODES); p->flags=0; p->lvalue=0; p->sidefx=0; p->ntyp=0; p->left=0; p->right=0; p->alist=0; p->identifier=0; p->o.flags=0; return p; } np expression(void) /* Komma-Ausdruecke */ { np left,right,new; left=assignment_expression(); if(!left->flags) return 0; killsp(); while(ctok->type==COMMA){ #ifdef HAVE_MISRA /* removed */ #endif next_token(); killsp(); right=assignment_expression(); new=new_node(); new->left=left; new->right=right; new->ntyp=0; new->flags=KOMMA; left=new; killsp(); } return left; } np assignment_expression(void) /* Zuweisungsausdruecke */ { np left,new;int c=ASSIGNOP,op; left=conditional_expression(); killsp(); switch(ctok->type){ case ASGN: c=ASSIGN;break; case ASSTAR: op=MULT;break; case ASSLASH: op=DIV;break; case ASPCT: op=MOD;break; case ASPLUS: op=ADD;break; case ASMINUS: op=SUB;break; case ASAND: op=AND;break; case ASCIRC: op=XOR;break; case ASOR: op=OR;break; case ASLSH: op=LSHIFT;break; case ASRSH: op=RSHIFT;break; default: return left; } next_token(); new=new_node(); new->left=left; new->ntyp=0; if(c==ASSIGN){ new->right=assignment_expression(); new->flags=ASSIGN; }else{ /* ASSIGNOP(a,b)->ASSIGN(a,OP(a,b)) */ new->flags=ASSIGNOP; /* nur um zum Merken, dass nur einmal */ /* ausgewertet werden darf */ new->right=new_node(); new->right->left=left; new->right->right=assignment_expression(); new->right->ntyp=0; new->right->flags=op; } return new; } np conditional_expression(void) /* Erledigt ? : */ { np left,new; left=logical_or_expression(); killsp(); if(ctok->type==QUEST){ next_token();killsp(); new=new_node(); new->flags=COND; new->ntyp=0; new->left=left; new->right=new_node(); new->right->flags=COLON; new->right->ntyp=0; new->right->left=expression(); killsp(); if(ctok->type==T_COLON){next_token();killsp();} else error(70); new->right->right=conditional_expression(); left=new; killsp(); } return left; } np logical_or_expression(void) /* Erledigt || */ { np left,right,new;int bra; if(ctok->type==LPAR) bra=1; else bra=0; left=logical_and_expression(); killsp(); while(ctok->type==T_LOR){ #ifdef HAVE_MISRA /* removed */ #endif next_token(); killsp(); if(ctok->type==LPAR) bra=1; else bra=0; right=logical_and_expression(); #ifdef HAVE_MISRA /* removed */ #endif new=new_node(); new->left=left; new->right=right; new->flags=LOR; new->ntyp=0; left=new; killsp(); if(ctok->type==T_LAND) error(222); } return left; } np logical_and_expression(void) /* Erledigt && */ { np left,right,new;int bra; if(ctok->type==LPAR) bra=1; else bra=0; left=inclusive_or_expression(); killsp(); while(ctok->type==T_LAND){ #ifdef HAVE_MISRA /* removed */ #endif next_token(); killsp(); if(ctok->type==LPAR) bra=1; else bra=0; right=inclusive_or_expression(); #ifdef HAVE_MISRA /* removed */ #endif new=new_node(); new->left=left; new->right=right; new->flags=LAND; new->ntyp=0; left=new; killsp(); if(ctok->type==T_LOR) error(222); } return left; } np inclusive_or_expression(void) /* Erledigt | */ { np left,right,new; left=exclusive_or_expression(); killsp(); while(ctok->type==T_OR){ next_token(); killsp(); right=exclusive_or_expression(); new=new_node(); new->left=left; new->right=right; new->flags=OR; new->ntyp=0; left=new; killsp(); } return left; } np exclusive_or_expression(void) /* Erledigt ^ */ { np left,right,new; left=and_expression(); killsp(); while(ctok->type==CIRC){ next_token(); killsp(); right=and_expression(); new=new_node(); new->left=left; new->right=right; new->flags=XOR; new->ntyp=0; left=new; killsp(); } return left; } np and_expression(void) /* Erledigt & */ { np left,right,new; left=equality_expression(); killsp(); while(ctok->type==T_AND){ next_token(); killsp(); right=equality_expression(); new=new_node(); new->left=left; new->right=right; new->flags=AND; new->ntyp=0; left=new; killsp(); } return left; } np equality_expression(void) /* Erledigt == und != */ { np left,right,new;int c; left=relational_expression(); killsp(); while(ctok->type==SAME||ctok->type==NEQ){ if(ctok->type==NEQ) c=INEQUAL; else c=EQUAL; next_token(); killsp(); right=relational_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left; } np relational_expression(void) /* Erledigt <,>,<=,>= */ { np left,right,new;int c; left=shift_expression(); killsp(); while(ctok->type==LT||ctok->type==GT||ctok->type==LEQ||ctok->type==GEQ){ if(ctok->type==LT) c=LESS; else if(ctok->type==GT) c=GREATER; else if(ctok->type==LEQ) c=LESSEQ; else c=GREATEREQ; next_token(); killsp(); right=shift_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left; } np shift_expression(void) /* Erledigt <<,>> */ { np left,right,new;int c; left=additive_expression(); killsp(); while(ctok->type==LSH||ctok->type==RSH){ if(ctok->type==LSH) c=LSHIFT; else c=RSHIFT; next_token(); killsp(); right=additive_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left; } np additive_expression(void) /* Erledigt +,- */ { np left,right,new;int c; left=multiplicative_expression(); killsp(); while(ctok->type==PLUS||ctok->type==T_MINUS){ if(ctok->type==PLUS) c=ADD; else c=SUB; next_token();killsp(); right=multiplicative_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left; } np multiplicative_expression(void) /* Erledigt *,/,% */ { np left,right,new;int c; left=cast_expression(); killsp(); while(ctok->type==STAR||ctok->type==SLASH||ctok->type==PCT){ if(ctok->type==STAR) c=MULT; else if(ctok->type==SLASH) c=DIV; else c=MOD; next_token();killsp(); right=cast_expression(); new=new_node(); new->left=left; new->right=right; new->flags=c; new->ntyp=0; left=new; killsp(); } return left; } np cast_expression(void) /* Erledigt (typ) */ { np new;char *imerk,buff[MAXI]; killsp(); if(ctok->type!=LPAR||!declaration(1)) return unary_expression(); next_token();killsp(); new=new_node(); new->right=0; buff[0]=0; imerk=ident;ident=buff; new->ntyp=declarator(declaration_specifiers()); ident=imerk; if(buff[0]) error(356); killsp(); if(ctok->type!=RPAR) error(59); else next_token(); killsp(); if(c99&&ctok->type==LBRA){ /* compund literals */ init_dyn_cnt=0; new->cl=initialization(new->ntyp,nesting!=0,0,0,0,0); killsp(); if(new->cl){ if(ISARRAY(new->ntyp->flags)&&zmeqto(new->ntyp->size,l2zm(0L))){ struct const_list *p=new->cl; while(p){new->ntyp->size=zmadd(p->idx,l2zm(1L));p=p->next;} } } new->flags=LITERAL; new->left=0; new->val.vmax=l2zm((long)init_dyn_cnt); }else{ new->flags=CAST; new->left=cast_expression(); } return new; } np unary_expression(void) /* Erledigt !,~,++,--,+,-,*,&,sizeof,__typeof */ { np new;char *merk; killsp(); if(ctok->type!=NAME&&ctok->type!=PLUS&&ctok->type!=PPLUS&&ctok->type!=T_MINUS&&ctok->type!=MMINUS&&ctok->type!=T_AND&&ctok->type!=STAR&&ctok->type!=NOT&&ctok->type!=LNOT) return postfix_expression(); if(ctok->type==NAME){ enum {SIZEOF,TYPEOF,ALIGNOF,OFFSETOF} op; if(strcmp("sizeof",ctok->name)&&strcmp("__typeof",ctok->name)&&strcmp("__alignof",ctok->name)&&strcmp("__offsetof",ctok->name)){ return postfix_expression(); }else{ if(*ctok->name=='s') op=SIZEOF; else if(ctok->name[2]=='a') op=ALIGNOF; else if(ctok->name[2]=='t') op=TYPEOF; else op=OFFSETOF; next_token(); killsp(); new=new_node(); new->flags=CEXPR; new->ntyp=new_typ(); if(op==SIZEOF||op==OFFSETOF){ if(HAVE_INT_SIZET) new->ntyp->flags=(UNSIGNED|INT); else new->ntyp->flags=(UNSIGNED|LONG); }else new->ntyp->flags=INT; new->right=0; new->left=0; if(ctok->type==LPAR&&declaration(1)){ struct Typ *t; next_token();killsp(); buff[0]=0; merk=ident;ident=buff; t=declarator(declaration_specifiers()); if(type_uncomplete(t)) error(176); ident=merk; if(buff[0]) error(356); if(op==OFFSETOF){ if(ctok->type==COMMA) next_token(); else error(57); if(ctok->type!=NAME) error(76); if(t->flags!=STRUCT){ error(310); vumax=ul2zum(0UL); }else vumax=zm2zum(struct_offset(t->exact,ctok->name)); next_token(); if(HAVE_INT_SIZET) new->val.vuint=zum2zui(vumax); else new->val.vulong=zum2zul(vumax); }else if(op==SIZEOF){ if(is_vlength(t)){ new->dsize=vlength_szof(t); new->flags=IDENTIFIER; new->val.vmax=l2zm(0L); new->sidefx=0; new->identifier=empty; }else{ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(zm2zum(szof(t))); else new->val.vulong=zum2zul(zm2zum(szof(t))); } }else if(op==ALIGNOF){ new->val.vint=zm2zi(falign(t)); }else if(op==TYPEOF){ new->val.vint=zm2zi(l2zm(t->flags)); } freetyp(t); killsp(); if(ctok->type!=RPAR) error(59); else next_token(); }else{ np tree; if(op==OFFSETOF) error(0); killsp(); tree=unary_expression(); if(!tree||!type_expression(tree)){ if(op==SIZEOF){ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(ul2zum(0UL)); else new->val.vulong=zum2zul(ul2zum(0UL)); error(73); }else{ new->val.vint=zm2zi(l2zm(-1L)); } }else{ if(op==SIZEOF){ #ifdef HAVE_MISRA /* removed */ #endif if(type_uncomplete(tree->ntyp)) error(176); if(is_vlength(tree->ntyp)){ new->dsize=vlength_szof(tree->ntyp); new->flags=IDENTIFIER; new->val.vmax=l2zm(0L); new->sidefx=0; new->identifier=empty; }else{ if(HAVE_INT_SIZET) new->val.vuint=zum2zui(zm2zum(szof(tree->ntyp))); else new->val.vulong=zum2zul(zm2zum(szof(tree->ntyp))); } }else{ if(op==ALIGNOF) new->val.vint=zm2zi(falign(tree->ntyp)); else new->val.vint=zm2zi(l2zm(tree->ntyp->flags)); } } if(tree) free_expression(tree);killsp(); }