pcode.c
Description du code
pcode.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 (pcode.c) (823 lignes)
/* * pcode.c : generation of p-code * Part of the compiler project for LSD10 language * Gaudry Stéphane * More information on http://www.gaudry.be/langages-pcode.html */ #include <stdio.h> #include <stdlib.h> #if(VERBOSE_LEVEL<=DEB_E) #include <errno.h> #endif #include "common.h" #include "y.tab.h" /* * ********************************************************** * Internal business implementations * ********************************************************** */ extern int num_lines; extern char* yytext; extern int *yylineno; extern AstNode *rootNode; FILE* pcodeFile; #define RESERVED_MEM 5 int pcodeGenValue(AstNode *node); /** * Wrapper function to get location * This calls table of symbols method, and compute shift for reserved memory * Internal business */ int getShiftedMemoryLocation(AstNode *node) { if (node == NULL || !isSymbolsTableAvailable()) { onError("AST node and Table of Symbols must not be NULL", __FILE__, __LINE__, node); //Failure of the compiler behavior, independent of the parsed code } int location=INITIAL_INT; switch(node->type) { case LEXICAL_RETURN_STMT: location=RESERVED_MEM; break; case NODE_TYPE_FUNCTION_CALL: location = getDeclarationMemoryLocation(node)+RESERVED_MEM; location += node->info->scopeDepth>1?RESERVED_MEM:1; break; default: location = getDeclarationMemoryLocation(node); if(location<0)location=0; //if( node->info->scopeDepth>=1)location += RESERVED_MEM; break; } return location; } /** * Returns the depth difference between the call node and the declaration node * @see IHDCB332 séance 1.pdf "Laboratoire LSD010" slide 40 */ int getDepthDiff(AstNode *node) { AstNode *declaration = getDeclaration(node); // printPCode( // pcodeFile, // ";\t%s depth %d, declaration depth=%d\n", // node->info->name, // node->info->scopeDepth, // declaration->info->scopeDepth // ); int locationDiff = (node->info->scopeDepth - declaration->info->scopeDepth)-1; return locationDiff<0?0:locationDiff; } void printLoad(int type, int depthDiff, int location) { switch(type) { case AST_INTEGER_VAR_TYPE: printPCode(pcodeFile, "lda i %d %d\n", depthDiff, location); break; case AST_BOOLEAN_VAR_TYPE: printPCode(pcodeFile, "lda b %d %d\n", depthDiff, location); break; case AST_INSTACK_VAR_TYPE: //@todo: by val, by address //printPCode(pcodeFile, "lda a %d %d\n", getDepthDiff(node), location+RESERVED_MEM); break; } } int pcodeGenAddress(AstNode *node) { if (node == NULL) { return 0; } if(!isSymbolsTableAvailable()) { onError("Table of Symbols must not be NULL", __FILE__, __LINE__, node); //Failure of the compiler behavior, independent of the parsed code } // printPCode(pcodeFile, ";\tGenerate address for node %s\n", node->info->name); int location; int depthDiff = 0; switch (node->type) { case NODE_TYPE_ID: location = getShiftedMemoryLocation(node); depthDiff=getDepthDiff(node); printPCode(pcodeFile, ";\tGenerate address for %s variable\n",node->info->name); printLoad(node->info->computedType, depthDiff, location+RESERVED_MEM); break; // case LEXICAL_RETURN_STMT: // printPCode(pcodeFile, ";\tStart generate address for return statement\n"); // location = getShiftedMemoryLocation(node); // printLoad(node->info->computedType, depthDiff, location); // switch(node->info->computedType) // { // case AST_INTEGER_VAR_TYPE: // printPCode(pcodeFile, "ind i\n"); // printPCode(pcodeFile, "sto i\n"); // break; // case AST_BOOLEAN_VAR_TYPE: // printPCode(pcodeFile, "ind b\n"); // printPCode(pcodeFile, "sto b\n"); // break; // } // printPCode(pcodeFile, ";\tEnd generate address for return statement\n"); // break; } return 0; } /** * */ void pcodeGenParam(AstNode *node) { // printPCode( // pcodeFile, // ";\tGenerate %s Parameter (compiler %s, %d)\n", // node->info->name, // __FILE__, // __LINE__ // ); switch(node->subtype) { case LEXICAL_VAR://NODE_DECL_PADR: pcodeGenAddress(node); break; default://case NODE_DECL_PVAL: pcodeGenValue(node); break; /* * case stack by val : * pcodeGenValue(node); * printPCode(pcodeFile, "ind a"); */ } } /** * Recursive method to produce p-code from AST */ int pcodeGenValue(AstNode *node) { int location = INITIAL_INT; static int staticLabel = 0; int label = staticLabel; int rightLabel = INITIAL_INT; int leftLabel = INITIAL_INT; staticLabel++; if (node == NULL){ return EXIT_SUCCESS; } if(!isSymbolsTableAvailable()) { onError("Table of Symbols must not be NULL", __FILE__, __LINE__, NULL); //Failure of the compiler behavior, independent of the parsed code } char str[1024];//todo: minimize length #if(VERBOSE_LEVEL<=DEB_P) str, "pcodeGenValue %s (%d) (%s, line %d)", typeToString(node->type), node->type, node->debug->file, node->debug->line ); printMsg(DEB_P, str, __FILE__, __LINE__); #endif // printPCode(pcodeFile, ";\tGenerate value for node %s\n", node->info->name); // printf( // ";\n;\tp-code : %s (%s, %s) line %d col %d (compiler %s, %d)\n", // node->info->name, // typeToString(node->type), // typeToString(node->subtype), // node->debug->line, // node->debug->linePsn, // __FILE__, // __LINE__ // ); switch (node->type) { case NUMBER: printPCode(pcodeFile, ";\t---Generate value for %d integer constant\n",node->info->value); printPCode(pcodeFile, "ldc i %d\n", node->info->value); break; case LEXICAL_TRUE_VAL: printPCode(pcodeFile, ";\t---Generate value for true boolean constant\n"); printPCode(pcodeFile, "ldc b 1\n"); break; case LEXICAL_FALSE_VAL: printPCode(pcodeFile, ";\t---Generate value for false boolean constant\n",node->info->value); printPCode(pcodeFile, "ldc b 0\n"); break; case NODE_TYPE_FUNCTIONS: //function pcodeGenValue(node->right); //functions pcodeGenValue(node->left); break; case NODE_TYPE_FUNCTION: printPCode(pcodeFile, ";\tStart of %s function\n",node->info->name); location = getShiftedMemoryLocation(node); printPCode(pcodeFile, "define @fct_%s_%d\n",node->info->name,location); //int varsCount=getDeclarationsMemoryUpperBound(); AstNode *arg = node->left; int varsCount=0; //get params count while(arg!=NULL) { switch(arg->type) { case NODE_TYPE_PARAM_LIST: varsCount++; arg=arg->right; break; case NODE_TYPE_PARAM: varsCount++; arg=NULL; break; default: arg=NULL; } } arg=node->right; //get declarations count while(arg!=NULL) { switch(arg->type) { case NODE_TYPE_CONTAINER: if( arg->left!=NULL && (arg->left->type==NODE_TYPE_DECLARATIONS||arg->left->type==NODE_TYPE_VAR_DECL) ) { arg=arg->left; } else { arg=NULL; } break; case NODE_TYPE_DECLARATIONS: if(arg->left!=NULL && arg->left->type==NODE_TYPE_VAR_DECL) { varsCount++; } arg=arg->right; break; case NODE_TYPE_VAR_DECL: varsCount++; arg=NULL; break; default: arg=NULL; } } printPCode(pcodeFile, "ssp %d\n",varsCount+RESERVED_MEM); printPCode(pcodeFile, "ujp @fct_body_%s_%d\n",node->info->name, location); pcodeGenValue(node->left); printPCode(pcodeFile, "define @fct_body_%s_%d\n",node->info->name,location); printPCode(pcodeFile, "lda i %d %d\n", 0, 0);//args= {diff, rel addr} ?? pcodeGenValue(node->right); if(node->info->returnStatement!=NULL) { printPCode(pcodeFile, ";\tReturn\n"); // pcodeGenAddress(node->info->returnStatement); switch (node->info->returnStatement->info->computedType) { case AST_INTEGER_VAR_TYPE: printPCode(pcodeFile, "sto i\n"); break; case AST_BOOLEAN_VAR_TYPE: printPCode(pcodeFile, "sto b\n"); break; case AST_INSTACK_VAR_TYPE: printPCode(pcodeFile, "sto a\n"); break; default: onNotIntegerNotBooleanTypeError(node, __FILE__, __LINE__); break; } printPCode(pcodeFile, "retf\n"); } printPCode(pcodeFile, "retf\n"); printPCode(pcodeFile, ";\tEnd of %s function\n",node->info->name); break; case NODE_TYPE_FUNCTION_CALL: { printPCode(pcodeFile, ";\t---%s function call\n",node->info->name); printPCode(pcodeFile, "mst %d\n", getDepthDiff(node)); AstNode *arg = node->left; int paramsCount=0; while(arg!=NULL) { switch(arg->type) { case NODE_TYPE_PARAM_LIST: pcodeGenParam(arg->left); paramsCount++; arg=arg->right; break; case NODE_TYPE_PARAM: pcodeGenParam(arg); paramsCount++; arg=NULL; break; default: // These types are the only allowed types for parameters // Must trigger an error here? arg=NULL; } } // printPCode( pcodeFile, "cup %d @fct_%s_%d\n", paramsCount, node->info->name, getShiftedMemoryLocation(node->info->declarationNode) ); } break; case NODE_TYPE_REXP: // printf( // ";\n;\t*************tp-code %s =>%s=> %sline %d col %d (compiler %s, %d)\n", // node->left==NULL?"NULL":node->left->info->name, // typeToString(node->subtype), // node->right==NULL?"NULL":node->right->info->name, // node->debug->line, // node->debug->linePsn, // __FILE__, // __LINE__ // ); switch(node->subtype) { //Integer operations case LEXICAL_PLUS: printPCode(pcodeFile, ";\t---Start + operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "add i\n"); printPCode(pcodeFile, ";\t---Start + operation\n"); break; case LEXICAL_MINUS: printPCode(pcodeFile, ";\t---Start - operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "sub i\n"); printPCode(pcodeFile, ";\t---Start - operation\n"); break; case LEXICAL_MULT: printPCode(pcodeFile, ";\t---Start * operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "mul i\n"); printPCode(pcodeFile, ";\t---Start * operation\n"); break; case LEXICAL_DIV: printPCode(pcodeFile, ";\t---Start DIV operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "ldc i 0\n"); printPCode(pcodeFile, "equ i\n"); printPCode(pcodeFile, "fjp @div_%d\n", label); /* here left == 0 */ printPCode(pcodeFile, ";\tdiv division by 0 !!\n"); printPCode(pcodeFile, "stp\n"); /* else left != 0 */ printPCode(pcodeFile, ";\tbegin of div\n"); printPCode(pcodeFile, "define @div_%d\n",label); label++; pcodeGenValue(node->right); printPCode(pcodeFile, "div i\n"); printPCode(pcodeFile, ";\t---Start DIV operation\n"); break; case LEXICAL_MOD: { printPCode(pcodeFile, ";\t---Start mod operation (b mod a)\n"); int modLeft=5; int modRight=6; printPCode(pcodeFile, "lda i 0 %d\n",modLeft); pcodeGenValue(node->right); printPCode(pcodeFile, "sto i\n"); printPCode(pcodeFile, "lda i 0 %d\n",modRight); pcodeGenValue(node->left); printPCode(pcodeFile, "sto i\n"); printPCode(pcodeFile, ";\tchecks if b == 0\n"); printPCode(pcodeFile, "lda i 0 %d\n",modLeft); printPCode(pcodeFile, "ind i\n"); printPCode(pcodeFile, "ldc i 0\n"); printPCode(pcodeFile, "equ i\n"); printPCode(pcodeFile, "fjp @mod_%d\n", label); /* here left == 0 */ printPCode(pcodeFile, ";\tmod division by 0 !!\n"); printPCode(pcodeFile, "stp\n"); /* else left != 0 */ printPCode(pcodeFile, "define @mod_%d\n",label); label++; //load left printPCode(pcodeFile, "lda i 0 %d\n",modRight); printPCode(pcodeFile, "ind i\n"); printPCode(pcodeFile, "lda i 0 %d\n",modRight); printPCode(pcodeFile, "ind i\n"); printPCode(pcodeFile, "lda i 0 %d\n",modLeft); printPCode(pcodeFile, "ind i\n"); printPCode(pcodeFile, "div i\n"); printPCode(pcodeFile, "lda i 0 %d\n",modLeft); printPCode(pcodeFile, "ind i\n"); printPCode(pcodeFile, "mul i\n"); printPCode(pcodeFile, "sub i\n"); printPCode(pcodeFile, ";\t---Start MOD operation\n"); } break; //Boolean operations case LEXICAL_EQUALS: printPCode(pcodeFile, ";\t---Start == operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "equ b\n"); printPCode(pcodeFile, ";\t---Start == operation\n"); break; case LEXICAL_LESS_EQUALS: printPCode(pcodeFile, ";\t---Start <= operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "leq b\n"); printPCode(pcodeFile, ";\t---Start <= operation\n"); break; case LEXICAL_LESS: printPCode(pcodeFile, ";\t---Start < operation\n"); pcodeGenValue(node->left); pcodeGenValue(node->right); printPCode(pcodeFile, "les b\n"); printPCode(pcodeFile, ";\t---Start < operation\n"); break; case LEXICAL_ANDLAZY: printPCode(pcodeFile, ";\t---Start & operation\n"); leftLabel = staticLabel++; rightLabel = staticLabel++; pcodeGenValue(node->left); //set condition for the false jump(exp_1) pcodeGenValue(node->left); char andLazy[7+1] = "andLazy"; printPCode(pcodeFile, "fjp @%s%d\n", andLazy, leftLabel); pcodeGenValue(node->right); printPCode(pcodeFile, "and b\n"); printPCode(pcodeFile, "define @%s%d\n", andLazy, leftLabel); printPCode(pcodeFile, ";\t---Start & operation\n"); break; case LEXICAL_AND: printPCode(pcodeFile, ";\t---Start && operation\n"); pcodeGenValue(node->right); pcodeGenValue(node->left); printPCode(pcodeFile, "and b\n"); printPCode(pcodeFile, ";\t---Start && operation\n"); break; case LEXICAL_ORLAZY: printPCode(pcodeFile, ";\t---Start | operation\n"); leftLabel = staticLabel++; rightLabel = staticLabel++; pcodeGenValue(node->left); //set condition for the false jump(exp_1) pcodeGenValue(node->left); printPCode(pcodeFile, "not b\n"); char orLazy[6+1] = "orLazy"; printPCode(pcodeFile, "fjp @%s%d\n", orLazy, leftLabel); pcodeGenValue(node->right); printPCode(pcodeFile, "or b\n"); printPCode(pcodeFile, "define @%s%d\n", orLazy, leftLabel); printPCode(pcodeFile, ";\t---Start | operation\n"); break; case LEXICAL_OR: printPCode(pcodeFile, ";\t---Start || operation\n"); pcodeGenValue(node->right); pcodeGenValue(node->left); printPCode(pcodeFile, "or b\n"); printPCode(pcodeFile, ";\t---Start || operation\n"); break; case LEXICAL_NOT: printPCode(pcodeFile, ";\t---NOT operation\n"); pcodeGenValue(node->right); printPCode(pcodeFile, "not b\n"); break; case LEXICAL_ISEMPTY_OPS : printPCode(pcodeFile, "ldc b 1\n"); break; default: pcodeGenValue(node->right); pcodeGenValue(node->left); break; } break; case NODE_TYPE_PARAM_DECL: { printPCode(pcodeFile, ";\t---Start %s param declaration\n",node->info->name); char nodeArgType[1+1];//because I have some problems with %c on printPCode char *pnodeArgType = nodeArgType; switch(node->info->computedType) { case AST_INTEGER_VAR_TYPE: pnodeArgType="i"; break; case AST_BOOLEAN_VAR_TYPE: pnodeArgType="b"; break; case AST_INSTACK_VAR_TYPE: pnodeArgType="a"; break; default: onNotIntegerNotBooleanTypeError(node, __FILE__, __LINE__); break; } char varInst[3+1]; char *varInstp=varInst; if( node->subtype==LEXICAL_VAR) { varInstp="lda"; } else if( node->subtype==ID) { varInstp="lod"; pnodeArgType="a"; } else { str, "Unsupported subtype %s (%d) for %s, only %s or %s are allowed (%s, line %d)", typeToString(node->subtype), node->type, node->info->name, typeToString(LEXICAL_VAR), typeToString(ID), node->debug->file, node->debug->line ); onError(str, __FILE__, __LINE__, node); //Failure of the compiler behavior, independent of the parsed code } printPCode(pcodeFile, "%s %s %d %d\n", varInstp, pnodeArgType, getDepthDiff(node), getShiftedMemoryLocation(node)); printPCode(pcodeFile, "ind %s\n", pnodeArgType); printPCode(pcodeFile, ";\t---End of %s param declaration\n",node->info->name); } break; case NODE_TYPE_ID: printPCode(pcodeFile, ";\t---%s id\n",node->info->name); pcodeGenAddress(node); switch (node->info->computedType) { case AST_INTEGER_VAR_TYPE: printPCode(pcodeFile, "ind i\n"); break; case AST_BOOLEAN_VAR_TYPE: printPCode(pcodeFile, "ind b\n"); break; case AST_INSTACK_VAR_TYPE: printPCode(pcodeFile, "ind a\n"); break; default: onNotIntegerNotBooleanTypeError(node, __FILE__, __LINE__); break; } break; // case LEXICAL_RETURN_STMT: // break; case NODE_TYPE_STATEMENT: switch(node->subtype) { case LEXICAL_AFFECTATION: printPCode(pcodeFile, ";\t---Start affectation\n"); pcodeGenAddress(node->left); //printPCode(pcodeFile, ";\tAFFECT right %d--%d\n",node->right->type,node->right->subtype); pcodeGenValue(node->right); switch (node->right->info->computedType) { case AST_INTEGER_VAR_TYPE: printPCode(pcodeFile, "sto i\n"); break; case AST_BOOLEAN_VAR_TYPE: printPCode(pcodeFile, "sto b\n"); break; case AST_INSTACK_VAR_TYPE: printPCode(pcodeFile, "sto a\n"); break; default: onNotIntegerNotBooleanTypeError(node, __FILE__, __LINE__); break; } printPCode(pcodeFile, ";\tEnd of affectation\n"); break; //Flow control operations case LEXICAL_IF_STMT: printPCode(pcodeFile, ";\t---Start if statement\n"); leftLabel = staticLabel++; rightLabel = staticLabel++; //set condition for the false jump pcodeGenValue(node->left); printPCode(pcodeFile, "fjp @endif_%d\n", leftLabel); pcodeGenValue(node->right); printPCode(pcodeFile, "define @endif_%d\n", leftLabel); printPCode(pcodeFile, ";\t---End of if statement\n"); break; case AST_IF_ELSE_STMT: printPCode(pcodeFile, ";\t---Start if...else... statement\n"); leftLabel = staticLabel++; rightLabel = staticLabel++; //set condition for the false jump pcodeGenValue(node->left); printPCode(pcodeFile, "fjp @then_%d\n", leftLabel); pcodeGenValue(node->right->left); printPCode(pcodeFile, "ujp @endif_%d\n", rightLabel); printPCode(pcodeFile, "define @then_%d\n", leftLabel); pcodeGenValue(node->right->right); printPCode(pcodeFile, "define @endif_%d\n", rightLabel); printPCode(pcodeFile, ";\t---End of if...else... statement\n"); break; case LEXICAL_FOR_STMT: printPCode(pcodeFile, ";\t---Start for statement\n"); // for(pre_instructions:condition:post_instructions_loop){instructions_loop} // is translated into // pre_instructions; while(condition){instructions_loop;post_instructions_loop} leftLabel = staticLabel++; rightLabel = staticLabel++; // pre_instructions if(node->right!=NULL && node->right->left!=NULL) { //printf("\n; FLEXICAL_OR statement pre_instructions (compiler %s, %d)",__FILE__,__LINE__); pcodeGenValue(node->right->left->left); } // while printPCode(pcodeFile, "define @for_%d\n", leftLabel); //set condition for the false jump pcodeGenValue(node->left); printPCode(pcodeFile, "fjp @endfor_%d\n", rightLabel); // instructions_loop if(node->right!=NULL) { //printf("\n; FLEXICAL_OR statement instructions_loop (compiler %s, %d)",__FILE__,__LINE__); pcodeGenValue(node->right->right); } // post_instructions_loop if(node->right!=NULL && node->right->left!=NULL) { //printf("\n; FLEXICAL_OR statement post_instructions_loop (compiler %s, %d)",__FILE__,__LINE__); pcodeGenValue(node->right->left->right); } printPCode(pcodeFile, "ujp @for_%d\n", leftLabel); printPCode(pcodeFile, "define @endfor_%d\n", rightLabel); printPCode(pcodeFile, ";\t---End of for statement\n"); break; case LEXICAL_WHILE_STMT: printPCode(pcodeFile, ";\t---Start while statement\n"); leftLabel = staticLabel++; rightLabel = staticLabel++; printPCode(pcodeFile, "define @while_%d\n", leftLabel); //set condition for the false jump pcodeGenValue(node->left); printPCode(pcodeFile, "fjp @endwhile_%d\n", rightLabel); pcodeGenValue(node->right); printPCode(pcodeFile, "ujp @while_%d\n", leftLabel); printPCode(pcodeFile, "define @endwhile_%d\n", rightLabel); printPCode(pcodeFile, ";\t---End of while statement\n"); break; default: pcodeGenValue(node->right); pcodeGenValue(node->left); break; } break; case LEXICAL_READ_OPS: printPCode(pcodeFile, ";\t---Start read operation\n"); pcodeGenAddress(node->right); printPCode(pcodeFile, "read\n"); //Only integer argument allowed for read (Spec. 6.2) printPCode(pcodeFile, "sto i\n"); printPCode(pcodeFile, ";\t---End of read operation\n"); break; case LEXICAL_WRITE_OPS: printPCode(pcodeFile, ";\t---Start write operation\n"); pcodeGenValue(node->right); printPCode(pcodeFile, "prin\n"); printPCode(pcodeFile, ";\t---End of write operation\n"); break; // case NODE_TYPE_CONTAINER: // case NODE_TYPE_FUNCTION_BODY: // case NODE_TYPE_DECLARATIONS: // pcodeGenValue(node->left); // pcodeGenValue(node->right); // break; default: pcodeGenValue(node->left); pcodeGenValue(node->right); //onUnrecognizedTypeError(node->type, __FILE__, __LINE__); break; } return EXIT_SUCCESS; } /* * ********************************************************** * Implementation of the header exposed items * See pcode.h for these functions comments * ********************************************************** */ int generatePCode() { if(rootNode==NULL) { //To check : Meaning of a null node, is it an error or only a warning? onError("Root node may not be null", __FILE__, __LINE__, NULL); return EXIT_FAILURE; } if(!isSymbolsTableAvailable()) { onError("Table of Symbols must not be NULL", __FILE__, __LINE__, NULL); //Failure of the compiler behavior, independent of the parsed code } #if(PCODE_FILE_REQUESTED) { #if(VERBOSE_LEVEL<=DEB_EXEC) printMsg(DEB_EXEC,"Open p-code file...ERRLEXICAL_OR", __FILE__, __LINE__); #endif }else { #if(VERBOSE_LEVEL<=DEB_EXEC) "\n; Open %s p-code file...OK\n", PCODE_FILE, __FILE__, __LINE__ ); #endif } #endif printPCode(pcodeFile, ";\tStart program\n"); // int maxMem = getDeclarationsMemoryUpperBound(); // printPCode(pcodeFile, "ssp %d\n", (maxMem<= 0) ? 0 : maxMem ); printPCode(pcodeFile, "ssp 0\n"); printPCode(pcodeFile, "mst 0\n"); int mainMemLoc = getShiftedMemoryLocation(getMain()); printPCode(pcodeFile, "cup 0 @fct_%s_%d\n", getMain()->info->name, mainMemLoc); printPCode(pcodeFile, "ujp @program_end\n"); int ret = pcodeGenValue(rootNode); printPCode(pcodeFile, "define @program_end\n"); printPCode(pcodeFile, "stp\n"); printPCode(pcodeFile, ";\tEnd of program\n"); if(PCODE_FILE_REQUESTED && pcodeFile!=NULL) { } #if(VERBOSE_LEVEL<=DEB_P) printSymbolsTableDebug(__FILE__,__LINE__); #endif return ret; }
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 | 1734858091 22/12/2024 10:01:31 |
Avertissement
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.
Version en cache
22/12/2024 10:01:31 Cette version de la page est en cache (à la date du 22/12/2024 10:01:31) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 07/03/2010, dernière modification le 28/10/2018
Source du document imprimé : https://www.gaudry.be/langages-lsd10-source-rf-project/source//pcode.c.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
- ↑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.
Références
- IHDCB332 - Théorie des langages : Syntaxe et sémantique : PY Schobbens,
Syntaxe et sémantique
(January 2010)
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.