有严格限制跨preTED语言工作 [英] Working with a severely limited interpreted language

查看:115
本文介绍了有严格限制跨preTED语言工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码称为JS的嵌入式语言。

I'm coding in an embedded language called JS.

我希望能够调用三种功能于任何顺序。 (ABC,ACB,BAC,BCA,CBA,CAB)。

I want to be able to call three functions in any order. (ABC, ACB, BAC, BCA, CBA, CAB.)

诀窍?语言不具有用户定义的函数。

The trick? The language doesn't have user-defined functions.

它有一个条件和循环结构。

It does have a conditional and a looping construct.

我觉得我有三种选择。

I think I have three choices.


  1. 复制一大堆code的。

  2. 写preprocessor(这将创建所有重复的code)。

  3. 请循环有三个迭代,使用数组来控制哪些功能被调用的循环的每个传球。

我恨#1。复制code是讨厌。我怎么没有搞砸了改变什么?

I hate #1. Duplicated code is nasty. How do I change anything without screwing up?

我猜#2确定。至少我没有在源重复code。但我的输出code是什么,我会调试,我不知道如果我想从它发散。从有利的一面,我一堆糖添加到语言。

I guess #2 is OK. At least I don't have duplicated code in the source. But my output code is what I'll be debugging, and I wonder if I want to diverge from it. On the plus side, I could add a bunch of sugar to the language.

我想我最好的选择是#3。

I think my best bet is #3.

任何其他的想法?有没有goto。没有的功能。没有现成的preprocessor。

Any other ideas? There is no goto. No functions. No existing preprocessor.

有趣的事情大约第3的是,它本质上是臭名昭著/交换机的噩梦。

Funny thing about #3 is that it's essentially the infamous for/switch nightmare.

推荐答案

也许某种突变状态机的,即:

Perhaps some kind of mutant state-machine, viz:

int CODEWORD=0x123;

while (CODEWORD)
{
    switch(CODEWORD&15)
    {
    case 1:
       /// case 1
       break;
    case 2:
       /// case 2
       break;
    case 3:
       //// case 3
       break;
    }
    CODEWORD=CODEWORD>>4;
}

干燥,无preprocessor,没有数组。为/开关似乎有些不可避免的。

DRY, no preprocessor, no array. for/switch seems somewhat unavoidable.

这篇关于有严格限制跨preTED语言工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