DEADSOFTWARE

Добавлены комментарии
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 24 Jul 2017 19:57:29 +0000 (22:57 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 24 Jul 2017 19:57:29 +0000 (22:57 +0300)
notes
oberon.c
test.c

diff --git a/notes b/notes
index c1a8b0b5dfc95559b85b6c5fdbf0dbad7a58e315..4133badb548062218500fb6a93abea0594551be3 100644 (file)
--- a/notes
+++ b/notes
@@ -1,5 +1,3 @@
-- нету комментариев
-
 - нету тестовых процедур для ввода-вывода
 - нету процедуры NEW
 - нету открытых массивов
index b56a458a6c1e979a743c9d4139b5df3044f1cdc3..e857b1d1ec6f93e454b5439cdcf81f96c150d167 100644 (file)
--- a/oberon.c
+++ b/oberon.c
@@ -228,8 +228,11 @@ oberon_define_type(oberon_scope_t * scope, char * name, oberon_type_t * type, in
 static void
 oberon_get_char(oberon_context_t * ctx)
 {
-       ctx -> code_index += 1;
-       ctx -> c = ctx -> code[ctx -> code_index];
+       if(ctx -> code[ctx -> code_index])
+       {
+               ctx -> code_index += 1;
+               ctx -> c = ctx -> code[ctx -> code_index];
+       }
 }
 
 static void
@@ -379,6 +382,43 @@ oberon_skip_space(oberon_context_t * ctx)
        }
 }
 
+static void
+oberon_read_comment(oberon_context_t * ctx)
+{
+       int nesting = 1;
+       while(nesting >= 1)
+       {
+               if(ctx -> c == '(')
+               {
+                       oberon_get_char(ctx);
+                       if(ctx -> c == '*')
+                       {
+                               oberon_get_char(ctx);
+                               nesting += 1;
+                       }
+               }
+               else if(ctx -> c == '*')
+               {
+                       oberon_get_char(ctx);
+                       if(ctx -> c == ')')
+                       {
+                               oberon_get_char(ctx);
+                               nesting -= 1;
+                       }
+               }
+               else if(ctx -> c == 0)
+               {
+                       oberon_error(ctx, "unterminated comment");
+               }
+               else
+               {
+                       oberon_get_char(ctx);
+               }
+       }
+}
+
+static void oberon_read_token(oberon_context_t * ctx);
+
 static void
 oberon_read_symbol(oberon_context_t * ctx)
 {
@@ -408,6 +448,12 @@ oberon_read_symbol(oberon_context_t * ctx)
                case '(':
                        ctx -> token = LPAREN;
                        oberon_get_char(ctx);
+                       if(ctx -> c == '*')
+                       {
+                               oberon_get_char(ctx);
+                               oberon_read_comment(ctx);
+                               oberon_read_token(ctx);
+                       }
                        break;
                case ')':
                        ctx -> token = RPAREN;
@@ -450,6 +496,11 @@ oberon_read_symbol(oberon_context_t * ctx)
                case '*':
                        ctx -> token = STAR;
                        oberon_get_char(ctx);
+                       if(ctx -> c == ')')
+                       {
+                               oberon_get_char(ctx);
+                               oberon_error(ctx, "unstarted comment");
+                       }
                        break;
                case '/':
                        ctx -> token = SLASH;
@@ -480,7 +531,7 @@ oberon_read_symbol(oberon_context_t * ctx)
                        oberon_get_char(ctx);
                        break;
                default:
-                       oberon_error(ctx, "invalid char");
+                       oberon_error(ctx, "invalid char %c", ctx -> c);
                        break;
        }
 }
diff --git a/test.c b/test.c
index 541b3a57f55dae71a8936e0c696f6ad506084340..f1b175cf476d22f404de648888f0d39e45c9de81 100644 (file)
--- a/test.c
+++ b/test.c
@@ -5,6 +5,7 @@
 #include <assert.h>
 
 static char source_test[] =
+       "(* Main module *)"
        "MODULE Test;"
        "IMPORT I := Imported;"
        "VAR"