浏览代码

fix: 调整了lexical和syntax中的字符类型

把char调整为int
SongZihuan 4 年之前
父节点
当前提交
e5e526ac99
共有 4 个文件被更改,包括 16 次插入16 次删除
  1. 3 3
      include/lexical.h
  2. 5 5
      include/syntax.h
  3. 2 2
      parser/lexical.c
  4. 6 6
      parser/syntax.c

+ 3 - 3
include/lexical.h

@@ -6,7 +6,7 @@ struct LexFile{
     FILE *file;
     struct LexFileBack{
         bool is_back;
-        signed char p;
+        int p;
     } back;
     long int count;
     long int line;
@@ -14,7 +14,7 @@ struct LexFile{
 
 struct LexMather{
     int len;
-    signed char string_type;
+    int string_type;
     char *str;
     char *second_str;
     enum LexMatherStatus{
@@ -38,7 +38,7 @@ typedef struct LexFile LexFile;
 typedef struct LexMather LexMather;
 typedef struct LexMathers LexMathers;
 
-signed char readChar(LexFile *file);
+int readChar(LexFile *file);
 void backChar(LexFile *file);
 
 LexFile *makeLexFile(char *dir);

+ 5 - 5
include/syntax.h

@@ -4,10 +4,10 @@
 #define strMatherMacro(n, word) strMather(p, mathers->mathers[n], word) /*这个宏只能用于getMatherStatus*/
 #define charMatherMacro(n, word) charMather(p, mathers->mathers[n], word) /*这个宏只能用于getMatherStatus*/
 
-void numberMather(signed char p, LexMather *mather);
-void varMather(signed char p, LexMather *mather);
-void stringMather(signed char p, LexMather *mather);
-void strMather(signed char p, LexMather *mather, const char *dest_p);
-void charMather(signed char p, LexMather *mather, signed char dest_p);
+void numberMather(int p, LexMather *mather);
+void varMather(int p, LexMather *mather);
+void stringMather(int p, LexMather *mather);
+void strMather(int p, LexMather *mather, const char *dest_p);
+void charMather(int p, LexMather *mather, int dest_p);
 
 #endif //VIRTUALMATH_SYNTAX_H

+ 2 - 2
parser/lexical.c

@@ -6,11 +6,11 @@
  * @param file
  * @return 返回一个字符,若为EOF则返回-1
  */
-signed char readChar(LexFile *file){
+int readChar(LexFile *file){
     if (file->back.is_back)
         file->back.is_back = false;
     else {
-        file->back.p = (char) fgetc(file->file);
+        file->back.p = fgetc(file->file);
         if (file->back.p == '\n')
             file->line ++;
     }

+ 6 - 6
parser/syntax.c

@@ -12,7 +12,7 @@
  * @param p
  * @param mather
  */
-void numberMather(signed char p, LexMather *mather){
+void numberMather(int p, LexMather *mather){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING || mather->status == LEXMATHER_INGPOINT){
         if ('0'<= p && '9' >= p || '.' == p && mather->status == LEXMATHER_ING){
             mather->str = memStrcpy(mather->str, 1, true, true, p);
@@ -57,7 +57,7 @@ void numberMather(signed char p, LexMather *mather){
  * @param p
  * @param mather
  */
-void varMather(signed char p, LexMather *mather){
+void varMather(int p, LexMather *mather){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING){
         if ('A'<= p && 'Z' >= p ||'a'<= p && 'z' >= p ||'_' == p ||
             '0'<= p && '9' >= p && mather->status == LEXMATHER_ING){
@@ -85,7 +85,7 @@ void varMather(signed char p, LexMather *mather){
  * @param p
  * @param mather
  */
-void stringMather(signed char p, LexMather *mather){
+void stringMather(int p, LexMather *mather){
     if (mather->status == LEXMATHER_START){
         if ('\"' == p || '\'' == p){
             mather->status = LEXMATHER_ING;
@@ -137,7 +137,7 @@ void stringMather(signed char p, LexMather *mather){
  * @param mather
  * @param dest_p
  */
-void strMather(signed char p, LexMather *mather, const char *dest_p){
+void strMather(int p, LexMather *mather, const char *dest_p){
     if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING){
         if (p == dest_p[mather->len]){
             mather->str = memStrcpy(mather->str, 1, true, true, p);
@@ -162,7 +162,7 @@ void strMather(signed char p, LexMather *mather, const char *dest_p){
  * @param mather
  * @param dest_p
  */
-void charMather(signed char p, LexMather *mather, signed char dest_p){
+void charMather(int p, LexMather *mather, int dest_p){
     if (p == dest_p && mather->status == LEXMATHER_START){
         mather->str = memStrcpy(mather->str, 1, true, true, p);
         mather->len ++;
@@ -186,7 +186,7 @@ int getMatherStatus(LexFile *file, LexMathers *mathers, FILE *debug) {
     setupMathers(mathers);
     int status = -1;
     while (status == -1){
-        signed char p = readChar(file);
+        int p = readChar(file);
         if (p == EOF)
             writeLog_(debug, LEXICAL_DEBUG, "get char: (EOF)\n", NULL);
         else if (p == '\n')