shithub: hammer

Download patch

ref: e8603799ceaa3ef49d8a193b315f2cac94bb358f
parent: 469b6871283ee08925584726368cd100c4275fef
author: Jacob Moody <[email protected]>
date: Fri Nov 17 16:14:39 EST 2023

else, more expr, slice and arrays

--- a/n.y
+++ b/n.y
@@ -48,7 +48,7 @@
 	long ival;
 }
 
-%token FUNC DEF IF FOR MOD USE OR AND NOTEQ SHIFTL SHIFTR STRUCT
+%token FUNC DEF IF FOR MOD USE OR AND NOTEQ EQ SHIFTL SHIFTR STRUCT ELSE
 %token TYPE NAME NUM
 
 %token	<sval>	NAME TYPE;
@@ -68,7 +68,7 @@
 
 sdecls
 :
-|	sdecls NAME ':' TYPE ';'
+|	sdecls NAME ':' type ';'
 
 def
 :	DEF NAME TYPE
@@ -80,20 +80,32 @@
 		addtype($2);
 	}
 
+type
+:	TYPE
+|	type '[' ']'
+|	type '[' NUM ']'
+|	type '!'
+
 return
-:	'-' '>' TYPE
+:	'-' '>' type
 |
 
 unary
 :	NUM
-|	NAME	
+|	NAME
+|	'<' '-' NAME
+|	'(' expr ')'
 
-mulexpr
-:	mulexpr '*' unary
-|	mulexpr '/' unary
-|	mulexpr '%' unary
+sufexpr
+:	unary '--'
+|	unary '++'
 |	unary
 
+mulexpr
+:	mulexpr '*' sufexpr
+|	mulexpr '/' sufexpr
+|	mulexpr '%' sufexpr
+|	sufexpr
 
 addexpr
 :	addexpr '+' mulexpr
@@ -100,13 +112,19 @@
 |	addexpr '-' mulexpr
 |	mulexpr
 
-compexpr
-:	compexpr '>' addexpr
-|	compexpr '<' addexpr
-|	compexpr NOTEQ addexpr
+shifexpr
+:	shifexpr SHIFTL addexpr
+|	shifexpr SHIFTR addexpr
 |	addexpr
 
+compexpr
+:	compexpr '>' shifexpr
+|	compexpr '<' shifexpr
+|	compexpr NOTEQ shifexpr
+|	compexpr EQ shifexpr
+|	shifexpr
 
+
 logexpr
 :	logexpr OR compexpr
 |	logexpr AND compexpr
@@ -122,7 +140,7 @@
 |	stmts stmt
 
 decl
-:	NAME ':' TYPE
+:	NAME ':' type
 |	NAME ':' '=' expr
 
 stmt
@@ -129,9 +147,13 @@
 :	expr ';'
 |	'{' stmts '}'
 |	decl ';'
+|	FOR '(' expr ')' stmt
+|	FOR '(' expr ';' expr ';' expr ')' stmt
+|	IF '(' expr ')' stmt ELSE stmt
+|	IF '(' expr ')' stmt
 
 arg
-:	NAME TYPE
+:	NAME type
 
 args
 :	
@@ -153,9 +175,11 @@
 	"&&", AND,
 	"||", OR,
 	"!=", NOTEQ,
+	"==", EQ,
 	"<<", SHIFTR,
 	">>", SHIFTL,
 	"struct", STRUCT,
+	"else", ELSE,
 };
 
 Biobuf *bin;
@@ -249,7 +273,7 @@
 	case '*': case '/':
 	case '%': case ':':
 	case '>': case '<':
-	case ',':
+	case ',': case '.':
 		return c;
 	}
 	ungetc();
@@ -267,7 +291,6 @@
 			return TYPE;
 		}
 	}
-			
 
 	if(isdigit(buf[0])){
 		yylval.ival = atoi(buf);