diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-04-02 11:58:42 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-04-02 12:39:30 (GMT) |
commit | 1db4ef323b7a76093356ae76268132f3760e1631 (patch) | |
tree | fec36ee0ec1b6b2010b62ca4177edca0e31e2114 /tools/d2c/pattern/grammar.y | |
parent | 1bc80837dde03a32b5ab185067f7bd4c499a9850 (diff) |
Rewritten the whole instruction definition format.
Diffstat (limited to 'tools/d2c/pattern/grammar.y')
-rw-r--r-- | tools/d2c/pattern/grammar.y | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/d2c/pattern/grammar.y b/tools/d2c/pattern/grammar.y new file mode 100644 index 0000000..c3399cc --- /dev/null +++ b/tools/d2c/pattern/grammar.y @@ -0,0 +1,107 @@ + +%{ + +#include "tokens.h" + + +/* Affiche un message d'erreur suite à l'analyse en échec. */ +static int yyerror(asm_pattern *, char *); + +%} + + +%code requires { + +#include "decl.h" + +} + + +%union { + + char *string; /* Chaîne de caractères */ + +} + + +%define api.pure full + +%parse-param { asm_pattern *pattern } + +%code provides { + +#define YY_DECL \ + int pattern_lex(YYSTYPE *yylvalp) + +YY_DECL; + +} + + +%token OPERAND + +%type <string> OPERAND + + +%% + + +operands : /* empty */ + | operands OPERAND { register_asm_pattern_item(pattern, $2); } + + +%% + + +/****************************************************************************** +* * +* Paramètres : pattern = 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(asm_pattern *pattern, char *msg) +{ + printf("syntax yyerror line %d: %s\n", yyget_lineno(), msg); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : pattern = structure à constituer à partir de données lues. * +* raw = données brutes à analyser. * +* * +* Description : Interprête des données liées à une définition de syntaxe. * +* * +* Retour : true si l'opération s'est bien déroulée, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool load_asm_pattern_from_raw_line(asm_pattern *pattern, 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(pattern); + + result = (status == 0); + + yy_delete_buffer(state); + + return result; + +} |