2 Star 8 Fork 1

小鱼干 / RainbowLexer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

RainbowLexer

简介📃

RainbowLexer是一个可配置的词法分析器💾
RainbowLexer接收一个RainbowLexer可识别的规则描述文档[*.RL文件📃]
RainbowLexer可以基于 RL文件所描述的规则 调试你的 被解析目标文件
RainbowLexer可以编译出对应 RL文件所描述的规则 对应的C文件,其中包含可以解析对应文档的C代码.

目录

RL文件描述规则✏

每一个词法描述单元应以如下方式定义\

type union index_series;
// 说明: 
// type 为 静态词和分隔词
//    静态词type为 sw/staticWord
//    分隔词type为 sp/sperator
// union 为 集合单词
// index_series 为id序列
//    例如[1,2,3,4]对应4个词素id分别为1,2,3,4
//        [4:]表示任意数量词素 id 从4递增
//        [:4]表示任意数量词素 id 从4逆向递减
//        [:]表示任意数量词素  id 从0递增
//        IGNORE 表示该词素不会进入结果列表

例如

sw {"hello","world","test","hel"} [1,2,3,4];
sw {"dididi","hahaha","ppp",__VAR__} [4:];
sp {"%","/","*"} [20:];
sp {" ","\n","\t"} IGNORE;
}

需要注意的是 任何词素都需要用" "包裹
提供了一些已经定义的集合描述\

  • VAR 通用合法变量名集合
  • NUMBER 通用合法数集合
  • STRING_DOUBLE 通用双引号包括字符串
  • STRING_SINGLE 通用单引号包括字符串 若希望引用上述集合,请在描述中以{}包括上述集合
    对单一单词的集合可以简写为
type "token" id

使用方法

在命令行中使用
参数列表\

  • -D [file.RL] >>开启调试模式(不编译,可以单句为单位解析,也可以读入文件)
  • -C file.RL >>编译模式(将file.RL编译为outputfile.c)

编译文件使用说明

对于编译所得的C文件,其中包含3个接口

  1. (void)RainbowLex(const char* string)解析string文件
  2. (token*)RainboNext() 顺序返回一个token结构,包含(id[size_t],token[char*])
  3. FINAL() 放弃所有token,直接结束解析

开发手册

开源声明

MIT License

Copyright (c) 2020-* GuoZi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

帮助

如果在使用RainbowLexer的过程中遇到了问题,您可以在此处或issue中寻找解决方法

  • 果子 (original author)
MIT License Copyright (c) 2020 君子当如BiuBiuBiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

文档描述的通用词法解析器 展开 收起
C 等 3 种语言
MIT
取消

发行版 (3)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/bupt_xyg/RainbowLexer.git
git@gitee.com:bupt_xyg/RainbowLexer.git
bupt_xyg
RainbowLexer
RainbowLexer
master

搜索帮助