summaryrefslogtreecommitdiff
path: root/yacc/reader.c
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2004-04-21 23:26:06 +0000
committerDamien Doligez <damien.doligez-inria.fr>2004-04-21 23:26:06 +0000
commit7405556404b5034a7489b6541045064bc1f4600a (patch)
tree781856ceffa9ce60cbbb536901421d10fe5d20c9 /yacc/reader.c
parent2158b37ebdd8d5c25ba9ee06fbca5ecdd7e3a272 (diff)
downloadocaml-7405556404b5034a7489b6541045064bc1f4600a.tar.gz
directives #line pour lex et yacc
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6244 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'yacc/reader.c')
-rw-r--r--yacc/reader.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/yacc/reader.c b/yacc/reader.c
index 5ab9997d63..73165601b1 100644
--- a/yacc/reader.c
+++ b/yacc/reader.c
@@ -155,6 +155,51 @@ void skip_comment(void)
}
}
+char *substring (char *str, int start, int len)
+{
+ int i;
+ char *buf = MALLOC (len+1);
+ if (buf == NULL) return NULL;
+ for (i = 0; i < len; i++){
+ buf[i] = str[start+i];
+ }
+ return buf;
+}
+
+void parse_line_directive (void)
+{
+ int i = 0, j = 0;
+ int line_number = 0;
+ char *file_name = NULL;
+
+ again:
+ if (line == 0) return;
+ if (line[i] != '#') return;
+ ++ i;
+ while (line[i] == ' ' || line[i] == '\t') ++ i;
+ if (line[i] < '0' || line[i] > '9') return;
+ while (line[i] >= '0' && line[i] <= '9'){
+ line_number = line_number * 10 + line[i] - '0';
+ ++ i;
+ }
+ while (line[i] == ' ' || line[i] == '\t') ++ i;
+ if (line[i] == '"'){
+ ++ i;
+ j = i;
+ while (line[j] != '"' && line[j] != '\0') ++j;
+ if (line[j] == '"'){
+ file_name = substring (line, i, j - i);
+ if (file_name == NULL) no_space ();
+ }
+ }
+ lineno = line_number - 1;
+ if (file_name != NULL){
+ if (virtual_input_file_name != NULL) FREE (virtual_input_file_name);
+ virtual_input_file_name = file_name;
+ }
+ get_line ();
+ goto again;
+}
int
nextc(void)
@@ -164,6 +209,7 @@ nextc(void)
if (line == 0)
{
get_line();
+ parse_line_directive ();
if (line == 0)
return (EOF);
}
@@ -175,6 +221,7 @@ nextc(void)
{
case '\n':
get_line();
+ parse_line_directive ();
if (line == 0) return (EOF);
s = cptr;
break;
@@ -204,6 +251,7 @@ nextc(void)
else if (s[1] == '/')
{
get_line();
+ parse_line_directive ();
if (line == 0) return (EOF);
s = cptr;
break;
@@ -1823,6 +1871,8 @@ void print_grammar(void)
void reader(void)
{
+ virtual_input_file_name = substring (input_file_name, 0,
+ strlen (input_file_name));
create_symbol_table();
read_declarations();
output_token_type();