Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

hashCode.c

Description du code

hashCode.c est un fichier du projet Compilateur LSD010.
Ce fichier est situé dans /var/www/bin/sniplets/lsd010/.

Projet Compilateur LSD010 :

Compilateur LSD010 développé dans le cadre du cours de syntaxe et sémantiqueref 1

Code source ou contenu du fichier

  1. /*
  2.  * hashCode.c : Implementation to get int value from a node
  3.  * Part of the compiler project for LSD10 language
  4.  * Gaudry Stéphane
  5.  * More information on http://www.gaudry.be/langages-table-des-symboles.html
  6.  * **********************************************************
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #if(VERBOSE_LEVEL<=DEB_E)
  13. #include <errno.h>
  14. #endif
  15. #include "common.h"
  16.  
  17. /*
  18.  * **********************************************************
  19.  * Internal business declarations
  20.  * **********************************************************
  21.  */
  22.  
  23. int maxVal = -1;
  24.  
  25. /*
  26.  * **********************************************************
  27.  * Internal business
  28.  * **********************************************************
  29.  */
  30. void checkMaxVal(char *file, int line)
  31. {
  32. if(maxVal==-1)
  33. {
  34. #if(VERBOSE_LEVEL<=DEB_E)
  35. {
  36. printMsg(DEB_E,"Upper boundary undefined, you must call \"setHashUpperBoundary\" before", file, line);
  37. printMsg(DEB_E, (char *)strerror(errno), file, line);
  38. }
  39. #endif
  40. //Failure of the compiler behavior, independent of the parsed code
  41. exit(EXIT_FAILURE);
  42. }
  43. }
  44.  
  45. /*
  46.  * **********************************************************
  47.  * Internal business hashcode algorithms alternatives
  48.  * **********************************************************
  49.  */
  50.  
  51. int getDragonHash(const char *cle)
  52. {
  53. // printf("\n; Compute hash for %s (%s,%d)", cle, __FILE__, __LINE__);
  54. const char *ptr = cle;
  55. int val = 0;
  56. while(*ptr!='\0')
  57. {
  58. int tmp;
  59. val = (val<<4)+(*ptr);
  60. if(tmp = (val & 0xF0000000))
  61. {
  62. val = val ^ (tmp >>24);
  63. val = val ^ tmp;
  64. }
  65. ptr++;
  66. }
  67. // printf("\n; Hash for %s = %d(%s,%d)", cle, val, __FILE__ ,__LINE__);
  68. return val;//%maxVal; don't use % because this is an internal function and the % is called once on the result
  69. }
  70. unsigned long getBernsteinHash(unsigned char *str)
  71. {
  72. unsigned long hash = 5381;
  73. while(*str!='\0')
  74. {
  75. int c = *str;
  76. hash = (hash << 5 ) + c;
  77. str++;
  78. }
  79. return hash;
  80. }
  81. //unsigned int getDJBHash(const char *str)
  82. //{
  83. // unsigned int hash = 5381; // DJB Hash
  84. // const char *s;
  85. // for (s = str; *s; s++) {
  86. // hash = ((hash << 5) + hash) + tolower(*s);
  87. // }
  88. // return (hash & 0x7FFFFFFF)%maxVal;
  89. //}
  90.  
  91. /*
  92.  * **********************************************************
  93.  * Implementation of the header exposed items
  94.  * See hashCode.h for these functions comments
  95.  * **********************************************************
  96.  */
  97. void setHashUpperBoundary(int _maxVal)
  98. {
  99. if(_maxVal==-1)
  100. {
  101. #if(VERBOSE_LEVEL<=DEB_E)
  102. {
  103. printMsg(DEB_E,"Upper boundary must be > 0", __FILE__, __LINE__);
  104. printMsg(DEB_E, (char *)strerror(errno), __FILE__, __LINE__);
  105. }
  106. #endif
  107. //Failure of the compiler behavior, independent of the parsed code
  108. exit(EXIT_FAILURE);
  109. }
  110. maxVal = _maxVal;
  111. }
  112. int getHashCode(char *identifier)
  113. {
  114. checkMaxVal(__FILE__, __LINE__);
  115. return getDragonHash(identifier)%maxVal;
  116. }
  117. int getASTHashCode(AstNode *astNodePtr)
  118. {
  119. checkMaxVal(__FILE__, __LINE__);
  120. int hash = getDragonHash(astNodePtr->info->name);
  121. switch(astNodePtr->type)
  122. {
  123. /* functions overloading is not allowed for LSD010
  124. * ref: LSD010_7.2.6
  125. * otherwise, we may use something like that:
  126. * for each argument, add the int value of the argument type
  127. * astNodePtr =
  128. * fctHash += astNodePtr->info->type;
  129. */
  130.  
  131. /*
  132. * The only one allowed case of same names is the set of {function, var} for {declarationNode, existingNode}
  133. * ref: LSD010_7.2.5
  134. * Thus, adding 1 to the result produces different hash for vars and functions
  135. */
  136. case NODE_TYPE_FUNCTION:
  137. case NODE_TYPE_FUNCTION_CALL:
  138. hash+=1;
  139. break;
  140. }
  141. #if(VERBOSE_LEVEL<=DEB_SYM)
  142. "\n;Hash for %s=%d[final %d] (compiler %s, %d)",
  143. astNodePtr->info->name,
  144. hash,
  145. (hash<0)?(maxVal-hash)%maxVal:hash%maxVal,
  146. __FILE__,
  147. __LINE__
  148. );
  149. #endif
  150. if(hash<0)
  151. {
  152. hash=maxVal-hash;
  153. }
  154. return hash%maxVal;
  155. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/lsd010/project/source/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1715363917 10/05/2024 19:58:37
