%{ #include using namespace std; #include "grafcet.h" using namespace Automate; void yyerror (const char *s); int yylex (void); Grafcet *input_grafcet; %} %defines %union { int num; double fl; bool boolean; string *s; Grafcet *grafcet; Etape *etape; Action *action; Receptivite *receptivite; Transition *transition; Expression *expression; } %token NUM %token FLOAT %token BOOL %token STRING %token ERR GOTO SI %token EQ NEQ LEQ GEQ %token INITIALISATION %token RECHERCHER %token ROTATION %token AVANCER_PALET %token NB_PALET_PILE %token NB_PALET_STOCKE %token MISE_EN_PLACE %token REPERER_COULEUR %token RETOURNER %token AVANCER %token RECULER %token PLACER_PINCE %token PRINT %token INIT %token PALETS_TROUVES %token PALETS %token STOCKE %token COULEUR_ADVERSE %token PINCE_ANGLE %token PINCE_POS %token ROBOT_RECULE %token ROBOT_AVANCE %type grafcet %type etape %type action %type receptivite %type transition %type expression %type flnum %left '|' %left '&' %left '!' %left EQ NEQ LEQ GEQ '<' '>' %left '+' '-' %left '*' '/' %left NEG %% input: grafcet { input_grafcet = $1; } ; grafcet: /* Rien */ { $$ = new Grafcet (); } | grafcet etape { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); } | grafcet action { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); } | grafcet SI receptivite { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($3)); } | grafcet transition { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); } ; etape: '#' NUM { $$ = new Etape ($2); } ; action: PRINT STRING { $$ = new ActionPrint (*$2); delete $2; } | AVANCER NUM { $$ = new ActionMotorGoDistance ($2); } | AVANCER NUM NUM { $$ = new ActionMotorGoDistance ($2, $3); } | RECULER NUM { $$ = new ActionMotorGoDistance (-$2); } | RECULER NUM NUM { $$ = new ActionMotorGoDistance (-$2, $3); } | INITIALISATION { $$ = new ActionInitialisation ();} | RECHERCHER { $$ = new ActionRechercher ();} | ROTATION { $$ = new ActionRotation ();} | AVANCER_PALET { /*$$ = new ActionAvancerPalet ();*/ } | NB_PALET_PILE { $$ = new ActionNbPaletPile ();} | NB_PALET_STOCKE { $$ = new ActionNbPaletStocke ();} | MISE_EN_PLACE { $$ = new ActionMiseEnPlace ();} | REPERER_COULEUR NUM { $$ = new ActionRepererCouleur ($2);} | RETOURNER { $$ = new ActionRetourner ();} | PLACER_PINCE NUM { $$ = new ActionPlacerPince ($2);} ; receptivite: BOOL { $$ = new ReceptiviteBool ($1); } | ROBOT_RECULE { $$ = new ReceptMotorFinnish; } | ROBOT_AVANCE { $$ = new ReceptMotorFinnish; } | INIT { $$ = new ReceptInit (); } | PALETS_TROUVES { $$ = new ReceptPaletsTrouves (); } | PALETS NUM { $$ = new ReceptPalets ($2); } | STOCKE NUM { $$ = new ReceptStocke ($2); } | COULEUR_ADVERSE NUM { $$ = new ReceptCouleurAdverse ($2); } | PINCE_ANGLE NUM { $$ = new ReceptPinceAngle ($2); } | PINCE_POS NUM { $$ = new ReceptPincePos ($2); } | receptivite '&' receptivite { $$ = new ReceptiviteBoolOp ($1, '&', $3); } | receptivite '|' receptivite { $$ = new ReceptiviteBoolOp ($1, '|', $3); } | '!' receptivite { $$ = new ReceptiviteBoolOp ('!', $2); } | '(' receptivite ')' { $$ = $2; } | expression EQ expression { $$ = new ReceptiviteCmpOp ($1, '=', $3); } | expression NEQ expression { $$ = new ReceptiviteCmpOp ($1, 'n', $3); } | expression LEQ expression { $$ = new ReceptiviteCmpOp ($1, 'l', $3); } | expression GEQ expression { $$ = new ReceptiviteCmpOp ($1, 'g', $3); } | expression '<' expression { $$ = new ReceptiviteCmpOp ($1, '<', $3); } | expression '>' expression { $$ = new ReceptiviteCmpOp ($1, '>', $3); } ; expression: NUM { $$ = new ExpressionNum ($1); } | expression '+' expression { $$ = new ExpressionNumOp ($1, '+', $3); } | expression '-' expression { $$ = new ExpressionNumOp ($1, '-', $3); } | expression '*' expression { $$ = new ExpressionNumOp ($1, '*', $3); } | '-' expression %prec NEG { $$ = new ExpressionNumOp ('n', $2); } ; transition: GOTO NUM { $$ = new Transition ($2); } ; flnum: FLOAT { $$ = $1; } | NUM { $$ = $1; } | flnum '/' flnum { $$ = $1 / $3; } ; %% void yyerror (const char *s) { cerr << "Parse error: " << s << endl; } // vim: ft=yacc