为我正在考虑设计的语言开发语法

发布于 2024-10-01 01:41:24 字数 1432 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2024-10-08 01:41:24

假设您已经研究了其他预先存在的语言并发现它们想要...好吧,我很抱歉,但是您想要设计自己的语言,从而陷入了一个非常复杂的主题。定义良好(且受支持)的语言,例如 LogoBBC BASIC (我个人最喜欢的)和(我 3 岁的孩子喜欢这个)Scratch 都很容易上手。

假设您要继续执行此操作,请查看域特定语言并还可以考虑购买同名书籍< /a>(无附属链接)由著名的 Martin Fowler 等人撰写。

编辑以包含语法示例:

BBC Basic RSS feed 阅读器

INSTALL @lib$+"XMLLIB"

      url$ = "http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/2688.xml"
      XMLfile$ = @tmp$+"temp.xml"
      PROCurldownload(url$, XMLfile$)

      PROC_initXML(xml{}, XMLfile$)
      rss% = FN_skipTo(xml{}, "rss", 0)
      IF rss% THEN
        channel% = FN_skipTo(xml{}, "channel", rss%)
        IF channel% THEN
          IF FN_skipTo(xml{}, "title", channel%) THEN
            PRINT FN_repEnt(FN_nextToken(xml{}))
          ENDIF
          WHILE FN_skipTo(xml{}, "item", channel%)
            item% = FN_getLevel(xml{})
            IF FN_skipTo(xml{}, "title", item%) THEN
              PRINT 'FN_repEnt(FN_nextToken(xml{}))
            ENDIF
          ENDWHILE
        ENDIF
      ENDIF
      PROC_exitXML(xml{})
      END

徽标:

FD 20    ; drawing a line and moving
PENUP    ; lifting the pen so it will not draw anything
FD 20    ; moving but not drawing
PENDOWN  ; lowering the pen so it draws again
FD 20    ; drawing a line and moving
PENUP    ; lifting the pen so it will not draw anything
FD 40    ; moving but not drawing
PENDOWN  ; lowering the pen so it draws again
RT 20    ; rotating right (clockwise) 20 degrees

Scratch:

您确实需要查看可视化编辑器

“替代文本”

Assuming that you've looked into other pre-existing languages and found them wanting... OK, I'm sorry, but you're leaping into a seriously complicated subject by wanting to design your own language. Well defined (and supported) languages such as Logo, BBC BASIC (a personal favourite of mine) and (my 3 year old loves this) Scratch are all very simple to pick up.

Assuming you're going forward with this, then take a look at Domain Specific Languages and also consider purchasing the book of the same title (no affiliate link) by the renowned Martin Fowler et al.

Edited to include syntax examples:

BBC Basic RSS feed reader

INSTALL @lib$+"XMLLIB"

      url$ = "http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/2688.xml"
      XMLfile$ = @tmp$+"temp.xml"
      PROCurldownload(url$, XMLfile$)

      PROC_initXML(xml{}, XMLfile$)
      rss% = FN_skipTo(xml{}, "rss", 0)
      IF rss% THEN
        channel% = FN_skipTo(xml{}, "channel", rss%)
        IF channel% THEN
          IF FN_skipTo(xml{}, "title", channel%) THEN
            PRINT FN_repEnt(FN_nextToken(xml{}))
          ENDIF
          WHILE FN_skipTo(xml{}, "item", channel%)
            item% = FN_getLevel(xml{})
            IF FN_skipTo(xml{}, "title", item%) THEN
              PRINT 'FN_repEnt(FN_nextToken(xml{}))
            ENDIF
          ENDWHILE
        ENDIF
      ENDIF
      PROC_exitXML(xml{})
      END

Logo:

FD 20    ; drawing a line and moving
PENUP    ; lifting the pen so it will not draw anything
FD 20    ; moving but not drawing
PENDOWN  ; lowering the pen so it draws again
FD 20    ; drawing a line and moving
PENUP    ; lifting the pen so it will not draw anything
FD 40    ; moving but not drawing
PENDOWN  ; lowering the pen so it draws again
RT 20    ; rotating right (clockwise) 20 degrees

Scratch:

You need to see the visual editor really

alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文