Traduction programme C++ to delphi

salago Messages postés 1 Date d'inscription jeudi 30 août 2007 Statut Membre Dernière intervention 11 janvier 2014 - 11 janv. 2014 à 13:25
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Dernière intervention 3 juillet 2015 - 13 janv. 2014 à 09:48
Bonjour, je veux traduire ce programme au DELPHI , SVP
C Urg
merci
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
  int fct_chiffre(char c);
  int fct_lettre(char c);
  int fct_operateur(char c);
  int fct_Identificateur(char *tab,int d,int f);
  int fct_entier(char *tab,int d,int f);
  void affiche(char *tab,int d,int f);
  void fct_test(char  tab[]);//pour determiner les lettres,les chiffres et les operateur
  void bloc();
  void corps();
  void declaration();
  void exp();
  void exp_simple();
  void facteur();
  void inst();
  void list_id();
  void list_inst();
  void list_type();
  void pgauche();
  void prgm();
  void relop();
  void terme();
  void type();
  int is_addop();
  int is_mulop();
  int is_cste(char tab[]);
  int is_id(char tab[])
  {

      return(fct_lettre(tab[0]));
  }
  int is_cste(char entier[])
  {
      int r=1;
      for(int i=0;i<strlen(entier);i++)
        {
            if(!fct_chiffre(entier[i])) r=0;
        }
        return r;
  }
  int d=0,f;

  char sym[20];
  char phrase[200];
int compar(char s1[], char s2[])
{
    int i=0;
    while(i<strlen(s1))
    {
        if(strlen(s1)!=strlen(s2)) return 0 ;
        else if (s1[i]!=s2[i]) {return 0; break ;}
        else i++;
    }
    if (i==strlen(s1)) return 1;
}

void cut(char phrase1[],int a, int b)
{
    for(int k=0;k<20;k++) sym[k]=NULL;
    int i,j;
    j=a;i=0;
    while(i<=b-a)
    {
        sym[i]=phrase1[j];
        j++;i++;
    }
}
void next()
{
    for(int k=0;k<20;k++) sym[k]=NULL;
    int i= d;
    while(phrase[i]!=' '&& i<strlen(phrase)+1) i++;
    if(phrase[i]==' '|| i==strlen(phrase)+1)
         {
         f=i-1;
          if(fct_Identificateur(phrase,d,f))
          {
              cut(phrase,d,f);

          }
          else if (fct_entier(phrase,d,f))
          {
              cut(phrase,d,f);
          }
             else
             {
             cut(phrase,d,f);

             }
             d=f+2;
             i=f+1;
        }
        i++;
}
void type(){
if(compar(sym,"integer")) {printf("\n%s : type accepted ",sym) ; next();}
else if (compar(sym,"array"))
{
    printf("\n%s :accepted ",sym) ;
    next();
    if(compar(sym,"["))
    {
        printf("\n%s :accepted ",sym) ;
        next();
        if(is_cste(sym))
        {
            printf("\n%s :accepted ",sym) ;
            next();
            if (compar(sym,".."))
            {
                printf("\n%s :accepted ",sym) ;
                next();
                if(is_cste(sym))
                {
                    printf("\n%s :accepted ",sym) ;
                    next();
                    if(compar(sym,"]"))
                    {
                        printf("\n%s :accepted ",sym) ;
                        next();
                        if(compar(sym,"of"))
                        {
                            printf("\n%s :accepted ",sym) ;
                            next();
                            if(compar(sym,"integer")) {printf("\ndeclaration du tableau reussi ");next();}else printf("\nerreur->%s type non valide",sym);

                        }else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
                    }else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
                }else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
            }else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
        } else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
    }else printf("\nerreur->%s non valide pour la declaration d un tableau",sym);
} else printf("\nerreur->%s type non valide",sym);
}
void list_id()
{
    if(is_id(sym)&& !compar(sym,"begin"))
    {
    printf("\n%s->ID valide",sym);
    next() ;
    } else if(compar(sym,"begin")&& !is_id(sym))printf("\nerreur->ID %s non valide",sym);
    while(compar(sym,",")) { next(); list_id();}
}

void list_type()
{
list_id();
if(compar(sym,":")){
    next(); type();
    if(compar(sym,";")){
    next(); list_type();
    }

    } else if(!compar(sym,"begin")) printf("\nerreur: declaration des variables");
}
void declaration()
{
    if (compar(sym,"var")){
    next(); list_type();
    } else printf("\naucune declalation validée");
}

void exp_simple()
{
    terme();
    if(is_addop())
    {
        printf("\n addop reussi");
        next();
        exp_simple();
    }

}

void exp()
{
    exp_simple();
    relop();
    exp_simple();
    printf("\n expression verifie");
}


void facteur()
{
    if(compar(sym,"not")) { next(); exp();}
    else if(is_cste(sym)) {printf("\n%s->constante ",sym); next();}
    else if(compar(sym,"("))
    {
        next();
        exp();
        if(compar(sym,")")) {printf("\nparentheses verifiees");next();}
        else printf("\nerreur parenthese manquante");
    }
    else pgauche();
}


void terme()
{
    facteur();
    if (is_mulop())
    {
        printf("\nmulop reussi ");
        next();
        terme();
    }

}


