2 Star 0 Fork 0

kernel64 / XML-base-interpreter

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

一个基于XML词法分析实现的微型的解释器, 仅 233 行代码,

实现了:

变量定义(var),

赋值(set),

条件判断(if),

循环(for,while),

算术运算(+,-,*,/,%),

函数(Func,RETURN,CALL),

输入(READLINE),

输出(PRINT,PRINTLN),

An tiny interpreter,based on XML analysis, only 233 lines of code,

Implement features:

Variable definition (var);

Assignment (set);

Conditional judgment (if);

Loop (for, while);

Arithmetic operations (+, -, *, /,%);

Functions (Func, RETURN, CALL);

Input (READLINE);

Output (PRINT, PRINTLN);

示例/Example

var ticks = Environment.TickCount;
new Interpreter().Eval(@"
<PROGRAM>
    <PRINT V='please input your name:' />
    <VAR str='guest' />
    <READLINE str='' />
    <PRINT V='hello!' />
    <PRINTLN V='str' />

	<FOR_LT i='0' TO='3'>
        <IF_GE i='2'>
            <PRINTLN V='have a good day!' />
        </IF_GE>
        <PRINT V='welcome!' />
		<PRINTLN V='str' />
	</FOR_LT>
    <PRINT V='i=' />
    <PRINTLN V='i' />
    <WHILE_GT i='0'>
        <SUB i='1' />
        <PRINT V='i--=' />
        <PRINTLN V='i' />
    </WHILE_GT>
    <FUNC add='FLOAT' x='FLOAT' y='FLOAT'>
        <SET add='x' />
        <ADD add='y' />
    </FUNC>
    <VAR f='0' />
    <CALL f='add' x='123' y='456' />
    <PRINT V='call func add(123,456)=' />
    <PRINT V='123+456=' />
    <PRINTLN V='f' />
</PROGRAM>
");
ticks = Environment.TickCount - ticks;
Console.WriteLine("done. elapse:{0} ms", ticks);
Console.ReadLine();
MIT License Copyright (c) 2017 zhangxx2015 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.

简介

一个基于XML词法分析实现的微型的解释器, 仅 233 行代码 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/fools2015/XML-base-interpreter.git
git@gitee.com:fools2015/XML-base-interpreter.git
fools2015
XML-base-interpreter
XML-base-interpreter
master

搜索帮助