No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

scopeHelper.c

Description du code

scopeHelper.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 the compilation scope
  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. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #if(VERBOSE_LEVEL<=DEB_E)
  12. #include <errno.h>
  13. #endif
  14. #include "scopeStack.h"
  15. #include "scopeHelper.h"
  16. #include "common.h"
  17.  
  18. /*
  19.  * **********************************************************
  20.  * Internal business
  21.  * **********************************************************
  22.  */
  23.  
  24. ScopeStack *scopeStackPtr;
  25.  
  26. /**
  27.  * Incremental identifier of the scope
  28.  */
  29. int scopeId=INITIAL_INT;
  30.  
  31. /**
  32.  * Depth of the scope
  33.  */
  34. int scopeDepth=INITIAL_INT;
  35.  
  36. /**
  37.  * Exits with a failure level if the scopeHelper
  38.  * is not able to perform the operation
  39.  */
  40. void scopeHelperCheckIntegrity(char *file, int line)
  41. {
  42. if(scopeStackPtr==NULL)
  43. {
  44. #if(VERBOSE_LEVEL<=DEB_E)
  45. {
  46. printMsg(DEB_E,"Illegal operation (read on uninitialized stack)", file, line);
  47. printMsg(DEB_E, (char *)strerror(errno), __FILE__, __LINE__);
  48. }
  49. #endif
  50. //Failure of the compiler behavior, independent of the parsed code
  51. exit(EXIT_FAILURE);
  52. }
  53. }
  54. /**
  55.  * Creates a new fictive ASTNode to store depth and scope information on the stack
  56.  */
  57. AstNode *getScopeHelperNewNode()
  58. {
  59. return createASTNode(
  60. NULL,
  61. NODE_TYPE_NOTHING,
  62. createASTNodeInfo(NO_NAME, NODE_TYPE_NOTHING, INITIAL_INT),
  63. NULL,
  64. NULL );
  65. }
  66.  
  67. /*
  68.  * **********************************************************
  69.  * Implementation of the header exposed items
  70.  * See scopeHelper.h for these functions comments
  71.  * **********************************************************
  72.  */
  73.  
  74. void scopeHelperSetCurrentFunction(AstNode *currentFunctionNode)
  75. {
  76. #if(VERBOSE_LEVEL<=DEB_SYM)
  77. "\n;\tSet current function : %s (compiler %s %d)",
  78. currentFunctionNode->info->name,
  79. __FILE__,
  80. __LINE__
  81. );
  82. #endif
  83. scopeStackPtr->functionNode=currentFunctionNode;
  84. }
  85. AstNode* scopeHelperGetCurrentFunction()
  86. {
  87. return scopeStackPtr->functionNode;
  88. }
  89. void scopeHelperEnterScope()
  90. {
  91. ++scopeId;
  92. ++scopeDepth;
  93. pushScopesStack(&scopeStackPtr, scopeId, getScopeHelperNewNode());
  94. //setScopesStackDepth(scopeStackPtr, scopeDepth);
  95. printSymbolsTableItem("Entrée dans la portée");
  96. #if(VERBOSE_LEVEL<=DEB_SYM)
  97. "\n;\tenter scope %d; ast=%s",
  98. getScopeDepth(scopeStackPtr),
  99. scopeStackPtr->declarationNode==NULL?"null":"ok"
  100. );
  101. #endif
  102. }
  103. void scopeHelperExitScope()
  104. {
  105. #if(VERBOSE_LEVEL<=DEB_SYM)
  106. "\n;\texit scope %d, return to %d(%s)",
  107. getScopeDepth(scopeStackPtr),
  108. getScopeDepth(scopeStackPtr==NULL?scopeStackPtr:scopeStackPtr->parentPtr),
  109. scopeStackPtr->parentPtr==NULL||scopeStackPtr->parentPtr->functionNode==NULL ?
  110. "?":
  111. scopeStackPtr->parentPtr->functionNode->info->name
  112. );
  113. #endif
  114. popScopeStack(&scopeStackPtr);
  115. --scopeDepth;
  116. printSymbolsTableItem("Sortie de la portée; déclarations non supprimées de la table");
  117. }
  118. int scopeHelperGetCurrentScope()
  119. {
  120. scopeHelperCheckIntegrity (__FILE__, __LINE__);
  121. return getScopeDepth(scopeStackPtr);
  122. }
  123. int scopeHelperGetCurrentDepth()
  124. {
  125. return scopeDepth;
  126. }
  127. int scopeHelperGetParentScope()
  128. {
  129. scopeHelperCheckIntegrity(__FILE__, __LINE__);
  130. return getScopeDepth(scopeStackPtr==NULL?scopeStackPtr:scopeStackPtr->parentPtr);
  131. }
  132. void resetScopeHelper()
  133. {
  134. #if(VERBOSE_LEVEL<=DEB_SYM)
  135. printf("\n;\n;\tReset scope helper");
  136. #endif
  137. if(scopeStackPtr!=NULL)
  138. {
  139. scopeStackPtr->functionNode = NULL;
  140. }
  141. scopeId= INITIAL_INT;
  142. scopeDepth= INITIAL_INT;
  143. }
  144. void initializeScopeHelper()
  145. {
  146. scopeStackPtr=createScopeStack();
  147. scopeStackPtr->declarationNode = getScopeHelperNewNode();
  148. scopeStackPtr->declarationNode->info->scopeId = INITIAL_INT;
  149. scopeStackPtr->declarationNode->info->scopeDepth = INITIAL_INT;
  150. resetScopeHelper();
  151. }
  152. void finalizeScopeHelper()
  153. {
  154. resetScopeHelper();
  155. if(scopeStackPtr!=NULL)
  156. {
  157. finalizeScopeStack(&scopeStackPtr);
  158. }
  159. }

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 octets1715192044 08/05/2024 20:14:04
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é-

Warning

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.

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 07/03/2010, last modified the 28/10/2018
Source of the printed document:https://www.gaudry.be/en/langages-lsd10-source-rf-project/source/scopeHelper.c.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

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.

Contents Haut

References

  1. book Language of the document:fr IHDCB332 - Théorie des langages : Syntaxe et sémantique : PY Schobbens, Syntaxe et sémantique (January 2010)

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut