Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

scopeStack.c

Description du code

scopeStack.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.  * scopeStack.c : Implementation to manage a stack of scopes
  3.  * for a declaration symbol and his re-declarations
  4.  * Part of the compiler project for LSD10 language
  5.  * Gaudry Stéphane
  6.  * More information on http://www.gaudry.be/langages-lex-yacc-intro.html
  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 "scopeStack.h"
  16. #include "common.h"
  17.  
  18.  
  19. /*
  20.  * **********************************************************
  21.  * Internal business
  22.  * **********************************************************
  23.  */
  24.  
  25.  
  26. /*
  27.  * **********************************************************
  28.  * Implementation of the header exposed items
  29.  * See scopeStack.h for these functions comments
  30.  * **********************************************************
  31.  */
  32.  
  33. ScopeStack* createScopeStack()
  34. {
  35. ScopeStack *newScopeStack = malloc( sizeof(*newScopeStack) );
  36. if(newScopeStack==NULL)
  37. {
  38. #if(VERBOSE_LEVEL<=DEB_E)
  39. {
  40. printMsg(DEB_E,"Allocation Error(ScopeStack)", __FILE__, __LINE__);
  41. printMsg(DEB_E, (char *)strerror(errno), __FILE__, __LINE__);
  42. }
  43. #endif
  44. //Failure of the compiler behavior, independent of the parsed code
  45. exit(EXIT_FAILURE);
  46. }
  47. newScopeStack->parentPtr=NULL;
  48. newScopeStack->usage=VAR_USAGE_NEVER;
  49. newScopeStack->declarationNode = NULL;
  50. newScopeStack->functionNode=NULL;
  51. return newScopeStack;
  52. }
  53.  
  54. void finalizeScopeStack(ScopeStack **scopeStackPtr)
  55. {
  56. while(*scopeStackPtr)
  57. {
  58. popScopeStack(scopeStackPtr);
  59. }
  60. }
  61.  
  62. void pushScopesStack(ScopeStack **scopeStackPtr, int scope, AstNode *declarationNode)
  63. {
  64. ScopeStack *tempScopeStackPtr = createScopeStack();
  65.  
  66. // char msg[1024];//todo: minimize length
  67. // sprintf(
  68. // msg,
  69. // "Push scope : %d [15%p] => %s (compiler %s,%d)",
  70. // scope, tempScopeStackPtr, declarationNode==NULL?"node null":declarationNode->info->name,
  71. // __FILE__,
  72. // __LINE__
  73. // );
  74. // printMsg(DEB_EXEC, msg, __FILE__, __LINE__);
  75.  
  76. tempScopeStackPtr->declarationNode = declarationNode;
  77. if(declarationNode!=NULL)
  78. {
  79. declarationNode->info->scopeId = scope;
  80. declarationNode->info->scopeDepth = scopeHelperGetCurrentDepth();
  81. }
  82. tempScopeStackPtr->parentPtr=*scopeStackPtr;
  83. *scopeStackPtr = tempScopeStackPtr;
  84. }
  85.  
  86. AstNode* popScopeStack(ScopeStack **scopeStackPtr)
  87. {
  88. if(!*scopeStackPtr)
  89. {
  90. return NULL;
  91. }
  92.  
  93. // char msg[1024];//todo: minimize length
  94. // sprintf(
  95. // msg,
  96. // "\tBefore Pop scope : %d [15%p] => %s (compiler %s,%d)",
  97. // (*scopeStackPtr)->scopeId,
  98. // (*scopeStackPtr),
  99. // returnVal==NULL?"node null":returnVal->info->name,
  100. // __FILE__,
  101. // __LINE__
  102. // );
  103. // printMsg(DEB_EXEC, msg, __FILE__, __LINE__);
  104.  
  105. ScopeStack *top = *scopeStackPtr;
  106. AstNode *returnVal = top->declarationNode;
  107. *scopeStackPtr = top->parentPtr;
  108. free(top);
  109.  
  110. // sprintf(
  111. // msg,
  112. // "\tAfter Pop scope : %d [15%p] => %s (compiler %s,%d)",
  113. // (*scopeStackPtr)==NULL?INITIAL_INT:(*scopeStackPtr)->scopeId,
  114. // (*scopeStackPtr),
  115. // returnVal==NULL?"node null":returnVal->info->name,
  116. // __FILE__,
  117. // __LINE__
  118. // );
  119. // printMsg(DEB_EXEC, msg, __FILE__, __LINE__);
  120.  
  121. return returnVal;
  122. }
  123.  
  124. void setScopesStackDepth(ScopeStack *scopeStack, int scopeDepth)
  125. {
  126. scopeStack->declarationNode->info->scopeDepth=scopeDepth;
  127. }
  128. int getScopeDepth(ScopeStack *scopeStack)
  129. {
  130. if(scopeStack==NULL)
  131. {
  132. // printf("\n; scopeStack null (compiler %s, %d)\n", __FILE__, __LINE__);
  133. return ERROR_INT;
  134. }
  135. if(scopeStack->declarationNode==NULL)
  136. {
  137. // printf("\n; declaration node null (compiler %s, %d)\n", __FILE__, __LINE__);
  138. return ERROR_INT;
  139. }
  140. return scopeStack->declarationNode->info->scopeId;
  141. }

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 octets1714300231 28/04/2024 12:30:31
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é-

Waarschuwing

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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 07/03/2010 gemaakt, de laatste keer de 28/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/langages-lsd10-source-rf-project/source//scopeStack.c.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Notes

  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.

Inhoudsopgave Haut

Referenties

  1. boek Taal van het document:fr IHDCB332 - Théorie des langages : Syntaxe et sémantique : PY Schobbens, Syntaxe et sémantique (January 2010)

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut