Giter Site home page Giter Site logo

compilation2024's Introduction

⭐Analyse lexicale avec Flex

Installation de Flex

$ sudo install flex

Execution d'un file.l

$ flex file.l && gcc lex.yy.c -o exec && ./exec

Execution avec arguments

$ flex file.l && gcc lex.yy.c -o exec && ./exec input.txt > output.txt

⭐Analyse syntaxique avec Bison

$ sudo install yacc

Execution d'un file.y

$ yacc -d file.y && gcc y.tab.c -o exec && ./exec

⭐Analyse syntaxique+lexicale avec Flex/Bison

$ flex file.l && yacc -d file.y && gcc y.tab.c -o exec && ./exec 

Exemple: commandes réseau

Analyse lexicale

Unités lexicales file.l

%option noyywrap
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
%}
routerconfig "config-router"
network "network"
hashtag "#"
area "area"
parouv "("
parferm ")"
point "."
nb [2][0-5][0-9]|[1][0-9][0-9]|[1-9][0-9]|[0-9]
id [a-zA-Z]([a-zA-Z]|[0-9])*
%%
{routerconfig} {return CONFIGROUTER;}
{hashtag} {return HASHTAG;}
{parouv} {return PAROUV;}
{parferm} {return PARFERM;}
{area} {return AREA; }
{network} {return NETWORK;}
{id} {return ID;}
{nb} {return NB;}
{point} {return POINT;}
[$] {return FIN;}
[\t \n]
%%
$ flex file.l

Analyse syntaxique file.y

%{
#include<stdio.h>
int yylex(void); 
int yyerror(char*s);
%}
%token HASHTAG
%token ID
%token FIN
%token PAROUV
%token PARFERM
%token CONFIGROUTER
%token NETWORK
%token NB
%token AREA
%token POINT

%%
S: CMD FIN {printf("commande correcte !");}
;
CMD: ID PAROUV CONFIGROUTER PARFERM HASHTAG NETWORK ADR ADR AREA NB ;
ADR: NB POINT NB POINT NB POINT NB;

%%
#include "lex.yy.c" 
int yyerror(char *s){
   printf("%s \n",s);
   return 0;
   }
int main(){
   yyparse();
   return 0;
   }
$ yacc -d file.y && gcc y.tab.c -o exec && ./exec

Exemple d'execution

> isiAriana ( config-router ) # network 255.255.255.0 255.0.0.0 area 2$  

> commande reseau correcte !

compilation2024's People

Contributors

yos-r avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.