Esempio n. 1
0
static Boolean_t compound_statement( void )
{
   int lineno_beg;
   int charno_beg;
   int niveau_a;
   Save();
   niveau++;

   if( token( 0 ) != '{' )
   {
      Restore();
      niveau--;
      return False;
   }

   CompCreate();

   step( 1 );

   while( True )
   {
      if( token( 0 ) == '}' )
      {
         step( 1 );
         CompDestroy();
         niveau--;
         return True;
      } 

      if( token( 0 ) == 0 )
      {
         CompDestroy();
         niveau--;
         return True;
      }

      niveau_a = niveau;
      lineno_beg = f_lineno( 0 );
      charno_beg = f_charno( 0 );
      statement();
      if( niveau_a != niveau )
      {
         printf( "different niveau by statement: %s:%d.%d - %d.%d\n"
               , filename_g
               , lineno_beg
               , charno_beg
               , f_lineno( -1 )
               , f_charno( -1 ) + identlen( -1 )
               );
      }
   }
}
Esempio n. 2
0
static Boolean_t expression_statement( void )
{
   Save();

   if( f_expression())
   {
      if( token( 0 ) == ';' )
      {
         step( 1 );
      }
      else
      {
#ifdef CORVEX
         printf( "expected ';' at end of expression statement: %s:%d.%d\n"
               , filename_g
               , f_lineno( 0 )
               , f_charno( 0 )
               );
#endif
      }
      return True;
   }

   Restore();
   return False;
}
Esempio n. 3
0
static Boolean_t statement( void )
{
/*    printf( "statement: %s\n", ident( 0 )); */
   switch( token( 0 ))
   {
   case ';'         : step( 1 ); return True;
   case '{'         : return compound_statement();
   case SN_CASE     : return case_statement();
   case SN_DEFAULT  : return default_statement();
   case SN_IF       : return if_statement();
   case SN_ELSE     : return else_statement();
   case SN_SWITCH   : return switch_statement();
   case SN_WHILE    : return while_statement();
   case SN_DO       : return do_statement();
   case SN_FOR      : return for_statement();
   case SN_BREAK    : return break_statement();
   case SN_CONTINUE : return continue_statement();
   case SN_RETURN   : return return_statement();
   case SN_THROW    : return throw_statement();
   case SN_GOTO     : return goto_statement();
   case SN_TRY      : return try_statement();

   case SN_IDENTIFIER:
      if( labeled_statement     ()) return True;
      if( declaration_statement1()) return True;
      if( expression_statement  ()) return True;
      if( declaration_statement2()) return True;
      step( 1 );
      return False;

   case SN_CHAR     :
   case SN_SHORT    :
   case SN_INT      :
   case SN_LONG     :
   case SN_SIGNED   :
   case SN_UNSIGNED :
   case SN_FLOAT    :
   case SN_DOUBLE   :
   case SN_BOOL     :
   case SN_VOID     :
      if( declaration_statement1()) return True;
      if( expression_statement  ()) return True;
      if( declaration_statement2()) return True;
      step( 1 );
      return False;

   case SN_ASM      :
   case SN_TEMPLATE :
   case SN_NAMESPACE:
   case SN_USING    :
   case SN_AUTO     :
   case SN_REGISTER :
   case SN_EXTERN   :
   case SN_STATIC   :
   case SN_INLINE   :
   case SN_VIRTUAL  :
   case SN_CONST    :
   case SN_VOLATILE :
   case SN_CLASS    :
   case SN_STRUCT   :
   case SN_UNION    :
   case SN_ENUM     :
   case SN_FRIEND   :
   case SN_TYPEDEF  :
      if( declaration_statement1()) return True;
      if( declaration_statement2()) return True;
      f_StepTo( ';', '}', 0 );
      return False;

   case SN_SIZEOF :
   case SN_NEW :
   case SN_DELETE :
   case SN_THIS :
   case SN_OPERATOR :
   case SN_STRINGliteral :
   case SN_FLOATINGconstant :
   case SN_INTEGERconstant :
   case SN_LONGconstant :
   case SN_CHARACTERconstant :
   case SN_ICR :
   case SN_DECR :
   case SN_CLCL :
   case '(':
   case '~':
   case '*':
   case '&':
   case '+':
   case '-':
   case '!':
      if( expression_statement ()) return True;
      step( 1 );
      return False;

   case 0:
      printf( "unexpected end of file\n" );
      return False;

   default:
#ifdef PRINT_STATEMENT_DEFAULT
      printf( "statement: default: %4d %s file: %s:(%d.%d)\n"
            , token( 0 )
            , ident( 0 )
            , filename_g
            , f_lineno( 0 )
            , f_charno( 0 )
            );
#endif
#ifdef BREAK_BY_STATEMENT_DEFAULT
      exit( -1 );
#endif
      if( declaration_statement1()) return True;
      if( expression_statement  ()) return True;
      if( declaration_statement2()) return True;
      step( 1 );
      return False;

/*    case SN_ARROW : */
/*    case SN_LS : */
/*    case SN_RS : */
/*    case SN_LE : */
/*    case SN_GE : */
/*    case SN_EQ : */
/*    case SN_NE : */
/*    case SN_ANDAND : */
/*    case SN_OROR : */
/*    case SN_ELLIPSIS : */
/*    case SN_DOTstar : */
/*    case SN_ARROWstar : */
/*    case SN_MULTassign : */
/*    case SN_DIVassign : */
/*    case SN_MODassign : */
/*    case SN_PLUSassign : */
/*    case SN_MINUSassign : */
/*    case SN_LSassign : */
/*    case SN_RSassign : */
/*    case SN_ANDassign : */
/*    case SN_ERassign : */
/*    case SN_ORassign : */
/*    case '=' : */
/*    case '|' : */
/*    case '^' : */
/*    case '&' : */
/*    case '<' : */
/*    case '>' : */
/*    case '/' : */
/*    case '%' : */
/*    case ')' : */
/*    case '[' : */
/*    case ']' : */
/*    case '.' : */
/*    case ',' : */
/*    case '{' : */
/*    case '}' : */
/*    case '?' : */
/*    case ':' : */
   }
}
Esempio n. 4
0
static Declaration_t f_ArgumentDeclaration( void )
{
   Declaration_t Declaration = f_DeclarationCreate( DECLARATION_ARGUMENT );
   Declarator_t Declarator;
   int iTypeSpec = 0;
   int iStorage = 0;
   int iModifier = 0;
   Name_t Name;
   Save();
   niveau++;

   if( test ) printf( "f_ArgumentDeclaration: %s\n", ident( 0 ));

   while( True )
   {
      switch( token( 0 ))
      {
   /* storage class specifiers */
      case SN_REGISTER  :
         Declaration->storage_class = SN_REGISTER;
         iStorage++;
         step( 1 );
         break;

      case SN_AUTO  :
         Declaration->storage_class = SN_AUTO;
         iStorage++;
         step( 1 );
         break;

   /* fct specifiers */
      case SN_INLINE    :
         Declaration->fct_specifier = SN_INLINE;
         iModifier++;
         step( 1 );
         break;

      case SN_VIRTUAL   :
         Declaration->fct_specifier = SN_VIRTUAL;
         iModifier++;
         step( 1 );
         break;

      case SN_CLASS      :
      case SN_STRUCT     :
      case SN_UNION      :
         iTypeSpec++;
         if(( Declaration->Class = f_Class()) == 0 )
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 2 );
            niveau--;
            return 0;
         }
         break;

      case SN_ENUM       :
         iTypeSpec++;
         if(( Declaration->Enum = f_Enum()) == 0 )
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 3 );
            niveau--;
            return 0;
         }
         break;

      case SN_CONST      : Declaration->s_const    = True; goto modifier;
      case SN_VOLATILE   : Declaration->s_volatile = True; goto modifier;
