diff options
author | Robert Mustacchi <rm@joyent.com> | 2019-01-31 05:09:40 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2019-06-04 13:14:28 +0000 |
commit | 7a2abfc9b29ea1ccc055443876ab57455e3e8f71 (patch) | |
tree | fa5eb2e79b5c24e4c6123a23404e7c5d64768739 /usr/src | |
parent | 17a5fa85fe0c34b1146222e40a80b42f2aae8500 (diff) | |
download | illumos-gate-7a2abfc9b29ea1ccc055443876ab57455e3e8f71.tar.gz |
10941 mdb deserves a modulus operator
Reviewed by: John Levon <john.levon@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Toomas Soome <toomas@me.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/mdb/common/mdb/mdb_grammar.y | 13 | ||||
-rw-r--r-- | usr/src/cmd/mdb/common/mdb/mdb_lex.l | 4 |
2 files changed, 16 insertions, 1 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_grammar.y b/usr/src/cmd/mdb/common/mdb/mdb_grammar.y index 97ea454627..05171acdef 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_grammar.y +++ b/usr/src/cmd/mdb/common/mdb/mdb_grammar.y @@ -26,7 +26,7 @@ */ /* - * Copyright (c) 2015, Joyent, Inc. All rights reserved. + * Copyright (c) 2019, Joyent, Inc. All rights reserved. */ #include <mdb/mdb_types.h> @@ -112,6 +112,7 @@ yyexpand(int val) %left MDB_TOK_LSHIFT MDB_TOK_RSHIFT %left '-' '+' %left '*' '%' '#' +%left MDB_TOK_MODULUS %right MDB_COR_VALUE %right MDB_OBJ_VALUE @@ -309,6 +310,16 @@ expression: expression '+' expression { $$ = $1 + $3; } $$ = (intmax_t)$1 / (intmax_t)$3; } + | expression MDB_TOK_MODULUS expression { + + if ($3 == 0UL) + yyerror("attempted to divide by zero"); + + $$ = $1 % $3; + } + + + | expression '&' expression { $$ = $1 & $3; } | expression '|' expression { $$ = $1 | $3; } | expression '^' expression { $$ = $1 ^ $3; } diff --git a/usr/src/cmd/mdb/common/mdb/mdb_lex.l b/usr/src/cmd/mdb/common/mdb/mdb_lex.l index e777039c7b..7723f00f9e 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_lex.l +++ b/usr/src/cmd/mdb/common/mdb/mdb_lex.l @@ -28,6 +28,7 @@ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2017 by Delphix. All rights reserved. + * Copyright 2019, Joyent, Inc. */ #include <sys/types.h> @@ -131,6 +132,9 @@ RGX_COMMENT "//".*\n <S_INITIAL>"!=" | <S_EXPR>"!=" return (MDB_TOK_NOTEQUAL); /* Inequality operator */ +<S_INITIAL>"%%" | +<S_EXPR>"%%" return (MDB_TOK_MODULUS); /* Modulus operator */ + <S_INITIAL>"!" | <S_FMTLIST>"!" | <S_ARGLIST>"!" { |