]> j8takagi.net git repositories - yacasl2.git/commitdiff
文字定数の取得方法を整理
authorj8takagi <j8takagi@nifty.com>
Thu, 9 Jul 2026 14:13:29 +0000 (23:13 +0900)
committerj8takagi <j8takagi@nifty.com>
Thu, 9 Jul 2026 14:13:29 +0000 (23:13 +0900)
https://claude.ai/chat/29258bee-49a5-44a7-ae57-cdb98d05d688

39 files changed:
as/err/err_123_literal_1.casl [moved from as/err/err_123_literal.casl with 100% similarity]
as/err/err_123_literal_2.casl [moved from as/err/err_128.casl with 61% similarity]
as/err/err_124_literal_1.casl [new file with mode: 0644]
as/err/err_124_literal_2.casl [new file with mode: 0644]
as/err/err_126.casl [new file with mode: 0644]
as/err/err_126_literal_2.casl [new file with mode: 0644]
as/err/err_127_literal.casl [new file with mode: 0644]
src/assemble.c
src/casl2.c
src/label.c
test/system/casl2_cmd/cmd_dc__c2/0.txt [deleted file]
test/system/casl2_cmd/cmd_dc__c2/cmd [deleted file]
test/system/casl2_err/err_123_literal/0.txt [deleted file]
test/system/casl2_err/err_123_literal/cmd [deleted file]
test/system/casl2_err/err_123_literal_1/0.txt [new file with mode: 0644]
test/system/casl2_err/err_123_literal_1/Makefile [moved from test/system/casl2_cmd/cmd_dc__c2/Makefile with 100% similarity]
test/system/casl2_err/err_123_literal_1/cmd [new file with mode: 0755]
test/system/casl2_err/err_123_literal_2/0.txt [new file with mode: 0644]
test/system/casl2_err/err_123_literal_2/Makefile [moved from test/system/casl2_err/err_123_literal/Makefile with 100% similarity]
test/system/casl2_err/err_123_literal_2/cmd [new file with mode: 0755]
test/system/casl2_err/err_124_literal_1/0.txt [new file with mode: 0644]
test/system/casl2_err/err_124_literal_1/Makefile [new file with mode: 0644]
test/system/casl2_err/err_124_literal_1/cmd [new file with mode: 0755]
test/system/casl2_err/err_124_literal_2/0.txt [new file with mode: 0644]
test/system/casl2_err/err_124_literal_2/Makefile [new file with mode: 0644]
test/system/casl2_err/err_124_literal_2/cmd [new file with mode: 0755]
test/system/casl2_err/err_126/0.txt
test/system/casl2_err/err_126/cmd
test/system/casl2_err/err_126_literal/0.txt [new file with mode: 0644]
test/system/casl2_err/err_126_literal/Makefile [new file with mode: 0644]
test/system/casl2_err/err_126_literal/cmd [new file with mode: 0755]
test/system/casl2_err/err_127/0.txt
test/system/casl2_err/err_127/cmd
test/system/casl2_err/err_127_literal/0.txt [new file with mode: 0644]
test/system/casl2_err/err_127_literal/Makefile [new file with mode: 0644]
test/system/casl2_err/err_127_literal/cmd [new file with mode: 0755]
test/system/casl2_err/err_128/0.txt [new file with mode: 0644]
test/system/casl2_err/err_128/Makefile [new file with mode: 0644]
test/system/casl2_err/err_128/cmd [new file with mode: 0755]

similarity index 61%
rename from as/err/err_128.casl
rename to as/err/err_123_literal_2.casl
index 8d9ff9a179e7df4071af7a106001a5eae98d3a5d..49876fe7ac8c1275f6e591c35d35b210caf2aba7 100644 (file)
@@ -1,4 +1,4 @@
 MAIN    START
-        LAD     GR1,=''
+        LAD     GR1,='
 END     RET
         END
