计算器问题 [英] calculator issue

查看:72
本文介绍了计算器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设计一个特殊的计算器.. 我遇到了这样的问题: X = 1 +(12 * 4 + 2) 我需要先获取操作数 像这里,我有两个操作数1和(12 * 4 + 2) 我如何区分外+和内+?

I want to design a special calculator .. and I came to a problem like this : X=1+(12*4+2) i need to get number of operands first like here i have two operands 1 and (12*4+2) how could i distinguish between the outer + and the inner one ?

谢谢

这里真是一个了不起的社区.. 从最简单到最困难的答案.. 伙计们,我的问题不是计算器,也不是其他与数学有关的.. 我只是问外在和内在加法,将策略应用在完全不同的事情上.

what an amazing community here .. different answers from easiest to hardest .. guyz my problem is not calculator nor anything else related to math .. I just asked about the outer and inner plus to apply the strategy in a completely different thing .

我正在用Java实现统一算法(就像当您给Prolog解释器两个表达式时所做的一样)

I am implementing unification algorithm in java (just like what Prolog interpreter does when you give it two expressions )

这是算法:

function unify(E1, E2);
    begin
        case
            both E1 and E2 are constants or the empty list:
                if E1 = E2 then return {}
                else return FAIL;
            E1 is a variable:
                if E1 occurs in E2 then return FAIL
                 else return {E2/E1}
            E2 is a variable
                if E2 occurs in E1 then FAIL
                    else return {E1/E2}
            either E1 or E2 are empty then return FAIL
            otherwise:
                begin
                    HE1 := first element of E1;
                    HE2 := first element of E2;
                    SUBS1 := unify(HE1, HE2);
                    if SUBS1 := FAIL then return FAIL;
                    TE1 := apply(SUBS1, rest of E1);
                    TE2 := apply(SUBS1, rest of E2);
                    SUBS2 := unify(TE1, TE2);
                    if SUBS2 = FAIL then return FAIL;
                         else return composition(SUBS1, SUBS2)
                end
            end

现在我的问题是我是否有这样的输入: a(X,Y)= a(b(c,Y),Z)..

now my question is if I have such input : a(X,Y)=a(b(c,Y),Z)..

如何提取元素的数量(和值)(即第一个Expression的X和Y)

how could I extract number (and values)of the elements (i.e. X and Y for the first Expression )

当我阅读并尝试解决此问题时,我想到了不同的新技术. 像Lexical Analysis,Parsing一样,我对Lexical Alanysis毫无头绪,尽管我知道解析和令牌(以String的方式),而且我认为这无法解决我的问题.. 我现在正在尝试实现乔伊·亚当斯说的话..我认为这对我的问题很有用..

I have come to different new techniques for me when i read and try to solve this .. like Lexical Analysis,Parsing I have no clue about Lexical Alanysis though I know parsing and tokens (in String manner) moreover i think it's not gonna solve my problem .. I am now trying to implement what Joey Adams said .. I think it's useful to my problem..

这篇散文小伙子的故事...感谢您的帮助

soory for this essay guyz ... appreciate you help

推荐答案

您的问题非常笼统,完整的答案可能需要占用一本书的几章.

Your question is very general, and a complete answer could take up several chapters in a book.

话虽如此,我建议您从谷歌搜索开始,先学习一些术语并了解以下内容:

That being said, I would suggest you start by Googling for some terms and learning about:

标记化解析(从字符串中提取单个组件.)

Tokenizing and Parsing (extracting the individual components from the string.)

中缀评估(采用一对操作数和一个中间运算符并存储答案)

Infix Evaluation (taking a pair of operands and an intervening operator and storing an answer)

后缀评估(采用一对操作数和后继运算符-尚无道理,但可能需要阅读一会儿.)

Postfix Evaluation (taking a pair of operands and a following operator -- this won't make sense yet, but probably will after you've read a bit.)

..并进一步阅读:

编译器设计

...,当您遇到特定问题时,请继续访问此网站.不要忘记搜索与已经提出的问题类似的答案!

... and as you encounter specific questions, continue to visit this site. Don't forget to search for answers to questions similar to yours that have already been asked!

这篇关于计算器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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