semant.old 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "parser.h"
  2. void ExprSeqNode::semant( Scope *s ){
  3. for( int k=0;k<exprs.size();++k ) exprs[k]->semant( s );
  4. type=Type::int_type;
  5. }
  6. void SimpleVarNode::semant( Scope *s ){
  7. if( type=s->findIdent( ident ) ) return;
  8. s->insertIdent( ident,Type::int_type );
  9. }
  10. void LabelNode::semant( Scope *s ){
  11. Type *t=s->findIdent( label );
  12. if( !t ){
  13. s->insertIdent( label,new LabelType( this ) );
  14. return;
  15. }
  16. if( t->labelType() && !t->labelType()->defn ){
  17. t->labelType()->defn=this;
  18. return;
  19. }
  20. semantEx( "Duplicate identifier" );
  21. }
  22. void GotoNode::semant( Scope *s ){
  23. Type *t=s->findIdent( label );
  24. if( !t ){
  25. s->insertIdent( label,new LabelType(0) );
  26. return;
  27. }
  28. if( t->labelType() ) return;
  29. semantEx( "Duplicate Identifier" );
  30. }
  31. void ProgNode::semant( Scope *s ){
  32. StmtSeqNode::semant( s );
  33. map<string,Type*>::iterator it;
  34. for( it=s->idents.begin();it!=s->idents.end();++it ){
  35. if( LabelType *l=it->second->labelType() ){
  36. if( !l->defn ){
  37. semantEx( "Undefined Label" );
  38. }
  39. }
  40. }
  41. }