diff --git a/as/err/err_124_literal_1.casl b/as/err/err_124_literal_1.casl
new file mode 100644 (file)
index 0000000..c3a4061
--- /dev/null
@@ -0,0 +1,4 @@
+MAIN    START
+        LAD     GR1,='ab'
+END     RET
+        END
diff --git a/as/err/err_124_literal_2.casl b/as/err/err_124_literal_2.casl
new file mode 100644 (file)
index 0000000..2688ca8
--- /dev/null
@@ -0,0 +1,5 @@
+MAIN    START
+        LAD     GR1,=''''
+        LAD     GR2,='''a'
+END     RET
+        END
diff --git a/as/err/err_126.casl b/as/err/err_126.casl
new file mode 100644 (file)
index 0000000..fcebf08
--- /dev/null
@@ -0,0 +1,4 @@
+MAIN    START
+END     RET
+        DC 'a'b'
+        END
diff --git a/as/err/err_126_literal_2.casl b/as/err/err_126_literal_2.casl
new file mode 100644 (file)
index 0000000..eeca618
--- /dev/null
@@ -0,0 +1,4 @@
+MAIN    START
+        LAD     GR1,='''
+END     RET
+        END
diff --git a/as/err/err_127_literal.casl b/as/err/err_127_literal.casl
new file mode 100644 (file)
index 0000000..eeca618
--- /dev/null
@@ -0,0 +1,4 @@
+MAIN    START
+        LAD     GR1,='''
+END     RET
+        END
index 014d40a658e5f1fc0c7c491d7ac1c79a9684882b..bb765dcaed68bc98fda675a2e097a9c8155b558b 100644 (file)
@@ -271,7 +271,8 @@ static CERR cerr_assemble[] = {
     { 122, "cannot create hash table" },
     { 124, "more than one character in literal" },
     { 125, "not GR in operand x" },
-    { 126, "syntax error in literal" },
+    { 126, "syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe (')." },
+    { 127, "empty character constant" },
 };
 
 /**
@@ -384,12 +385,14 @@ WORD getliteralquote(const char *str)
     assert(str[0] == '\'');
     size_t len = strlen(str);
     WORD val = 0;
-    if (len < 2 || str[len - 1] != '\'' || (str[1] == '\'' && len == 3)) {
+    if(str[1] == '\'' && len == 2) {
+        setcerr(127, str);    /* empty character constant */
+    } else if (len == 1 || str[len - 1] != '\'') {
         setcerr(123, str);    /* unclosed quote */
     } else if((str[1] != '\'' && len > 3) || (str[1] == '\'' && len > 4)) {
         setcerr(124, str);    /* more than one character in literal */
-    } else if(len ==2 && !strcmp(str, "''")) {
-        setcerr(126, str);    /* syntax error in literal */
+    } else if(str[1] == '\'' && len == 3 && str[2] == '\'') {
+        setcerr(126, str);    /* syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe ('). */
     } else {
         val = (WORD)str[1];
     }
