lsd10.l
Description du code
lsd10.l 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 Lex (lsd10.l) (312 lignes)
%{ /* * lsd10.l : lexical parsing file for Lex * @see http://www.gaudry.be/langages-flex.html * Part of the compiler Project for LSD10 language */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "y.tab.h" /* #include "ast.h" */ #include "common.h" /** * Count of lines read */ int lexLinesCount=0; /** * Count of chars read */ int lexTotalCharsCount=0; extern AstNode *rootNode; /* * internal business ************************************************************* */ extern DebugInfo *psnBeforeToken; extern DebugInfo *psnAfterToken; int processToken(int tokenType); void incrementNumChar(); void addLineRead(); /* * Lex overriding ************************************************************* */ int yyTempColumn=1; //define YY_USER_ACTION yylloc.first_line=yylloc.last_line=yylineno;yylloc.first_column=yylloc.last_column=yyTempColumn+yyleng-1;yyTempColumn+=yyleng; %} %option noyywrap %option yylineno %x COMMENT_LINE COMMENT_BLOC /*nbr 0|[-][1-9][0-9]*|[1-9][0-9]* */ nbr 0|[1-9][0-9]* id [a-zA-Z]|([a-zA-Z]([a-zA-Z]|[0-9])*) blank [ \t]+ %% %{ //we specify that we begin with the rules of the state INITIAL BEGIN INITIAL; %} "boolean" { incrementNumChar(); return processToken(LEXICAL_BOOLEAN_TYPE);} "integer" { incrementNumChar(); return processToken(LEXICAL_INTEGER_TYPE);} "=" { incrementNumChar(); return processToken(LEXICAL_AFFECTATION); } "&&" { incrementNumChar(); return processToken(LEXICAL_AND); } "||" { incrementNumChar(); return processToken(LEXICAL_OR); } "&" { incrementNumChar(); return processToken(LEXICAL_ANDLAZY); } "|" { incrementNumChar(); return processToken(LEXICAL_ORLAZY); } "!" { incrementNumChar(); return processToken(LEXICAL_NOT); } "==" { incrementNumChar(); return processToken(LEXICAL_EQUALS); } "<=" { incrementNumChar(); return processToken(LEXICAL_LESS_EQUALS); } "<" { incrementNumChar(); return processToken(LEXICAL_LESS); } "+" { incrementNumChar(); return processToken(LEXICAL_PLUS); } "-" { incrementNumChar(); return processToken(LEXICAL_MINUS); } "*" { incrementNumChar(); return processToken(LEXICAL_MULT); } "div" { incrementNumChar(); return processToken(LEXICAL_DIV); } "mod" { incrementNumChar(); return processToken(LEXICAL_MOD); } "(" { incrementNumChar(); return processToken(L_PARENTHESIS); } "{" { incrementNumChar(); return processToken(LSQUI_BRACKET); } "." { incrementNumChar(); return processToken(POINT); } ")" { incrementNumChar(); return processToken(R_PARENTHESIS); } "}" { incrementNumChar(); return processToken(RSQUI_BRACKET); } "[" { incrementNumChar(); return processToken(LSQUA_BRACKET); } "]" { incrementNumChar(); return processToken(RSQUA_BRACKET); } "," { incrementNumChar(); return processToken(COMMA); } ":" { incrementNumChar(); return processToken(COLON); } ";" { incrementNumChar(); return processToken(SEMICOLON); } "true" { incrementNumChar(); return processToken(LEXICAL_TRUE_VAL); } "false" { return processToken(LEXICAL_FALSE_VAL); } "void" { incrementNumChar(); return processToken(LEXICAL_VOID_TYPE); } "var" { incrementNumChar(); return processToken(LEXICAL_VAR); } "get" { return processToken(LEXICAL_GET_OPS); } "isempty" { incrementNumChar(); return processToken(LEXICAL_ISEMPTY_OPS); } "write" { incrementNumChar(); return processToken(LEXICAL_WRITE_OPS); } "read" { incrementNumChar(); return processToken(LEXICAL_READ_OPS); } "put" { incrementNumChar(); return processToken(LEXICAL_PUT_OPS); } "return" { incrementNumChar(); return processToken(LEXICAL_RETURN_STMT); } "for" { incrementNumChar(); return processToken(LEXICAL_FOR_STMT); } "if" { incrementNumChar(); return processToken(LEXICAL_IF_STMT); } "else" { incrementNumChar(); return processToken(LEXICAL_ELSE_STMT); } "while" { incrementNumChar(); return processToken(LEXICAL_WHILE_STMT); } "intstack" { incrementNumChar(); return processToken(LEXICAL_INSTACK_TYPE); } {blank} { incrementNumChar(); } "\n" { addLineRead(); } {nbr} { yylval.text=yytext; incrementNumChar(); return processToken(NUMBER); } {id} { incrementNumChar(); return processToken(ID); } "//" { BEGIN(COMMENT_LINE); incrementNumChar(); } "/*" { BEGIN(COMMENT_BLOC); incrementNumChar(); } <COMMENT_BLOC>"*/" { BEGIN(INITIAL); incrementNumChar(); } <COMMENT_BLOC>"\n" { addLineRead(); } <COMMENT_BLOC>. { incrementNumChar();/*Ignore comment*/} <COMMENT_LINE>"\n" { BEGIN(INITIAL); addLineRead(); } <COMMENT_LINE>. { incrementNumChar();/*Ignore comment*/} . { char errorStr[1024];//todo: minimize length sprintf(errorStr, "Error : invalid '%s' On parsed file, Line %d col %d\n",yytext, yylloc.first_line, yylloc.first_column); yyerror(errorStr); } %% int processToken(int tokenType) { yylloc.first_line=yylloc.last_line=yylineno; yylloc.first_column=yylloc.last_column=yyTempColumn+yyleng-1; yyTempColumn+=yyleng; #if(VERBOSE_LEVEL<=DEB_L) ";%15s %15s detected(%d) line %d char %d\n", typeToString(tokenType), yytext, tokenType, (yylloc).first_line, (yylloc).first_column ); #endif return tokenType; } void incrementNumChar() { //// if(lexLinesCount<1) //// { //// addLineRead(); //// } //// #if(VERBOSE_LEVEL<=DEB_L) //// if(YY_START==INITIAL) //// { //// ECHO; //// } //// #endif // lexCharsCountBeforeToken+=yyleng; //// lexCharsCountBeforeToken=lexCharsTempPsn-yyleng; //// lexCharsTempPsn+=yyleng; lexTotalCharsCount+=yyleng; //printf("%s => line %d, bt=%d,tmp=%d, t=%d\n", yytext, lexLinesCount, lexCharsCountBeforeToken,lexCharsTempPsn,lexTotalCharsCount); } void addLineRead() { // #if(VERBOSE_LEVEL<=DEB_L) // printf("\n;\t"); // #endif // ++lexLinesCount; // lexLinesCountBeforeToken = yylineno; // lexCharsCountBeforeToken = 0; yyTempColumn=1; // if(psnBeforeToken!=NULL) // { ++lexLinesCount; // lexLinesCountBeforeToken = yylineno; // lexCharsCountBeforeToken = 0; // //lexCharsTempPsn = 0; // //psnBeforeToken->line = ; // psnAfterToken->line++; //// printf( //// ";\t%s detected line %d(%d, %d) char %d\n", //// yytext, //// lexLinesCount, //// yylineno, //// psnAfterToken->line, //// lexTotalCharsCount-yyleng//lexCharsCountBeforeToken //// ); // } } //int main() //{ // #if(VERBOSE_LEVEL<=DEB_L) // print("\n;\t"); // #endif // yylex(); // return 0; //}
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 | 1734897857 22/12/2024 21:04:17 |
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//lsd10.l.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.