ref: 184ef03517e984d9e9293ecaae60f8785ee73274
parent: d79699d880ff79a6f538731498f75f629f3051e8
author: Ori Bernstein <[email protected]>
date: Thu Jun 28 18:16:59 EDT 2012
Stub out grammar for matches.
--- a/8/main.c
+++ b/8/main.c
@@ -65,8 +65,11 @@
break;
case 'd':
debug = 1;
- while (optarg && *optarg)
+ while (optarg && *optarg) {
+ if (*optarg == 'y')
+ yydebug = 1;
debugopt[*optarg++ & 0x7f] = 1;
+ }
break;
case 'I':
lappend(&incpaths, &nincpaths, optarg);
--- a/mk/lexyacc.mk
+++ b/mk/lexyacc.mk
@@ -1,9 +1,9 @@
NECFLAGS = $(subst -Werror,,$(subst -Wall,,$(CFLAGS)))
-%.o: %.y .deps
- yacc -d -o$*.c $<
+%.o: %.y
+ yacc -dt -o$*.c $<
$(CC) -c $(NECFLAGS) $*.c
-%.o: %.l .deps
+%.o: %.l
flex -o$*.c $<
$(CC) -c $(NECFLAGS) $*.c
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -127,11 +127,12 @@
%type <node> bandexpr cmpexpr unioncons addexpr mulexpr shiftexpr prefixexpr postfixexpr
%type <node> funclit arraylit name block blockbody stmt label use
%type <node> decl declbody declcore structelt
-%type <node> ifstmt forstmt whilestmt elifs optexprln
+%type <node> ifstmt forstmt whilestmt matchstmt elifs optexprln
+%type <node> pat match
%type <node> castexpr
%type <ucon> unionelt
-%type <nodelist> arglist argdefs structbody params
+%type <nodelist> arglist argdefs structbody params matches
%type <uconlist> unionbody
%union {
@@ -528,6 +529,7 @@
| ifstmt
| forstmt
| whilestmt
+ | matchstmt
| Tendln {$$ = NULL;}
;
@@ -556,6 +558,26 @@
{$$ = $2;}
| Tendblk
{$$ = NULL;}
+ ;
+
+matchstmt: Tmatch exprln matches Tendblk
+ {$$ = NULL;}
+ ;
+
+matches : match
+ {$$.nl = NULL; $$.nn = 0;
+ if ($1)
+ lappend(&$$.nl, &$$.nn, $1);}
+ | matches match
+ {if ($2)
+ lappend(&$$.nl, &$$.nn, $2);}
+ ;
+
+match : pat Tcolon block {$$ = NULL;}
+ | Tendln {$$ = NULL;}
+ ;
+
+pat : literal {$$ = NULL;}
;
block : blockbody Tendblk
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -423,6 +423,7 @@
/* Options to control the compilation */
extern int debug;
+extern int yydebug;
extern char debugopt[128];
extern int asmonly;
extern char *outfile;