6 #include <linux/compiler.h>
8 #include "expr-bison.h"
10 char *expr_get_text(yyscan_t yyscanner);
11 YYSTYPE *expr_get_lval(yyscan_t yyscanner);
13 static double __value(YYSTYPE *yylval, char *str, int token)
18 num = strtod(str, NULL);
26 static int value(yyscan_t scanner)
28 YYSTYPE *yylval = expr_get_lval(scanner);
29 char *text = expr_get_text(scanner);
31 return __value(yylval, text, NUMBER);
35 * Allow @ instead of / to be able to specify pmu/event/ without
36 * conflicts with normal division.
38 static char *normalize(char *str, int runtime)
46 else if (*str == '\\')
48 else if (*str == '?') {
51 int size = asprintf(¶mval, "%d", runtime);
57 *dst++ = paramval[i++];
70 static int str(yyscan_t scanner, int token, int runtime)
72 YYSTYPE *yylval = expr_get_lval(scanner);
73 char *text = expr_get_text(scanner);
75 yylval->str = normalize(strdup(text), runtime);
79 yylval->str = normalize(yylval->str, runtime);
84 number ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
88 sym [0-9a-zA-Z_\.:@?]+
89 symbol ({spec}|{sym})+
92 struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
95 int start_token = sctx->start_token;
97 if (sctx->start_token) {
98 sctx->start_token = 0;
103 d_ratio { return D_RATIO; }
107 else { return ELSE; }
108 #smt_on { return SMT_ON; }
109 {number} { return value(yyscanner); }
110 {symbol} { return str(yyscanner, ID, sctx->runtime); }
127 int expr_wrap(void *scanner __maybe_unused)