@@ -416,14 +419,32 @@ void writestr(const char *str, PASS pass)
 {
     assert(str[0] == '\'');
 
-    /* 「'」1文字スキップし、次の文字が「'」でなければ正常終了 */
-    for(int i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
-        /* 「'」が閉じないまま文字列が終了した場合はエラー */
-        if(!str[i]) {
-            setcerr(123, str);    /* unclosed quote */
-            break;
-        }
-        writememory(str[i], (asptr->ptr)++, pass);
+    /* 空文字列(DC '')はエラー */
+    if(str[1] == '\'' && str[2] == '\0') {
+        setcerr(127, str);    /* empty character constant */
+    } else {
+        int i = 1;
+        do {
+            if(str[i] == '\0') {
+                /* 閉じクォートがないまま文字列が終了の場合 */
+                setcerr(123, str);    /* unclosed quote */
+                break;
+            }
+            if(str[i] == '\'') {
+                if(str[i + 1] != '\0' && str[i + 1] != '\'') {
+                    setcerr(126, str);    /* syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe ('). */
+                    break;
+                } else if(str[i + 1] == '\0') {
+                    break;         /* 正常終了 */
+                } else {
+                    /* エスケープされたアポストロフィ:1文字として書き込み、2文字分進める */
+                    writememory('\'', (asptr->ptr)++, pass);
+                    i += 2;
+                }
+            } else {
+                writememory(str[i++], (asptr->ptr)++, pass);
+            }
+        } while(1);
     }
 }
 
index c94c97548eb80004229b0c126d242bca2fed8e3a..b8498a082962608ac886c9077094373b6b79b50f 100644 (file)
@@ -46,7 +46,7 @@ static struct option longopts[] = {
  * @brief casl2のエラー定義
  */
 CERR cerr_casl2[] = {
-    { 127, "no source file" },
+    { 128, "no source file" },
 };
 
 void addcerrlist_casl2()
@@ -160,7 +160,7 @@ int main(int argc, char *argv[])
 
     /* ソースファイルが指定されていない場合は終了 */
     if(argv[optind] == NULL) {
-        setcerr(127, "");    /* no source file */
+        setcerr(128, "");    /* no source file */
         fprintf(stderr, "casl2 error - %d: %s\n", cerr->num, cerr->msg);
         goto casl2fin;
     }
index 842e34050e210b1209e054e2c11db9dc60a7670e..df936efa9b708efd87b8ef1ee8952064e33d2b56 100644 (file)
@@ -1,7 +1,7 @@
 #include "assemble.h"
 
 /**
- * ラベルのハッシュ値をセットしたキーを返す
+ * @brief ラベルのハッシュ値をセットしたキーを返す
  *
  * @return ハッシュ値をセットしたキー
  *
@@ -10,7 +10,7 @@
 HKEY *label_hashkey(const char *value);
 
 /**
- * プログラム名とラベルに対応するハッシュ値を返す
+ * @brief プログラム名とラベルに対応するハッシュ値を返す
  *
  * @return ハッシュ値
  *
@@ -20,7 +20,7 @@ HKEY *label_hashkey(const char *value);
 unsigned labelhash(const char *prog, const char *label);
 
 /**
- * ラベルを比較した結果を返す。qsort内で使われる関数
+ * @brief ラベルを比較した結果を返す。qsort内で使われる関数
  *
  * @return ラベルが同一の場合は0、異なる場合は0以外
  *
@@ -30,9 +30,7 @@ unsigned labelhash(const char *prog, const char *label);
 int compare_adr(const void *a, const void *b);
 
 /**
- * 定義されているラベルまたはリテラルの一覧を表示する
- *
- * @return ラベルが同一の場合は0、異なる場合は0以外
+ * @brief 定義されているラベルまたはリテラルの一覧を表示する
  *
  * @param literal リテラルの場合はtrue、それ以外はfalse
  */
diff --git a/test/system/casl2_cmd/cmd_dc__c2/0.txt b/test/system/casl2_cmd/cmd_dc__c2/0.txt
deleted file mode 100644 (file)
index e795fca..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-
-Assemble ../../../../as/cmd/DC/dc__c2.casl (0)
-
-Assemble ../../../../as/cmd/DC/dc__c2.casl (1)
-../../../../as/cmd/DC/dc__c2.casl:    1:;; DC 文字定数
-../../../../as/cmd/DC/dc__c2.casl:    2:MAIN    START
-../../../../as/cmd/DC/dc__c2.casl:    3:        RET
-       #0000   #8100
-../../../../as/cmd/DC/dc__c2.casl:    4:        DC      ''
-../../../../as/cmd/DC/dc__c2.casl:    5:        END
-#0000: Register::::
-#0000: GR0:      0 = #0000 = 0000000000000000
-#0000: GR1:      0 = #0000 = 0000000000000000
-#0000: GR2:      0 = #0000 = 0000000000000000
-#0000: GR3:      0 = #0000 = 0000000000000000
-#0000: GR4:      0 = #0000 = 0000000000000000
-#0000: GR5:      0 = #0000 = 0000000000000000
-#0000: GR6:      0 = #0000 = 0000000000000000
-#0000: GR7:      0 = #0000 = 0000000000000000
-#0000: SP:     128 = #0080 = 0000000010000000
-#0000: PR:       0 = #0000 = 0000000000000000
-#0000: FR (OF SF ZF): 000
-#0000: Memory::::
-#0000: adr : 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F
-       -------------------------------------------------------------------------------------
-#0000: 0000: 8100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0010: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0020: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0030: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0040: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0050: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0060: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-#0000: 0070: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
-
diff --git a/test/system/casl2_cmd/cmd_dc__c2/cmd b/test/system/casl2_cmd/cmd_dc__c2/cmd
deleted file mode 100755 (executable)
index d6a01d4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../../../casl2 -atd -M128 ../../../../as/cmd/DC/dc__c2.casl
diff --git a/test/system/casl2_err/err_123_literal/0.txt b/test/system/casl2_err/err_123_literal/0.txt
deleted file mode 100644 (file)
index f8e8c51..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Assemble error - 123: GR1,='a: unclosed quote
-../../../../as/err/err_123_literal.casl:    2:        LAD     GR1,='a
diff --git a/test/system/casl2_err/err_123_literal/cmd b/test/system/casl2_err/err_123_literal/cmd
deleted file mode 100755 (executable)
index 46cbbea..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../../../casl2 ../../../../as/err/err_123_literal.casl
diff --git a/test/system/casl2_err/err_123_literal_1/0.txt b/test/system/casl2_err/err_123_literal_1/0.txt
new file mode 100644 (file)
index 0000000..c2a1d0c
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 123: GR1,='a: unclosed quote
+../../../../as/err/err_123_literal_1.casl:    2:        LAD     GR1,='a
diff --git a/test/system/casl2_err/err_123_literal_1/cmd b/test/system/casl2_err/err_123_literal_1/cmd
new file mode 100755 (executable)
index 0000000..97f230f
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_123_literal_1.casl
diff --git a/test/system/casl2_err/err_123_literal_2/0.txt b/test/system/casl2_err/err_123_literal_2/0.txt
new file mode 100644 (file)
index 0000000..c0ca382
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 123: GR1,=': unclosed quote
+../../../../as/err/err_123_literal_2.casl:    2:        LAD     GR1,='
diff --git a/test/system/casl2_err/err_123_literal_2/cmd b/test/system/casl2_err/err_123_literal_2/cmd
new file mode 100755 (executable)
index 0000000..be700b8
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_123_literal_2.casl
diff --git a/test/system/casl2_err/err_124_literal_1/0.txt b/test/system/casl2_err/err_124_literal_1/0.txt
new file mode 100644 (file)
index 0000000..9f6493f
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 124: 'ab': more than one character in literal
+../../../../as/err/err_124_literal_1.casl:    2:        LAD     GR1,='ab'
diff --git a/test/system/casl2_err/err_124_literal_1/Makefile b/test/system/casl2_err/err_124_literal_1/Makefile
new file mode 100644 (file)
index 0000000..b6dac59
--- /dev/null
@@ -0,0 +1,2 @@
+include ../Define.mk
+include ../Test.mk
diff --git a/test/system/casl2_err/err_124_literal_1/cmd b/test/system/casl2_err/err_124_literal_1/cmd
new file mode 100755 (executable)
index 0000000..807b6fc
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_124_literal_1.casl
diff --git a/test/system/casl2_err/err_124_literal_2/0.txt b/test/system/casl2_err/err_124_literal_2/0.txt
new file mode 100644 (file)
index 0000000..9fd3880
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 124: '''a': more than one character in literal
+../../../../as/err/err_124_literal_2.casl:    3:        LAD     GR2,='''a'
diff --git a/test/system/casl2_err/err_124_literal_2/Makefile b/test/system/casl2_err/err_124_literal_2/Makefile
new file mode 100644 (file)
index 0000000..b6dac59
--- /dev/null
@@ -0,0 +1,2 @@
+include ../Define.mk
+include ../Test.mk
diff --git a/test/system/casl2_err/err_124_literal_2/cmd b/test/system/casl2_err/err_124_literal_2/cmd
new file mode 100755 (executable)
index 0000000..ec84579
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_124_literal_2.casl
index a080fa2ab2cee867ed84b65ad76e90ce0997998f..0b50b30f1d90478c17ebc7794f6456b2ecd80d50 100644 (file)
@@ -1,2 +1,2 @@
-Assemble error - 126: '': syntax error in literal
-../../../../as/err/err_128.casl:    2:        LAD     GR1,=''
+Assemble error - 126: 'a'b': syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe (').
+../../../../as/err/err_126.casl:    3:        DC 'a'b'
index fbb3c84c22c79766bd9fc76a25ba31d28efc7b97..a71676b42419b048e3247175aea08981b04bb071 100755 (executable)
@@ -1 +1 @@
-../../../../casl2 ../../../../as/err/err_128.casl
+../../../../casl2 ../../../../as/err/err_126.casl
diff --git a/test/system/casl2_err/err_126_literal/0.txt b/test/system/casl2_err/err_126_literal/0.txt
new file mode 100644 (file)
index 0000000..b20ea39
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 126: ''': syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe (').
+../../../../as/err/err_126_literal_2.casl:    2:        LAD     GR1,='''
diff --git a/test/system/casl2_err/err_126_literal/Makefile b/test/system/casl2_err/err_126_literal/Makefile
new file mode 100644 (file)
index 0000000..b6dac59
--- /dev/null
@@ -0,0 +1,2 @@
+include ../Define.mk
+include ../Test.mk
diff --git a/test/system/casl2_err/err_126_literal/cmd b/test/system/casl2_err/err_126_literal/cmd
new file mode 100755 (executable)
index 0000000..4b14816
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_126_literal_2.casl
index c13b9793b9c0a9878e96654aa9eff3141c22c100..f27c10caa57a56dd140a9e982b97b45c6e71633f 100644 (file)
@@ -1 +1,4 @@
-casl2 error - 127: no source file
+
+Assemble ../../../../as/cmd/DC/dc__c2.casl (0)
+Assemble error - 127: '': empty character constant
+../../../../as/cmd/DC/dc__c2.casl:    4:        DC      ''
index 0a373c3cdee08eb4ed7655257ab39e0730ccb034..d6a01d4cd1d931753462517afe9f9e8df65d7ce1 100755 (executable)
@@ -1 +1 @@
-../../../../casl2
+../../../../casl2 -atd -M128 ../../../../as/cmd/DC/dc__c2.casl
diff --git a/test/system/casl2_err/err_127_literal/0.txt b/test/system/casl2_err/err_127_literal/0.txt
new file mode 100644 (file)
index 0000000..5b2700a
--- /dev/null
@@ -0,0 +1,2 @@
+Assemble error - 126: ''': syntax error in character constant. In CASL II, two consecutive apostrophes ('') represent a single apostrophe (').
+../../../../as/err/err_127_literal.casl:    2:        LAD     GR1,='''
diff --git a/test/system/casl2_err/err_127_literal/Makefile b/test/system/casl2_err/err_127_literal/Makefile
new file mode 100644 (file)
index 0000000..b6dac59
--- /dev/null
@@ -0,0 +1,2 @@
+include ../Define.mk
+include ../Test.mk
diff --git a/test/system/casl2_err/err_127_literal/cmd b/test/system/casl2_err/err_127_literal/cmd
new file mode 100755 (executable)
index 0000000..6346e44
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2 ../../../../as/err/err_127_literal.casl
diff --git a/test/system/casl2_err/err_128/0.txt b/test/system/casl2_err/err_128/0.txt
new file mode 100644 (file)
index 0000000..e1cc77a
--- /dev/null
@@ -0,0 +1 @@
+casl2 error - 128: no source file
diff --git a/test/system/casl2_err/err_128/Makefile b/test/system/casl2_err/err_128/Makefile
new file mode 100644 (file)
index 0000000..b6dac59
--- /dev/null
@@ -0,0 +1,2 @@
+include ../Define.mk
+include ../Test.mk
diff --git a/test/system/casl2_err/err_128/cmd b/test/system/casl2_err/err_128/cmd
new file mode 100755 (executable)
index 0000000..0a373c3
--- /dev/null
@@ -0,0 +1 @@
+../../../../casl2