← 都来码 / Dolaima← 例程索引forth/test/parserexp_demo.fs 原文

forth/test/parserexp_demo.fs · 635 字节 · 下载原文

\ parserexp_demo.fs — 调用共享库 parserexp 解析表达式
\ parserexp_demo.fs — call the shared library parserexp to parse expressions
\ ⚠ `S" …"` 压的是 **(地址, 长度) 两个单元**(标准 Forth 如此),而共享库 `parserexp(char*)`
\   只要一个指针 ⇒ 长度必须 `DROP` 掉,否则形参拿到的是**长度**(实测打 0/0/0)。
\ `S" …"` pushes **(address, length)**; `parserexp(char*)` takes one pointer, so the length
\ must be dropped (measured before: 0/0/0).
: DEMO
    S" 2+3*4" DROP parserexp . CR
    S" (10-3)*2" DROP parserexp . CR
    S" 100/4+5" DROP parserexp . CR ;
DEMO