随笔-341  评论-2670  文章-0  trackbacks-0
    自从做好了Vczh Free Script之后,对于λ-calculus的热情还在,对于未实现lazy evaluation也耿耿于怀。因此又设计了一门类似Haskell的语言来(在语法上模仿了不少),本意是既能享受到lazy evaluation所带来的优美的表现形式,又能将这门语言当脚本而不是单纯的程序语言使用。不过将来会演变成什么就暂时不管了。现在贴出该语言的语法的形式描述,做备忘录之用,或有恳请同行斧正之意。

LAZY_PROGRAM is

    MODULE_DECLARATION

 

--------------------------------------

 

MODULE_DECLARATION is

    module MODULE_NAME exports {FUNCTION_NAME}+ where {DECLARATION}+ end;

 

DECLARATION is

    MODULE_DECLARATION

    IMPORT_DECLARATION

    TYPE_DECLARATION

    CLASS_DECLARATION

    INSTANE_DECLARATION

    FUNCTION_HEAD_DECLARATION

    FUNCTION_BODY_DECLARATION

 

--------------------------------------

 

IMPORT_DECLARATION is

    import MODULE_NAME{.MODULE_NAME};

 

--------------------------------------

 

TYPE_DECLARATION is

    type TYPE_NAME {TYPE_NAME}[= TYPE_DESCRIPTION];

 

SIMPLE_TYPE_DESCRIPTION is

    "(" TYPE_DESCRIPTION ")"

    TYPE_NAME

 

TYPE_DESCRIPTION is

    "(" TYPE_DESCRPTION ")"

    TYPE_NAME {SIMPLE_DESCRIPTION}

    TYPE_CONSTRUCTOR {SIMPLE_TYPE_DESCRIPTION}+

    TYPE_DESCRIPTION -> TYPE_DESCRIPTION

    TYPE_DESCRIPTION "|" TYPE_DESCRIPTION

 

--------------------------------------

 

CLASS_DECLARATION is

    class CLASS_NAME TYPE_NAME [inherits {CLASS_NAME}+] where {FUNCTION_HEAD_DECLARATION|FUNCTION_BODY_DECLARATION}+ end;

 

--------------------------------------

 

INSTANCE_DECLARATION is

    instance CLASS_NAME TYPE_NAME [where {FUNCTION_BODY_DECLARATION}+ end];

 

--------------------------------------

 

FUNCTION_HEAD_DECLARATION is

    FUNCTION_NAME :: {PREREQUISITE,}TYPE_DESCRIPTION;

 

PREREQUISITE is

    [CLASS_NAME] TYPE_NAME

 

FUNCTION_BODY_DECLARATION is

    FUNCTION_NAME {LEFT_VALUE} = (EXPRESSION | linking <string>);

 

--------------------------------------

 

LEFT_VALUE is

    VALUE_NAME

    LEFT_VALUE:VALUE_NAME

    "(" LEFT_VALUE{,LEFT_VALUE} ")"

    "[" [LEFT_VALUE{,LEFT_VALUE}] "]"

    TYPE_CONSTRUCTOR {LEFT_VALUE}+

    "(" LEFT_VALUE ")"

 

EXPRESSION is

    VALUE

    VALUE_NAME

    EXPRESSION:EXPRESSION

    "(" EXPRESSION{,EXPRESSION} ")"

    "[" [EXPRESSION{,EXPRESSION}] "]"

    TYPE_CONSTRUCTOR {EXPRESSION}+

    EXPRESSION EXPRESSION

    "(" OPERATOR_NAME EXPRESSION ")"

    "(" EXPRESSION OPERATOR_NAME ")"

    FUNCTION_NAME

    EXPRESSION OPERATOR EXPRESSION

    "[" EXPRESSION "|" [[LEFT_VALUE <- ]EXPRESSION{,[LEFT_VALUE <- ]EXPRESSION}] "]"

    case EXPRESSION of {LEFT_VALUE:EXPRESSION}+ end

    do {([LEFT_VALUE = ]EXPRESSION | LEFT_VALUE::TYPE_DESCRIPTION);}+ end

    EXPRESSION [where {FUNCTION_HEAD_DECLARATION | FUNCTION_BODY_DECLARATION}+ end]

    \{LEFT_VALUE}+ -> "(" EXPRESSION ")"

 

--------------------------------------

 

MODULE_NAME is

    <identifier>

 

FUNCTION_NAME is

    <identifier>

    "(" OPERATOR ")"

 

TYPE_NAME is

    <identifier>

 

TYPE_CONSTRUCTOR is

    <identifier>

 

CLASS_NAME is

    <identifier>

 

VALUE_NAME is

    <identifier>

 

VALUE is

    <identifier>

    <constant>

 

OPERATOR_NAME is

    "(" OPERATOR ")"

    $ <identifier> $

 

OPERATOR is

    +

    -

    *

    /

    \

    %

    &&

    ||

    ^

    !

    <

    >

    <=

    >=

    ==

    !=

    >>=

    >>

    !!

posted on 2008-04-20 20:49 陈梓瀚(vczh) 阅读(2815) 评论(3)  编辑 收藏 引用 所属分类: Vczh Lazy Script

评论:
# re: Vczh Lazy Script 语法描述 2008-04-20 20:54 | 空明流转
首个板凳。  回复  更多评论
  
# re: Vczh Lazy Script 语法描述 2008-04-22 06:52 | zar
留个名,学习一下  回复  更多评论
  
# re: Vczh Lazy Script 语法描述 2008-07-10 23:11 | pointer
你的编译器做了代码生成优化么?感觉这块挺复杂。包括寄存器选择算法等。  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理