diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-09-15 17:48:26 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-09-15 17:48:26 -0300 |
| commit | 367139c6d952272cff1f114e7323299478681ffd (patch) | |
| tree | 63a9a48a72811a2c7e8fad366518686e2d9e490a | |
| parent | 457bac94ce770682c140c971a4d1ec1638ca59cc (diff) | |
| download | lua-367139c6d952272cff1f114e7323299478681ffd.tar.gz lua-367139c6d952272cff1f114e7323299478681ffd.tar.bz2 lua-367139c6d952272cff1f114e7323299478681ffd.zip | |
buffer for literals now grows dynamically, allowing big programs between [[ and ]].
| -rw-r--r-- | lex.c | 47 |
1 files changed, 40 insertions, 7 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.15 1995/07/06 17:47:08 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | #include <ctype.h> | 4 | #include <ctype.h> |
| @@ -7,6 +7,7 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; | |||
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | 9 | ||
| 10 | #include "mem.h" | ||
| 10 | #include "tree.h" | 11 | #include "tree.h" |
| 11 | #include "table.h" | 12 | #include "table.h" |
| 12 | #include "opcode.h" | 13 | #include "opcode.h" |
| @@ -14,6 +15,8 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; | |||
| 14 | #include "parser.h" | 15 | #include "parser.h" |
| 15 | #include "ugly.h" | 16 | #include "ugly.h" |
| 16 | 17 | ||
| 18 | #define MINBUFF 260 | ||
| 19 | |||
| 17 | #define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) | 20 | #define lua_strcmp(a,b) (a[0]<b[0]?(-1):(a[0]>b[0]?(1):strcmp(a,b))) |
| 18 | 21 | ||
| 19 | #define next() { current = input(); } | 22 | #define next() { current = input(); } |
| @@ -21,7 +24,8 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; | |||
| 21 | #define save_and_next() { save(current); next(); } | 24 | #define save_and_next() { save(current); next(); } |
| 22 | 25 | ||
| 23 | static int current; | 26 | static int current; |
| 24 | static char yytext[3000]; | 27 | static char *yytext = NULL; |
| 28 | static int textsize = 0; | ||
| 25 | static char *yytextLast; | 29 | static char *yytextLast; |
| 26 | 30 | ||
| 27 | static Input input; | 31 | static Input input; |
| @@ -30,6 +34,11 @@ void lua_setinput (Input fn) | |||
| 30 | { | 34 | { |
| 31 | current = ' '; | 35 | current = ' '; |
| 32 | input = fn; | 36 | input = fn; |
| 37 | if (yytext == NULL) | ||
| 38 | { | ||
| 39 | textsize = MINBUFF; | ||
| 40 | yytext = newvector(textsize, char); | ||
| 41 | } | ||
| 33 | } | 42 | } |
| 34 | 43 | ||
| 35 | char *lua_lasttext (void) | 44 | char *lua_lasttext (void) |
| @@ -85,35 +94,52 @@ static int findReserved (char *name) | |||
| 85 | } | 94 | } |
| 86 | 95 | ||
| 87 | 96 | ||
| 97 | static void growtext (void) | ||
| 98 | { | ||
| 99 | int size = yytextLast - yytext; | ||
| 100 | textsize *= 2; | ||
| 101 | yytext = growvector(yytext, textsize, char); | ||
| 102 | yytextLast = yytext + size; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 88 | static int read_long_string (void) | 106 | static int read_long_string (void) |
| 89 | { | 107 | { |
| 90 | int cont = 0; | 108 | int cont = 0; |
| 109 | int spaceleft = textsize - (yytextLast - yytext); | ||
| 91 | while (1) | 110 | while (1) |
| 92 | { | 111 | { |
| 112 | if (spaceleft <= 2) /* may read more than 1 char in one cicle */ | ||
| 113 | { | ||
| 114 | growtext(); | ||
| 115 | spaceleft = textsize - (yytextLast - yytext); | ||
| 116 | } | ||
| 93 | switch (current) | 117 | switch (current) |
| 94 | { | 118 | { |
| 95 | case EOF: | 119 | case EOF: |
| 96 | case 0: | 120 | case 0: |
| 97 | return WRONGTOKEN; | 121 | return WRONGTOKEN; |
| 98 | case '[': | 122 | case '[': |
| 99 | save_and_next(); | 123 | save_and_next(); spaceleft--; |
| 100 | if (current == '[') | 124 | if (current == '[') |
| 101 | { | 125 | { |
| 102 | cont++; | 126 | cont++; |
| 103 | save_and_next(); | 127 | save_and_next(); spaceleft--; |
| 104 | } | 128 | } |
| 105 | continue; | 129 | continue; |
| 106 | case ']': | 130 | case ']': |
| 107 | save_and_next(); | 131 | save_and_next(); spaceleft--; |
| 108 | if (current == ']') | 132 | if (current == ']') |
| 109 | { | 133 | { |
| 110 | if (cont == 0) return STRING; | 134 | if (cont == 0) return STRING; |
| 111 | cont--; | 135 | cont--; |
| 112 | save_and_next(); | 136 | save_and_next(); spaceleft--; |
| 113 | } | 137 | } |
| 114 | continue; | 138 | continue; |
| 139 | case '\n': | ||
| 140 | lua_linenumber++; /* goes through */ | ||
| 115 | default: | 141 | default: |
| 116 | save_and_next(); | 142 | save_and_next(); spaceleft--; |
| 117 | } | 143 | } |
| 118 | } | 144 | } |
| 119 | } | 145 | } |
| @@ -200,9 +226,16 @@ int yylex (void) | |||
| 200 | case '\'': | 226 | case '\'': |
| 201 | { | 227 | { |
| 202 | int del = current; | 228 | int del = current; |
| 229 | int spaceleft = textsize - (yytextLast - yytext); | ||
| 203 | next(); /* skip the delimiter */ | 230 | next(); /* skip the delimiter */ |
| 204 | while (current != del) | 231 | while (current != del) |
| 205 | { | 232 | { |
| 233 | if (spaceleft <= 2) /* may read more than 1 char in one cicle */ | ||
| 234 | { | ||
| 235 | growtext(); | ||
| 236 | spaceleft = textsize - (yytextLast - yytext); | ||
| 237 | } | ||
| 238 | spaceleft--; | ||
| 206 | switch (current) | 239 | switch (current) |
| 207 | { | 240 | { |
| 208 | case EOF: | 241 | case EOF: |
