[Commit] nickle ChangeLog, 1.61, 1.62 gram.y, 1.131, 1.132 lex.l, 1.73, 1.74

Keith Packard commit at keithp.com
Wed Jun 2 23:55:26 PDT 2004


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv13395

Modified Files:
	ChangeLog gram.y lex.l 
Log Message:
2004-06-02  Keith Packard  <keithp at keithp.com>
version 2.39

	* gram.y:
	* lex.l:
	Eliminate 'primary' non-terminal.
	Add ENDFILE token to ensure files end at top level.
	Change NL handling to allow NL after simple declarations
	Allow 'func' values to not require SEMI termination


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- a/ChangeLog	28 May 2004 06:41:34 -0000	1.61
+++ b/ChangeLog	3 Jun 2004 06:55:23 -0000	1.62
@@ -1,3 +1,14 @@
+2004-06-02  Keith Packard  <keithp at keithp.com>
+version 2.39
+
+	* gram.y:
+	* lex.l:
+	Eliminate 'primary' non-terminal.
+	Add ENDFILE token to ensure files end at top level.
+	Change NL handling to allow NL after simple declarations
+	Allow 'func' values to not require SEMI termination
+	
+
 2004-05-27  Keith Packard  <keithp at keithp.com>
 version 2.38
 

Index: gram.y
===================================================================
RCS file: /local/src/CVS/nickle/gram.y,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -d -r1.131 -r1.132
--- a/gram.y	20 May 2004 09:37:37 -0000	1.131
+++ b/gram.y	3 Jun 2004 06:55:24 -0000	1.132
@@ -105,7 +105,7 @@
 %type  <expr>	    fullname
 %type  <expr>	    opt_rawnames rawname rawnames rawnamespace
 %type  <atom>	    rawatom
-%type  <expr>	    block opt_func_body func_body statements statement catches catch
+%type  <expr>	    block opt_func_body func_body func_right statements statement catches catch
 %type  <expr>	    block_or_expr
 %type  <expr>	    case_block cases case
 %type  <expr>	    union_case_block union_cases union_case
@@ -134,7 +134,7 @@
 %type  <argDecl>    argdefine
 %type  <bool>	    opt_dotdotdot
 
-%type  <expr>	    opt_expr for_exprs expr opt_exprs exprs simpleexpr primary
+%type  <expr>	    opt_expr for_exprs expr opt_exprs exprs simpleexpr
 %type  <expr>	    opt_actuals actuals
 %type  <expr>	    comma_expr
 %type  <ints>	    assignop
@@ -146,7 +146,7 @@
 
 %token		    VAR EXPR ARRAY STRUCT UNION ENUM COMP HASH
 
-%token		    NL SEMI MOD OC CC DOLLAR DOTDOTDOT
+%token		    NL SEMI MOD OC CC DOLLAR DOTDOTDOT ENDFILE
 %token <class>	    GLOBAL AUTO STATIC CONST
 %token <type>	    POLY INTEGER NATURAL RATIONAL REAL STRING
 %token <type>	    FILET MUTEX SEMAPHORE CONTINUATION THREAD VOID BOOL
@@ -201,6 +201,8 @@
 		    { yyerrok; }
 		| SEMI
 		    { yyerrok; }
+		| ENDFILE
+		    { yyerrok; }
 		;
 
 /*
@@ -223,6 +225,13 @@
 		    }
 
 		;
+
+/*
+ * To make commands only recognized as the first token on a line,
+ * this production precedes every top-level production in the grammar.
+ * As the parser will look one token ahead, this cleverly makes only
+ * the first token on the line match commands
+ */
 not_command	:
 		    { notCommand = 1; }
 		;
@@ -328,6 +337,7 @@
 			EXIT ();
 		    }
 		| NL
+		| ENDFILE
 		;
 opt_rawnames	: rawnames
 		|
@@ -642,10 +652,10 @@
 		;
 block_or_expr	: block
 		    { $$ = $1; }
-		| ASSIGN simpleexpr SEMI
+		| attendnl ASSIGN simpleexpr SEMI
 		    { 
 			$$ = NewExprTree (OC,
-					  NewExprTree (RETURNTOK, 0, $2),
+					  NewExprTree (RETURNTOK, 0, $3),
 					  NewExprTree (OC, 0, 0));
 		    }
 		;
