diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-01-30 17:23:16 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-01-30 17:23:16 (GMT) |
commit | 792b330c1bbe573a591687d25e14d4cd1eccd3c6 (patch) | |
tree | 9a3e0955205c0221ea5db03b1f3a4d56846efed2 /tools/d2c/format/grammar.y | |
parent | c922b6b9c841a97dd948755658cff07b2c6762ff (diff) |
Introduced a format switch to distinguish different kinds of definitions.
Diffstat (limited to 'tools/d2c/format/grammar.y')
-rw-r--r-- | tools/d2c/format/grammar.y | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/d2c/format/grammar.y b/tools/d2c/format/grammar.y new file mode 100644 index 0000000..062d616 --- /dev/null +++ b/tools/d2c/format/grammar.y @@ -0,0 +1,107 @@ + +%{ + +#include "tokens.h" + + +/* Affiche un message d'erreur suite à l'analyse en échec. */ +static int yyerror(operands_format *, char *); + +%} + + +%code requires { + +#include "decl.h" + +} + + +%union { + + char *string; /* Chaîne de caractères */ + +} + + +%define api.pure full + +%parse-param { operands_format *format } + +%code provides { + +#define YY_DECL \ + int format_lex(YYSTYPE *yylvalp) + +YY_DECL; + +} + + +%token OPS_TYPE + +%type <string> OPS_TYPE + + + +%% + + +type : OPS_TYPE { set_operands_format_type(format, $1); } + + +%% + + +/****************************************************************************** +* * +* Paramètres : format = structure impliquée dans le processus. * +* msg = message d'erreur. * +* * +* Description : Affiche un message d'erreur suite à l'analyse en échec. * +* * +* Retour : 0 * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int yyerror(operands_format *format, char *msg) +{ + printf("bits yyerror line %d: %s\n", yyget_lineno(), msg); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : format = structure à constituer à partir de données lues. * +* raw = données brutes à analyser. * +* * +* Description : Interprête des données relatives à une définition de format. * +* * +* Retour : true si l'opération s'est bien déroulée, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool load_format_from_raw_line(operands_format *format, const char *raw) +{ + bool result; /* Bilan à faire remonter */ + YY_BUFFER_STATE state; /* Support d'analyse */ + int status; /* Bilan de l'analyse */ + + state = yy_scan_string(raw); + + status = yyparse(format); + + result = (status == 0); + + yy_delete_buffer(state); + + return result; + +} |