Browse Source

update miniyacc

Quentin Carbonneaux 10 years ago
parent
commit
4beee73fd3
1 changed files with 18 additions and 9 deletions
  1. 18 9
      minic/yacc.c

+ 18 - 9
minic/yacc.c

@@ -851,7 +851,7 @@ nexttk()
 char *
 char *
 cpycode()
 cpycode()
 {
 {
-	int c, nest, len, pos;
+	int c, nest, in, len, pos;
 	char *s;
 	char *s;
 
 
 	len = 64;
 	len = 64;
@@ -859,17 +859,26 @@ cpycode()
 	s[0] = '{';
 	s[0] = '{';
 	pos = 1;
 	pos = 1;
 	nest = 1;
 	nest = 1;
+	in = 0;
 
 
 	while (nest) {
 	while (nest) {
 		c = fgetc(fin);
 		c = fgetc(fin);
-		if (c == '{')
-			nest++;
-		if (c == '}')
-			nest--;
-		if (c == EOF)
-			die("syntax error, unclosed code block");
-		if (c == '\n')
-			lineno++;
+		if (in) {
+			if (c == in)
+			if (s[pos-1] != '\\')
+				in = 0;
+		} else {
+			if (c == '"' || c == '\'')
+				in = c;
+			if (c == '{')
+				nest++;
+			if (c == '}')
+				nest--;
+			if (c == EOF)
+				die("syntax error, unclosed code block");
+			if (c == '\n')
+				lineno++;
+		}
 		if (pos>=len)
 		if (pos>=len)
 		if (!(s=realloc(s, len=2*len+1)))
 		if (!(s=realloc(s, len=2*len+1)))
 			die("out of memory");
 			die("out of memory");