@@ -815,19 +825,19 @@
 /*
  * Full declaration including storage, type and publication
  */
-decl		: publish class type ignorenl opt_nl
+decl		: publish class type opt_nl
 		    { $$.publish = $1; $$.class = $2; $$.type = $3; }
-		| class type ignorenl opt_nl
+		| class type opt_nl
 		    { $$.publish = publish_private; $$.class = $1; $$.type = $2; }
-		| publish type ignorenl opt_nl
+		| publish type opt_nl
 		    { $$.publish = $1; $$.class = class_undef; $$.type = $2; }
-		| type ignorenl opt_nl
+		| type opt_nl
 		    { $$.publish = publish_private; $$.class = class_undef; $$.type = $1; }
-		| publish class ignorenl opt_nl
+		| publish class opt_nl
 		    { $$.publish = $1; $$.class = $2; $$.type = typePoly; }
-		| class ignorenl opt_nl
+		| class opt_nl
 		    { $$.publish = publish_private; $$.class = $1; $$.type = typePoly; }
-		| publish ignorenl opt_nl
+		| publish opt_nl
 		    { $$.publish = $1; $$.class = class_undef; $$.type = typePoly; }
 		;
 /*
@@ -1061,12 +1071,12 @@
 args		: OP opt_argdefines CP
 		    { $$ = $2; }
 		;
-opt_argdefines	: argdefines
+opt_argdefines	: ignorenl argdefines
 		    {
 			ArgType	*args;
 			Type	*type;
 
-			for (args = $1; args; args = args->next)
+			for (args = $2; args; args = args->next)
 			{
 			    type = args->type;
 			    if (ParseCanonType (type, False) != CanonTypeDefined)
@@ -1084,9 +1094,9 @@
 							   class_arg, 
 							   type, args->name);
 			}
-			$$ = $1;
+			$$ = $2;
 		    }
-		| 
+		| ignorenl
 		    { $$ = 0; }
 		;
 argdefines	: argdefine COMMA argdefines
@@ -1157,11 +1167,18 @@
 			$$ = NewExprTree (COMMA, arg, 0); 
 		    }
 		;
+func_right	: attendnl ASSIGN simpleexpr
+		    { 
+			$$ = NewExprTree (OC,
+					  NewExprTree (RETURNTOK, 0, $3),
+					  NewExprTree (OC, 0, 0));
+		    }
+		| { ++funcDepth; } block { --funcDepth; $$ = $2; }
+		;
 /*
 * Fundemental expression production
 */
-simpleexpr	: primary
-		| simpleexpr assignop simpleexpr    		%prec ASSIGN
+simpleexpr	: simpleexpr assignop simpleexpr    		%prec ASSIGN
 		    { 
 			if ($2 == ASSIGNPOW)
 			    $$ = NewExprTree (ASSIGNPOW, 
@@ -1187,6 +1204,11 @@
 			    $$ = NewExprTree($2, $1, $3); 
 			}
 		    }
+		| opt_type FUNC namespace_start args func_right namespace_end	    	%prec ASSIGN
+		    {
+			ParseCanonType ($1, False);
+			$$ = NewExprCode (NewFuncCode ($1, $4, $5), 0); 
+		    }
 		| MOD integer						%prec THREADID
 		    {   Value	t;
 			t = do_Thread_id_to_thread ($2);
@@ -1266,22 +1288,7 @@
 		    { $$ = NewExprTree(LE, $1, $3); }
 		| simpleexpr GE simpleexpr
 		    { $$ = NewExprTree(GE, $1, $3); }
-		;
-assignop	: ASSIGNPLUS
-		| ASSIGNMINUS
-		| ASSIGNTIMES
-		| ASSIGNDIVIDE
-		| ASSIGNDIV
-		| ASSIGNMOD
-		| ASSIGNPOW
-		| ASSIGNSHIFTL
-		| ASSIGNSHIFTR
-		| ASSIGNLXOR
-		| ASSIGNLAND
-		| ASSIGNLOR
-		| ASSIGN
-		;
-primary		: fullname
+		| fullname
 		| TEN_NUM
 		    { $$ = NewExprConst(TEN_NUM, $1); }
 		| OCTAL_NUM
@@ -1349,7 +1356,7 @@
 			$$ = NewExprTree (UNION, NewExprAtom ($3, 0, False), 0); 
 			$$->base.type = $1;
 		    }
