graphVizHelper.c
Description du code
graphVizHelper.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
Code c (graphVizHelper.c) (235 lignes)
/* * graphVizHelper.c : Helper for the graphViz tool (generation of images from a tree) * @see http://www.graphviz.org/doc/info/command.html * Part of the compiler project for LSD10 language * Gaudry Stéphane * More information on http://www.gaudry.be/programmer-arbre-image-noeuds.html */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "common.h" #include "graphVizHelper.h" #include "y.tab.h" #if(VERBOSE_LEVEL<=DEB_E) #include <errno.h> #endif extern AstNode *rootNode; /* * ********************************************************** * Internal business * ********************************************************** */ #define GRAPH_RIGHT 0 #define GRAPH_LEFT 1 #define GRAPH_ROOT -1 int isGraphVisInstalled() { return 1;//todo : get it dynamically } /** * http://www.graphviz.org/doc/info/command.html */ void generateImage(char *dotFileName) { time_t now; struct tm *timeinfo; char commandString[100]; //todo : set the timeinfo int values on a 2 digits format commandString, "%slsd10_Img%d%d%d%d%d%d.jpg %s", "dot -Tjpg -o", timeinfo->tm_year+1900, timeinfo->tm_mon+1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, dotFileName); int ret = 0; //printf ("ret = %d\n", ret); } void printGraphDotHeader(FILE * graphFile) { if(graphFile!=NULL) { } } void printGraphDotFooter(FILE * graphFile) { if(graphFile!=NULL) { time_t now; struct tm *timeinfo; // fprintf(graphFile, "}\n"); // fprintf(graphFile, "digraph INFO{\n"); graphFile, "\t\"Generated by the SSHD09 LSD010 compiler\\n%d/%d/%d %dHr %d\\nWith GraphViz engine\" [", timeinfo->tm_mday, timeinfo->tm_mon+1, timeinfo->tm_year+1900, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec ); } } /** * Prints an AST node into the graph file * Pre-condition : dotFile not null */ void printGraphNode(FILE *dotFile, AstNode *node, int depth, int psn) { if(node!=NULL) { if(node->parent!=NULL) { } else { } dotFile, "\"%p\";\n\t\"%p\" [shape=%s, color=\"%s\", fontcolor=\"%s\", label=\"%s%s%s%s : \\n%s %s\\nLine %d char %d\"];\n",//print position? node, node, //node->type>LEX_FIRST_TOKEN&&node->type<LEX_LAST_TOKEN?"polygon":"box", psn==GRAPH_LEFT?"hexagon":(psn==GRAPH_RIGHT?"box":"doublecircle"), (node->type==NODE_TYPE_DECLARATION || node->type==NODE_TYPE_FUNCTION || node->type==NODE_TYPE_PARAM_DECL )?"#677E96":psn==GRAPH_LEFT?"#e6e8f2":(psn==GRAPH_RIGHT?"#AAB5C6":"#C0C0C0"), (node->type==NODE_TYPE_DECLARATION || node->type==NODE_TYPE_FUNCTION || node->type==NODE_TYPE_PARAM_DECL )?"#FFFFFF":"#000000", typeToString(node->type), node->subtype!=NODE_TYPE_NOTHING?" (":"", node->subtype!=NODE_TYPE_NOTHING?typeToString(node->subtype):"", node->subtype!=NODE_TYPE_NOTHING?")":"", typeToString(node->info->type), node->info->name, node->debug->line, node->debug->linePsn ); printGraphNode(dotFile, node->left, depth+1, GRAPH_LEFT); printGraphNode(dotFile, node->right, depth+1, GRAPH_RIGHT); } //else fprintf(dotFile, "null"); } void printGraphDotFromXML(char *xmlFileName, char *dotFileName) { FILE * graphFile; if(xmlFileName==NULL)xmlFileName=AST_XML_FILE; if(dotFileName==NULL)dotFileName=GRAPHVIZ_CONFIG_FILE; if(graphFile!=NULL) { printf("\n;\tGenerating AST Graph from %s into %s file ... (%s, col %d)", xmlFileName, dotFileName, __FILE__, __LINE__); printGraphDotHeader(graphFile); //todo : read info from XML file to generate the dot file printGraphDotFooter(graphFile); #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"...OK Graph printed", __FILE__, __LINE__); #endif if(isGraphVisInstalled()==1) { generateImage(dotFileName); } } else { #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"Printing AST into Graph file ... Can't open file", __FILE__, __LINE__); #endif } } void printGraphDotFromAST(char *dotFileName) { FILE * graphFile; if(dotFileName==NULL)dotFileName=GRAPHVIZ_CONFIG_FILE; if(graphFile!=NULL) { printf("\n;\tGenerating AST Graph from last compilation into %s file ... (%s, col %d)", dotFileName, __FILE__, __LINE__); printGraphDotHeader(graphFile); printGraphNode(graphFile, rootNode, 0, GRAPH_ROOT); printGraphDotFooter(graphFile); #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"...OK Graph printed", __FILE__, __LINE__); #endif } else { #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"Printing AST into Graph file ... Can't open file", __FILE__, __LINE__); #endif } } /* * ********************************************************** * Implementation of the header exposed items * See graphVizHelper.h for these functions comments * ********************************************************** */ void printGraph() { printGraphDotFromAST(GRAPHVIZ_CONFIG_FILE); if(isGraphVisInstalled()==1) { generateImage(GRAPHVIZ_CONFIG_FILE); } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732319742 23/11/2024 00:55:42 |
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/graphVizHelper.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.
- ↑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.
References
- 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.