Coder Social home page Coder Social logo

feifei61859 / menthol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ltframe/menthol

1.0 0.0 0.0 1.18 MB

Menthol is a very flexible,simple script language,it like javascript or lua,written by C++,use flex and bison

C++ 35.29% C 31.74% Makefile 5.16% M4 20.17% XSLT 4.99% Yacc 1.73% Lex 0.39% Roff 0.52%

menthol's Introduction

Menthol

Menthol is an easy-to-use, easy-to-learn scripting language with a simple syntax and easy development. With C / C++, you can quickly develop extension methods.

Teatures

  • No type
  • Automatic memory management
  • Functional programming
  • Convenient feature pack
  • Simple feature extension development

Tutorial

Keywords
if else for break true false
try except throw continue return while
null import _mmain def var in typeof module use
Operators
- * / () ; , | &  ? [] ! % ^ : :: .. = < > != <> || &&  >= <= == += -= /= *= %= &= |= ^= << >> **
Basic concepts

Menthol is a functional language, but it is a module-based language. In menthol, in addition to the startup function _mmain, other user-defined functions, such as global variables and functions, must be defined based on the module.

Use package

A package is a collection of modules written in Mint or C/C++ with a .med extension. If you want to use a module in a package, you need to import it using the import keyword.

Import "console"

The console is the system's own input and output package, which contains modules that control the inputs and outputs. There is no need to distinguish between file cases when importing.

use module

After importing the package, you can use the modules inside the package. You need to use the use keyword before using it. Note that the module name is case sensitive. You can introduce multiple module names after use, separated by commas.

Import "console"
Use the console;

If you are using modules that are in the same package and defined before use, you do not need to reintroduce them using the use keyword.

Variable concept

All menthol programs start with the system automatically executing _mmain, using the keyword var to declare variables, all global variables must start with @, and there should be a $ in front of the local variable.

module test
{
	var @global;// global variable
}
_mmain:$a,$c
{    
	var $v = 0; //local variable
}
Error handling
import "console"
use Console;
module test
{
	def test:
	{	    
	    throw "msg1","msg2";
	}
}

_mmain:$a,$c
{    
	try{
		test.test();
	}
	except:$a,$b
	{
		Console.Out($a);
		Console.Out($b);
	}
}
Array
import "console"
use Console;
_mmain:$a,$c
{    
	var $arr = [1,2,3,4,5,6];
	Console.Out($arr[1]);
	Console.Out($arr[1..][1]);
	Console.Out($arr[..3][2]);
	Console.Out($arr[2..5][3]);
	$arr = "abcdefghi";
	Console.Out($arr[1]);
}
Dictionary
import "console"
use Console;
_mmain:$a,$c
{    
    var $arr = [1,2,3,4,6,7];
	for(var $i in $arr)
	{
		Console.Out($i);
	}
	$arr ="abcdefghi";
	for(var $i in $arr)
	{
		Console.Out($i);
	}
	$arr =(key1::"value1",key2::"value2");
	for(var $key,$value in $arr)
	{
		Console.Out($key+":"+$value);
	}
}
Funciton
import "console"
use Console;
module test
{
	def func:$i1,$i2=333
	{	
		Console.Out($i1);
		Console.Out($i2);
	}
}
_mmain:$a,$c
{	
	test.func(222,1000,333);
	test.func(555);
}
Develop an external extension library (c / c ++)

example1.dll

#include "Menthol.h"
StackState test()
{
    StackState value =GetParam(1);
	StackState st;
	st.v = M_STRING;
	st = String_CreateString("this is a test string");
	return st;
}

UserFunctionAtter example1list[] = {
	{ "test", test, 0 },
	{NULL,NULL,0}
};

MentholPackMethod void example1_Init()
{
    RunTimeState* prt = CreateModuleRunTime("example1");
	RegisterModuleFunciton(prt, example1list);
}

For more information on menthol, please visit menthol document


Menthol

Menthol是一个简单、易用、易学的脚本语言,语法简单,开发简便,使用C/C++可以快速为它开发扩展

特性

  • 无类型
  • 自动内存管理
  • 面向函数编程
  • 方便的函数封装
  • 简便的方法扩展

教程说明

关键字
if else for break true false
try except throw continue return while
null import _mmain def var in typeof module use
操作符
- * / () ; , | &  ? [] ! % ^ : :: .. = < > != <> || &&  >= <= == += -= /= *= %= &= |= ^= << >> **
基本概念

menthol是一个函数式语言,但它是基于模块操作的语言,在menthol,除了启动函数_mmain,其他用户定义的全局变量、函数都必须基于模块而定义.

导入包

包就是一个用menthol语言或者C/C++写成的模块集合,扩展名为.med,如果要使用包中的模块,需要用import关键字导入

import "console"

console是系统自带的输入输出包,里面包含了控制输入输出的模块,导入时不需要区分文件大小写

使用模块

导入包以后,就可以使用包内的模块了,使用前需要用use关键字来使用,注意,模块名是去区分大小写的,在一个use后面可以引入多个模块名,用逗号隔开

import "console"
use Console;

如果使用的模块在同一包内,并且在使用前已经定义,则不要用use在引入

基本操作

所有的menthol都由系统自动执行_mmain开始,声明变量使用关键字var,全部变量要在变量名前加@,局部变量要在变量名前加$

module test
{
	var @global;// 全局变量
}
_mmain:$a,$c
{    
	var $v = 0; //局部变量
}
错误处理
import "console"
use Console;
module test
{
	def test:
	{	    
	    throw "msg1","msg2";
	}
}

_mmain:$a,$c
{    
	try{
		test.test();
	}
	except:$a,$b
	{
		Console.Out($a);
		Console.Out($b);
	}
}
数组
import "console"
use Console;
_mmain:$a,$c
{    
	var $arr = [1,2,3,4,5,6];
	Console.Out($arr[1]);
	Console.Out($arr[1..][5]);
	Console.Out($arr[..3][6]);
	Console.Out($arr[2..5][7]);
	$arr = "abcdefghi";
	Console.Out($arr[1]);
}
字典
import "console"
use Console;
_mmain:$a,$c
{    
    var $arr = [1,2,3,4,6,7];
	for(var $i in $arr)
	{
		Console.Out($i);
	}
	$arr ="abcdefghi";
	for(var $i in $arr)
	{
		Console.Out($i);
	}
	$arr =(key1::"value1",key2::"value2");
	for(var $key,$value in $arr)
	{
		Console.Out($key+":"+$value);
	}
}
函数
import "console"
use Console;
module test
{
	def func:$i1,$i2=333
	{	
		Console.Out($i1);
		Console.Out($i2);
	}
}
_mmain:$a,$c
{	
	test.func(222,1000,333);
	test.func(555);
}
开发外部扩展库(c/c++)

example1.dll

#include "Menthol.h"
StackState test()
{
    StackState value =GetParam(1);
	StackState st;
	st.v = M_STRING;
	st = String_CreateString("this is a test string");
	return st;
}

UserFunctionAtter example1list[] = {
	{ "test", test, 0 },
	{NULL,NULL,0}
};

MentholPackMethod void example1_Init()
{
    RunTimeState* prt = CreateModuleRunTime("example1");
	RegisterModuleFunciton(prt, example1list);
}

关于更多的menthol的相关文档,请浏览menthol文档

menthol's People

Contributors

ltframe avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.