diff options
author | June McEnroe <june@causal.agency> | 2019-05-15 19:54:29 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-05-15 19:54:29 -0400 |
commit | a3bbd78e0f9e05102eb0483209bc6e2eccc07c39 (patch) | |
tree | 6e40ea96624019886b9423c04113fa4498195c3c /bin | |
parent | Add order (diff) | |
download | src-a3bbd78e0f9e05102eb0483209bc6e2eccc07c39.tar.gz src-a3bbd78e0f9e05102eb0483209bc6e2eccc07c39.zip |
Implement sizeof in order
Diffstat (limited to 'bin')
-rw-r--r-- | bin/man1/order.1 | 6 | ||||
-rw-r--r-- | bin/order.y | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/bin/man1/order.1 b/bin/man1/order.1 index 696a24d1..5a01ab4b 100644 --- a/bin/man1/order.1 +++ b/bin/man1/order.1 @@ -29,6 +29,6 @@ $ order 'a & b << 1' .Sh CAVEATS .Nm does not support the -.Sy (type) , -.Sy sizeof -or assignment operators. +.Sy (type) +operator +or the assignment operators. diff --git a/bin/order.y b/bin/order.y index fb5a052a..83d6a37f 100644 --- a/bin/order.y +++ b/bin/order.y @@ -21,6 +21,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sysexits.h> static void yyerror(const char *str) { @@ -43,7 +44,7 @@ static int yylex(void); %} -%token Var Arr Inc Dec Shl Shr Le Ge Eq Ne And Or +%token Var Arr Inc Dec Sizeof Shl Shr Le Ge Eq Ne And Or %left ',' %right '?' ':' @@ -57,7 +58,7 @@ static int yylex(void); %left Shl Shr %left '+' '-' %left '*' '/' '%' -%right '!' '~' Inc Dec +%right '!' '~' Inc Dec Sizeof %left '[' ']' Arr '.' %% @@ -81,6 +82,7 @@ expr: | '-' expr { $$ = fmt("(-%s)", $2); } | '*' expr { $$ = fmt("(*%s)", $2); } | '&' expr { $$ = fmt("(&%s)", $2); } + | Sizeof expr { $$ = fmt("(sizeof %s)", $2); } | expr '*' expr { $$ = fmt("(%s * %s)", $1, $3); } | expr '/' expr { $$ = fmt("(%s / %s)", $1, $3); } | expr '%' expr { $$ = fmt("(%s %% %s)", $1, $3); } @@ -116,6 +118,10 @@ static int yylex(void) { int len; for (len = 0; isalnum(input[len]) || input[len] == '_'; ++len); if (len) { + if (!strncmp(input, "sizeof", len)) { + input += len; + return Sizeof; + } yylval = fmt("%.*s", len, input); input += len; return Var; |