void inst()
{
    if(compar(sym,"if"))
    {
        printf("\n if verifie");
        next();
        exp();
        if (compar(sym,"then")){ printf("\nparours then ");next(); corps();} else printf("\nerror: syntaxe if non verifie ");

    }
    else if(compar(sym,"while"))
    {
        printf("\n while verifie");
        next();
        exp();
        if (compar(sym,"do")){ printf("\nparours do ");next(); corps();} else printf("\nerror: syntaxe if non verifie ");

    }
    else
    {
        pgauche();
        if (compar(sym,":="))
        {
            printf("\n%s->accepte ");
            next();
            exp_simple();
        } else printf("\n erreur syntaxt d instruction - id := terme");
    }
}
void list_inst()
{
    inst();
    while(compar(sym,";")){
    next();
    inst();
    }
    printf("\ngrpe d instruction verifie ");

}
void corps(){
if(compar(sym,"begin"))
{
    next();
    list_inst();
    if(compar(sym,"end"))
    {
        printf("\nsyntax verifie ");
        next();
        printf("\nL ANALYSE SYNTAXIQUE TERMINE");
    } else printf("\nerreur: syntaxe non valide pour le grpe d instructions");


} else printf("\nerreur: begin ");
}
void bloc()
{
    declaration();
    corps();
}
void prgm()
{

    if (compar(sym,"program")){
        printf("\n%s->accepted\n",sym);
        next();
        if(is_id(sym))
            {
            printf("\n%s->accepted\n",sym);
            next();
            if (compar(sym,";")){ next(); bloc();}
            else printf("\nerreur: ; oubliee");
            } else printf("\nerreur: ident prog est faut ") ;
        } else printf("\nerreur: prgm");
}

void relop()
{
    if (compar(sym,"=")||compar(sym,"<")||compar(sym,"<=")) {printf("\n%s->operateur",sym); next();} else
    if (compar(sym,"<>")||compar(sym,">=")||compar(sym,">")) {printf("\n%s->operateur",sym); next();} else
    printf("\nerreur : %s operateur non valide  ", sym );
}


void pgauche()
{
    if(is_id(sym)) {printf("\npgauche reussi "); next();} ;
}

int is_mulop()
{
    if(compar(sym,"*")||compar(sym,"/")||compar(sym,"and")) return 1;
    else return 0;
}
int is_addop()
{
    if(compar(sym,"+")||compar(sym,"-")||compar(sym,"or")) return 1;
    else return 0;
}
int main() {

printf("\n\n");
printf("******************>>>>>>>>>>>>ANALYSEUR SYNTAXIQUE<<<<<<<<<<<<<<<**************** ");
printf("\nrealisé par : BENKADJA ABDELLAH******* ");
printf("\n\n \t ****||enter une pharse\n" );
printf("\n\n \t \t\t ***||" );

gets(phrase);
    next();
    prgm();


    getchar();
    return 0;
}
int fct_chiffre(char c){
    if (c>='1' && c<='9')return 1;
    return 0;
}
int fct_lettre(char c){
    if( (c>='a' && c<='z') ||(c>='A' && c<='Z'))return 1;
    return 0;
}
int fct_Identificateur(char *tab,int d,int f){
 if(!fct_lettre(tab[d])) return 0;
  while(d+1<=f+1){
      if(!fct_lettre(tab[d]) && !fct_chiffre(tab[d]) &&  tab[d]!='_') return 0;
      else d++;
  }
    return 1;
}
int fct_entier(char *tab,int d,int f){
 while(d<=f){
     if(!fct_chiffre(tab[d])) return 0;
        else d++;
            }
    return 1;
}
void affiche(char *tab,int d,int f){
     printf("\n\t");
     while(d<=f){
     printf("%c",tab[d]);
     d++;
               }
}
int fct_operateur(char c){
char operateur[10]="<>=+-*/!%";
int i=0;
for(i;operateur[i];i++){
    if(c==operateur[i])return 1;
    }
return 0;
}


2 réponses

NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
11 janv. 2014 à 13:31
Salut,

Codes-Sources est un site communautaire où des bénévoles apportent de l'aide à ceux qui le demandent. Nous ne demandons pas grand chose en retour : juste un peu de reconnaissance et de respect.
Venir poser une question sur le forum en disant que c'est urgent est un manque de respect : qu'est-ce que ça t'apporte de préciser que c'est urgent ? Tu crois qu'en disant ça tu seras prioritaire par rapport aux autres membres ? Tu crois qu'on va se dépêcher de te répondre parce que tu es dans l'urgence ?

Et bien non, bien au contraire ! Dire que c'est urgent ne nous donne vraiment pas envie d'aider. Nous avons tous nos tracas quotidiens, avec nos patrons qui nous disent qu'il leur faut telle fonctionnalité pour demain matin à 8 h (si ce n'est pour la veille). Alors je traque tout ceux qui demandent de l'aide de façon urgente histoire de bien leur faire comprendre qu'on y gagne rien à aider les gens, alors le moins que tu peux espérer, c'est de trouver quelqu'un qui veuille bien t'aider, l'urgence elle n'est que pour toi, et surtout pas pour nous !
0
sp40 Messages postés 1276 Date d'inscription mardi 28 octobre 2003 Statut Contributeur Dernière intervention 3 juillet 2015 15
13 janv. 2014 à 09:48
Combien tu payes salago ?
(pour "urgent", ajoutes un zéro...)
0
Rejoignez-nous