blob: d3f1cf6463b4f1bbd4dfe704e119503129f7afd0 [file] [log] [blame]
Gary Morrisonced8c6f2020-02-27 19:35:59 +00001/*
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
25int 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
34void 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 */
59purpose[ \t]+[^;]*; return PURPOSE;
60"/*" {BEGIN(BLOCK_COMMENT);}
61<BLOCK_COMMENT>"*/" {BEGIN(INITIAL);}
62<BLOCK_COMMENT>\n ;
63<BLOCK_COMMENT>. ;
64 /* Root commands: */
65set return SET;
66read return READ;
67remove return REMOVE;
68secure return SECURE;
69done return DONE;
70 /* PSA-asset types: */
71sst return SST;
72key return KEY;
73policy return POLICY;
74 /* Other root-command operands: */
75expect return EXPECT;
76pass return PASS;
77nothing return NOTHING;
78error return ERROR;
79\{ return OPEN_BRACE;
80\} return CLOSE_BRACE;
81; return SEMICOLON;
82name return NAME;
83uid return UID;
84data return DATA;
85\* return STAR;
86active return ACTIVE;
87deleted return DELETED;
88check return CHECK;
89assign return ASSIGN;
90print return PRINT;
91hash return HASH;
92neq return NEQ;
93dfname return DFNAME;
94shuffle return SHUFFLE;
95to return TO;
96of 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