Bläddra i källkod

hoc: a yacc program

Change-Id: I54107a44973127cfa189afef83f2837fb2259ffd
Aki Nyrhinen 9 år sedan
förälder
incheckning
9bcaa591e4
4 ändrade filer med 40 tillägg och 6 borttagningar
  1. 2 1
      sys/src/cmd/cmds.json
  2. 2 0
      sys/src/cmd/hoc/hoc.h
  3. 21 0
      sys/src/cmd/hoc/hoc.json
  4. 15 5
      sys/src/cmd/hoc/hoc.y

+ 2 - 1
sys/src/cmd/cmds.json

@@ -20,7 +20,8 @@
 		"disk/disk.json",
 		"dossrv/dossrv.json",
 		"fossil/fossil.json",
-		"ip/ip.json"
+		"ip/ip.json",
+		"hoc/hoc.json"
 	],
 	"SourceFilesCmd": [
 		"aan.c",

+ 2 - 0
sys/src/cmd/hoc/hoc.h

@@ -55,6 +55,8 @@ struct Fndefn {	/* formal parameter */
 	int	nargs;
 };
 
+extern int indef;
+
 extern	Formal *formallist(Symbol*, Formal*);
 extern	double Fgetd(int);
 extern	int moreinput(void);

+ 21 - 0
sys/src/cmd/hoc/hoc.json

@@ -0,0 +1,21 @@
+{
+	"Include": [
+		"../cmd.json"
+	],
+	"Install": "/$ARCH/bin",
+	"Name": "hoc",
+	"Post": [
+		"rm -f $HARVEY/sys/src/cmd/hoc/y.tab.[ch]"
+	],
+	"Pre": [
+		"yacc -d hoc.y"
+	],
+	"Program": "hoc",
+	"SourceFiles": [
+		"code.c",
+		"init.c",
+		"math.c",
+		"symbol.c",
+		"y.tab.c"
+	]
+}

+ 15 - 5
sys/src/cmd/hoc/hoc.y

@@ -1,4 +1,14 @@
 %{
+#include <u.h>
+#include <libc.h>
+#define _STDLIB_H 1
+
+void yyerror(char* s);	/* report compile-time error */
+int yylex(void);		/* hoc6 */
+int	backslash(int), follow(int, int, int);
+void	defnonly(char*), run(void);
+void	warning(char*, char*);
+
 #include "hoc.h"
 #define	code2(c1,c2)	code(c1); code(c2)
 #define	code3(c1,c2,c3)	code(c1); code(c2); code(c3)
@@ -133,8 +143,6 @@ arglist:  /* nothing */ 	{ $$ = 0; }
 	;
 %%
 	/* end of grammar */
-#include <u.h>
-#include <libc.h>
 #include <bio.h>
 #include <ctype.h>
 char	*progname;
@@ -146,13 +154,12 @@ Biobuf	*bin;		/* input file descriptor */
 Biobuf	binbuf;
 char	**gargv;	/* global argument list */
 int	gargc;
+int	yydebug;
 
 int c = '\n';	/* global for use by warning() */
 
-int	backslash(int), follow(int, int, int);
-void	defnonly(char*), run(void);
-void	warning(char*, char*);
 
+int
 yylex(void)		/* hoc6 */
 {
 	while ((c=Bgetc(bin)) == ' ' || c == '\t')
@@ -230,6 +237,7 @@ yylex(void)		/* hoc6 */
 	}
 }
 
+int
 backslash(int c)	/* get next char with \'s interpreted */
 {
 	static char transtab[] = "b\bf\fn\nr\rt\t";
@@ -241,6 +249,7 @@ backslash(int c)	/* get next char with \'s interpreted */
 	return c;
 }
 
+int
 follow(int expect, int ifyes, int ifno)	/* look ahead for >=, etc. */
 {
 	int c = Bgetc(bin);
@@ -317,6 +326,7 @@ main(int argc, char* argv[])	/* hoc6 */
 	exits(0);
 }
 
+int
 moreinput(void)
 {
 	char *expr;