-		| OP type DOT NAME CP primary 				%prec UNIONCAST
+		| OP type DOT NAME CP simpleexpr 			%prec UNIONCAST
 		    { 
 			ParseCanonType ($2, False);
 			$$ = NewExprTree (UNION, NewExprAtom ($4, 0, False), $6); 
@@ -1363,25 +1370,33 @@
 		    { $$ = $2; }
 		| OP block CP
 		    { $$ = $2; }
-		| primary STAROS dims CS
+		| simpleexpr STAROS dims CS
 		    { $$ = NewExprTree (OS, NewExprTree (STAR, $1, (Expr *) 0), $3); }
-		| primary OS dims CS
+		| simpleexpr OS dims CS
 		    { $$ = NewExprTree(OS, $1, $3); }
-		| primary OP opt_actuals CP				%prec CALL
+		| simpleexpr OP opt_actuals CP				%prec CALL
 		    { $$ = NewExprTree (OP, $1, $3); }
-		| primary DOT NAME
+		| simpleexpr DOT NAME
 		    { $$ = NewExprTree(DOT, $1, NewExprAtom ($3, 0, False)); }
-		| primary ARROW NAME
+		| simpleexpr ARROW NAME
 		    { $$ = NewExprTree(ARROW, $1, NewExprAtom ($3, 0, False)); }
-		| opt_type FUNC namespace_start args func_body namespace_end
-		    { 
-			ParseCanonType ($1, False);
-			$$ = NewExprCode (NewFuncCode ($1, $4, $5), 0); 
-		    }
 		;
 opt_integer	: integer
 		|
 		    { $$ = Zero; }
+assignop	: ASSIGNPLUS
+		| ASSIGNMINUS
+		| ASSIGNTIMES
+		| ASSIGNDIVIDE
+		| ASSIGNDIV
+		| ASSIGNMOD
+		| ASSIGNPOW
+		| ASSIGNSHIFTL
+		| ASSIGNSHIFTR
+		| ASSIGNLXOR
+		| ASSIGNLAND
+		| ASSIGNLOR
+		| ASSIGN
 		;
 integer		: TEN_NUM
 		| OCTAL_NUM

Index: lex.l
===================================================================
RCS file: /local/src/CVS/nickle/lex.l,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- a/lex.l	16 Apr 2004 21:41:52 -0000	1.73
+++ b/lex.l	3 Jun 2004 06:55:24 -0000	1.74
@@ -153,11 +153,8 @@
 	    ThreadsRun (0, lexInput->file);
 	else
 	{
-	    FileClose (lexInput->file);
-	    
 	    if (!lexInput->next)
 		return FileEOF;
-	    lexInput = lexInput->next;
 	    lexInput->at_eof = True;
 	    return '\n';
 	}
@@ -245,9 +242,13 @@
     int	    c;
     int	    result = 0;
     
-    lexInput->at_eof = False;
     if (lexInput->at_bol) { lexInput->lineno++; }
     while (result < max_size) {
+	if (lexInput->at_eof)
+	{
+	    FileClose (lexInput->file);
+	    lexInput = lexInput->next;
+	}
 	if (lexInput->interactive)
 	    c = LexGetInteractiveChar ();
 	else
@@ -349,6 +350,7 @@
 "=>"		{ yylval.ints = DARROW; return DARROW; }
 "<>"		{ yylval.value = Void; return VOIDVAL; }
 \n		{ 
+		    if (lexInput->at_eof) { strcpy (yytext, "EOF"); yylval.ints = ENDFILE; return ENDFILE; }
 		    if (!ignorenl) { yylval.ints = NL; return NL; } 
 		}
 "("		{ yylval.ints = OP; ++ignorenl; return OP; }
@@ -617,7 +619,6 @@
     {
 bail:	
         yyerror ("Missing */ at end of file");
-	lexInput->at_eof = False;
         return;
     }
     for (;;) {




More information about the Commit mailing list