0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

最新版ParserScript 3.0でさらに簡潔に式のマッチングを行う

Last updated at Posted at 2024-11-02

現在、ParserScriptは非推奨です。

前回

にて、式のマッチングをParserScript 2.0で行ったのですがバージョン3.0を公開したので、そのバージョンでもう一度マッチングを行いたいと思います。

ParserScript 3.0の新コマンド

 ParserScript 3.0では新しいコマンドが大きく分けて3つ追加されました。
 詳しくはこちらを見てください。

式のマッチング

 では早速そのコードを書きます。

ESCAPE ' '
CALL EXPRESSION
AST FACTOR
    VRECORD ""
    CSREGEX MATCH "((-)?[0-9]+(\.[0-9]+))"
    NOMATCH?
        BREAK
        VRECORD ""
        MATCH "("
        CALL EXPRESSION
        MATCH ")"
    END
    DOWNPUSH
LAST
AST TERM
    CALL FACTOR
    VRECORD ""
    SET
    CSREGEX MATCH "(\*|/)"
    CALL FACTOR
    MATCH?
        JUMP
    END
    DOWNPUSH
LAST
AST EXPRESSION
    CALL TERM
    VRECORD ""
    SET
    CSREGEX MATCH "(\+|-)"
    CALL TERM
    MATCH?
        JUMP
    END
    DOWNPUSH
LAST

まあ、こんな感じです。バージョン2.0よりも129文字短いです。

終わりに

 さらに使いやすくなったParserScript 3.0でもまだまだ改良の余地があります。もっと文法が厳しく安全な3.1が完成するのをお楽しみに。 後継言語の開発決定により開発終了。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?