Gary Morrison | ced8c6f | 2020-02-27 19:35:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | %{ |
| 10 | #include "class_forwards.hpp" |
| 11 | #include "boilerplate.hpp" |
| 12 | #include "gibberish.hpp" |
| 13 | #include "compute.hpp" |
| 14 | #include "string_ops.hpp" |
| 15 | #include "data_blocks.hpp" |
| 16 | #include "psa_asset.hpp" |
| 17 | #include "sst_asset.hpp" |
| 18 | #include "crypto_asset.hpp" |
| 19 | #include "find_or_create_asset.hpp" |
| 20 | #include "template_line.hpp" |
| 21 | #include "tf_fuzz.hpp" |
| 22 | #include "psa_call.hpp" |
| 23 | #include "tf_fuzz_grammar.tab.hpp" |
| 24 | |
| 25 | int yycolumn = 1; |
| 26 | |
| 27 | //char *yytext; |
| 28 | |
| 29 | #define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno; \ |
| 30 | yylloc.first_column = yycolumn; yylloc.last_column = yycolumn + yyleng - 1; \ |
| 31 | yycolumn += yyleng; \ |
| 32 | yylval.str = strdup(yytext); |
| 33 | |
| 34 | void yyerror (tf_fuzz_info *, const char *str) |
| 35 | /* not sure why it sends the yyparse() argument to yyerror(), but OK... */ |
| 36 | { |
| 37 | fprintf (stderr, "tf_fuzz template on line %d, at text = \"%s\": %s\n", |
| 38 | yylineno, yytext, str); |
| 39 | exit (1); |
| 40 | } |
| 41 | |
| 42 | #ifndef yyterminate |
| 43 | #define yyterminate() return YY_NULL |
| 44 | #endif |
| 45 | |
| 46 | %} |
| 47 | |
| 48 | %x BLOCK_COMMENT |
| 49 | |
| 50 | %option yylineno |
| 51 | %option nodefault |
| 52 | %option noyywrap |
| 53 | %array |
| 54 | |
| 55 | %% |
| 56 | |
| 57 | \r ; /* ignore all \r */ |
| 58 | \/\/.*\n ; /* ignore C++-style line comments */ |
| 59 | purpose[ \t]+[^;]*; return PURPOSE; |
| 60 | "/*" {BEGIN(BLOCK_COMMENT);} |
| 61 | <BLOCK_COMMENT>"*/" {BEGIN(INITIAL);} |
| 62 | <BLOCK_COMMENT>\n ; |
| 63 | <BLOCK_COMMENT>. ; |
| 64 | /* Root commands: */ |
| 65 | set return SET; |
| 66 | read return READ; |
| 67 | remove return REMOVE; |
| 68 | secure return SECURE; |
| 69 | done return DONE; |
| 70 | /* PSA-asset types: */ |
| 71 | sst return SST; |
| 72 | key return KEY; |
| 73 | policy return POLICY; |
| 74 | /* Other root-command operands: */ |
| 75 | expect return EXPECT; |
| 76 | pass return PASS; |
| 77 | nothing return NOTHING; |
| 78 | error return ERROR; |
| 79 | \{ return OPEN_BRACE; |
| 80 | \} return CLOSE_BRACE; |
| 81 | ; return SEMICOLON; |
| 82 | name return NAME; |
| 83 | uid return UID; |
| 84 | data return DATA; |
| 85 | \* return STAR; |
| 86 | active return ACTIVE; |
| 87 | deleted return DELETED; |
| 88 | check return CHECK; |
| 89 | assign return ASSIGN; |
| 90 | print return PRINT; |
| 91 | hash return HASH; |
| 92 | neq return NEQ; |
| 93 | dfname return DFNAME; |
| 94 | shuffle return SHUFFLE; |
| 95 | to return TO; |
| 96 | of return OF; |
| 97 | /* Structure operands: */ |
| 98 | [a-zA-z][a-zA-Z_0-9]* {yylval.str = yytext; return IDENTIFIER_TOK;} |
| 99 | [+-]?[0-9]* {yylval.valueN = atol(yytext); return NUMBER_TOK;} |
| 100 | \'[a-zA-Z_0-9\/\.]+\' {yylval.str = yytext; return FILE_PATH_TOK;} |
| 101 | \"[^\"]*\" {yylval.str = yytext; return LITERAL_TOK;} |
| 102 | /* inside quotes: anything but a quote, or nothing */ |
| 103 | [ \t\n\r] ; /* ignore white space */ |
| 104 | . yyerror ((tf_fuzz_info *) NULL, "Unexpected character"); |
| 105 | |
| 106 | %% |
| 107 | |