简体   繁体   English

CPP 中类似控制台的应用程序

[英]Console like application in CPP



I have been assigned with a coding homework in CPP where I'm supposed to create a Matrix calculator.我在 CPP 中分配了一个编码作业,我应该在其中创建一个矩阵计算器。 This would be an ok-ish task considering all I need to do is matrix calculations, use polymorphism, consider memory consumption, and some more criteria.考虑到我需要做的只是矩阵计算、使用多态性、考虑 memory 消耗以及更多标准,这将是一个不错的任务。 What I'm struggling with is that is should be a console like environment.我正在努力解决的是应该是一个类似控制台的环境。

Meaning start the app and I'm in a prompt where I type commands like:意思是启动应用程序,我在提示符下键入以下命令:

scan x[3][3] \n // this creates new matrix labeled 'x' and waits for 9 ints ( longs possibly ) to by typed.扫描 x[3][3] \n // 这将创建标记为“x”的新矩阵,并等待输入 9 个整数(可能是长整数)。

z = add xy \n // or z = 添加 xy \n // 或
z = x + y \n z = x + y \n

I am familiar with automata theory ( to some degree ) and making it this simple shouldn't be a problem.我熟悉自动机理论(在某种程度上),让它变得如此简单应该不是问题。 ( that practically has nothing to do with automata ) Simple meaning one command per line - because that's what I'm doing now. (这实际上与自动机无关)简单意味着每行一个命令 - 因为这就是我现在正在做的事情。 I have some parser class that breaks down the command, and than I do the necessary changes.我有一些解析器 class 可以分解命令,然后进行必要的更改。 Its more of a if-else tree going from first word to the last.它更像是从第一个单词到最后一个单词的 if-else 树。 If I encounter unrecognized word - Grammar/Syntax error.如果我遇到无法识别的单词 - 语法/语法错误。

What I'm asking is some tips on how to make it more.. bash like, for instance.我要问的是一些关于如何使它更多的提示。例如,bash 之类的。
Since the app is run in bash..由于该应用程序在 bash 中运行。
FIRST Q: how do i achieve a history of typed commands?第一个问:我如何获得键入命令的历史记录? rn when i push arrowup i get those ^[[A. rn 当我按下箭头时,我得到了那些 ^[[A.
SECOND Q: Some hints how start parsing some more complicated commands like: a = b = c * ( d + q ) ( implying that 'c' can multiply "(d + q)" and 'd' is addable to 'q' etc.. ) bcs that cant be done with the static way my parser works rn.第二个问题:一些提示如何开始解析一些更复杂的命令,例如: a = b = c * ( d + q ) (暗示 'c' 可以乘以 "(d + q)" 并且 'd' 可以添加到 'q'等等..)不能用 static 方式完成的 bcs 我的解析器工作 rn。

Thank you all.谢谢你们。

For your first question, look at libreadline or libeditline .对于您的第一个问题,请查看libreadlinelibeditline If you do not want to lift a finger, run your program under the rlwrap wrapper.如果您不想动手指,请在rlwrap包装器下运行您的程序。

For your second question, look at Simple library or implementation for a mathematical expression evaluator .对于第二个问题,请查看Simple library or implementation for a math expression evaluator Look for one that allows you to define and use variables.寻找一种允许您定义和使用变量的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM