zoukankan      html  css  js  c++  java
  • 修改 Lua支持中文变量名

    1. 找到 LuaPlus 工程下的 Lua Source Files 下的 llex.c;
     
    2. 在该文件中找到下面所列函数;
    static int llex (LexState *ls, SemInfo *seminfo)
    3. 这是 Lua 的语法分析模块的关键函数,它由一长段 switch 构成,在一串 case 后找到 default 分支
     
    4. 在该分支下找到如下代码段,这是一段完整的 if 分支,该代码段负责将符合条件的字符组合识别为 identifier (函数名或变量名)或 keyword (关键字)
    else if (isalpha(ls->current) || ls->current == '_') {
    02.          /* identifier or reserved word */
    03.          TString *ts;
    04.          if (ls->current == 'L') {
    05.            next(ls);
    06.            if (ls->current == '"' || ls->current == '/'') {
    07.              read_wstring(ls, ls->current, seminfo);
    08.              return TK_WSTRING;
    09.            }
    10.            save(ls, 'L');
    11.          }
    12.          /* identifier or reserved word */
    13.          do {
    14.            save_and_next(ls);
    15.          } while (isalnum(ls->current) || ls->current == '_');
    16.          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
    17.                                  luaZ_bufflen(ls->buff));
    18.          if (ts->tsv.reserved > 0)  /* reserved word? */
    19.            return ts->tsv.reserved - 1 + FIRST_RESERVED;
    20.          else {
    21.            seminfo->ts = ts;
    22.            return TK_NAME;
    23.          }
    24.        }

    5. 将该段替换为下面这一段即可,其作用在于加入了对中文ASCII字符的识别

    else if (isalpha(ls->current) || ls->current == '_' || ls->current > 0x80) {
    02.          /* identifier or reserved word */
    03.          TString *ts;
    04.          if (ls->current == 'L') {
    05.            next(ls);
    06.            if (ls->current == '"' || ls->current == '/'') {
    07.              read_wstring(ls, ls->current, seminfo);
    08.              return TK_WSTRING;
    09.            }
    10.            save(ls, 'L');
    11.          }
    12.          /* identifier or reserved word */
    13.          do {
    14.              if(ls->current > 0x80)
    15.              {
    16.                 save_and_next(ls);
    17.                 save_and_next(ls);
    18.              }
    19.              else
    20.                 save_and_next(ls);
    21.          } while (isalnum(ls->current) || ls->current == '_' || ls->current > 0x80);
    22.          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
    23.                                  luaZ_bufflen(ls->buff));
    24.          if (ts->tsv.reserved > 0)  /* reserved word? */
    25.            return ts->tsv.reserved - 1 + FIRST_RESERVED;
    26.          else {
    27.            seminfo->ts = ts;
    28.            return TK_NAME;
    29.          }
    30.        }
  • 相关阅读:
    图解JAVA对象的创建过程
    统计机器学习
    排序算法简介及其C实现
    linux中强大的screen命令
    C语言注释
    Hello hadoop——使用hadoop进行大规模数据的全局排序
    Hadoop Streaming框架使用(二)
    shell——tr的用法
    统计学习方法《文本分类(三)》
    hadoop 常存问题
  • 原文地址:https://www.cnblogs.com/wumac/p/4288642.html
Copyright © 2011-2022 走看看