modifier:
         iModifier++;
         step( 1 );
         break;

      case SN_CHAR       : Declaration->s_char     = True; goto type;
      case SN_SHORT      : Declaration->s_short    = True; goto type;
      case SN_INT        : Declaration->s_int      = True; goto type;
      case SN_LONG       : Declaration->s_long     = True; goto type;
      case SN_SIGNED     : Declaration->s_signed   = True; goto type;
      case SN_UNSIGNED   : Declaration->s_unsigned = True; goto type;
      case SN_FLOAT      : Declaration->s_float    = True; goto type;
      case SN_DOUBLE     : Declaration->s_double   = True; goto type;
      case SN_BOOL       : Declaration->s_bool     = True; goto type;
      case SN_VOID       : Declaration->s_void     = True; goto type;
type:
         iTypeSpec++;
         step( 1 );
         break;

      case ',':
      case ')':
      case SN_ELLIPSIS:
         if( iTypeSpec > 0 || iStorage > 0 || iModifier > 0 )
         {  /* optional abstract_declarator */
            niveau--;
            return Declaration;
         }
         else
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 4 );
            niveau--;
            return 0;
         }

      case '=':
         if( iTypeSpec > 0 || iStorage > 0 || iModifier > 0 )
         {  /* optional abstract_declarator */
            step( 1 );
            Declarator = f_DeclaratorCreate();
            Declarator->Expr = f_AssignmentExpression();
            f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
            niveau--;
            return Declaration;
         }
         else
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 5 );
            niveau--;
            return 0;
         }

      default:
         if( iTypeSpec == 0 && iStorage == 0 && iModifier == 0 )
         {
            if(( Declaration->Name = f_CompleteClassName()))
            {
               iTypeSpec++;
            }
            else
            {
               f_DeclarationDestroy( Declaration );
               Restore();
               niveau--;
               return 0;
            }
         }
         else if( iTypeSpec == 0 )
         {
            if(( Declaration->Name = f_CompleteClassName()))
            {
               iTypeSpec++;
            }
            else if(( Declarator = f_ArgumentDeclarator()))
            {
               f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
               niveau--;
               return Declaration;
            }
            else
            {
/* A constructor hivasok nagyon hasonlitanak a fuggveny deklaraciokra, ezert
   itt nem szabad nagyvonaluan atlepni a feldolgozhatatlan token-t */
               f_DeclarationDestroy( Declaration );
               Restore();
               niveau--;
               return 0;
            }
         }
         else
         {
            if(( Declarator = f_ArgumentDeclarator()))
            {
               f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
               niveau--;
               return Declaration;
            }

            if(( Name = f_CompleteClassName()))
            {
               iTypeSpec++;
               if( Declaration->Name )
               {
#ifdef CORVEX
                  printf( "error: second name: %s %s (%s:%d.%d)\n"
                        , Declaration->Name->pcName
                        , Name->pcName
                        , filename_g
                        , f_lineno( 0 )
                        , f_charno( 0 )
                        );
#endif
                  f_NameDestroy( Name );
               }
               else
               {
                  Declaration->Name = Name;
               }
            }
            else
            {
/*             step( 1 );
   A constructor hivasok nagyon hasonlitanak a fuggveny deklaraciokra, ezert
   itt nem szabad nagyvonaluan atlepni a feldolgozhatatlan token-t */
               f_DeclarationDestroy( Declaration );
               Restore();
/*                f_SyntaxError( 7 ); */
               niveau--;
               return 0;
            }
         }
         break;
      }
   }
}