Fichiers contenus dans /var/www/bin/sniplets/lsd010/project/source/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .o|.ographVizHelper.o4.72 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .c|.cast.c27.73 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hconst.h4.01 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .c|.cy.tab.c84.53 Ko31/10/2018 18:32:39-refusé-
Afficher le fichier .y|.ylsd10.y22.88 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .o|.olex.yy.o18.88 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .c|.cscopeStack.c3.69 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hgraphVizHelper.h573 octets31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hsymbolsTableDataRepresentation.h1.31 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .o|.osymbolsTable.o5.2 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hcommon.h1.08 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .c|.cscopeHelper.c4.09 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .o|.ohashCode.o1.45 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hconsole.h2.21 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .o|.oconsole.o12.23 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .|lsd10lsd1075.26 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hhashCode.h1020 octets31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hsymbolsTable.h2.65 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hpcode.h417 octets31/10/2018 18:32:38-refusé-
Afficher le fichier .o|.oast.o11.45 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hscopeStack.h2.2 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .c|.cgraphVizHelper.c6.11 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .l|.llsd10.l6.46 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hy.tab.h4.69 Ko31/10/2018 18:32:39-refusé-
Afficher le fichier .output|.outputy.output81.69 Ko31/10/2018 18:32:39-refusé-
Afficher le fichier .o|.oy.tab.o24.45 Ko31/10/2018 18:32:39-refusé-
Afficher le fichier .c|.clex.yy.c57.93 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hast.h2.39 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .o|.oscopeStack.o1.34 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .o|.oscopeHelper.o2.59 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .h|.hastDataRepresentation.h1.87 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .c|.csymbolsTable.c14.91 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .c|.cpcode.c23.45 Ko31/10/2018 18:32:38-refusé-
Afficher le fichier .c|.chashCode.c3.94 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .c|.cconsole.c18.01 Ko31/10/2018 18:32:37-refusé-
Afficher le fichier .h|.hscopeHelper.h719 octets31/10/2018 18:32:38-refusé-

Warnung

Ce code présente une manière possible d'implémenter un compilateur, et certains choix peuvent être discutés.
Cependant, il peut donner des pistes pour démarrer, ou approcher certains concepts, et je tenterais par la suite de mettre à jour le code.

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 07/03/2010, zuletzt geändert 28/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/langages-lsd10-source-rf-project/source//hashCode.c.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Aufzeichnungen

  1. a,b LSD010 : Langage Simple et Didactique Il existe une un certain nombre d'interprétations de l'acronyme LSD (Langage Symbolique Didactique, Langage Sans Difficulté, Langage Simple et Didactique). LSD010 est la version 2010 de la suite LSD80, LSD_02, LSD03, LSD04, LSD05, LSD06, LSD07, LSD08, et LSD09.

Inhaltsverzeichnis Haut

Referenzen

  1. Buch Sprache des Dokuments:fr IHDCB332 - Théorie des langages : Syntaxe et sémantique : PY Schobbens, Syntaxe et sémantique (January 2010)

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut