mirror of
https://gitlab.com/rnger/amath
synced 2025-10-05 18:39:41 +00:00
Compare commits
4 Commits
1.9.0
...
e788fec496
Author | SHA1 | Date | |
---|---|---|---|
e788fec496 | |||
ffa586c694 | |||
0240d3a439 | |||
93c8fdbef4 |
@ -37,6 +37,7 @@ Evaluator::Evaluator(const char* input)
|
||||
{
|
||||
this->input = input;
|
||||
output = new CharBuffer();
|
||||
ResultOnly = false;
|
||||
}
|
||||
|
||||
Evaluator::~Evaluator()
|
||||
@ -52,6 +53,7 @@ void Evaluator::Evaluate() const
|
||||
output->ClearBuffer();
|
||||
|
||||
Parser* parser = new Parser(input);
|
||||
parser->ResultOnly = ResultOnly;
|
||||
SyntaxNode* node = parser->Parse();
|
||||
delete parser;
|
||||
|
||||
|
@ -37,6 +37,12 @@ class Evaluator
|
||||
public:
|
||||
explicit Evaluator(const char *input);
|
||||
~Evaluator();
|
||||
|
||||
/**
|
||||
* @brief Do not include expression string in evaluation result.
|
||||
*/
|
||||
bool ResultOnly;
|
||||
|
||||
void Evaluate() const;
|
||||
char *GetResult() const;
|
||||
|
||||
|
@ -46,6 +46,7 @@ Parser::Parser(const char* input)
|
||||
token = nullptr;
|
||||
errorNode = nullptr;
|
||||
syntaxError = 0;
|
||||
ResultOnly = false;
|
||||
}
|
||||
|
||||
Parser::~Parser()
|
||||
@ -224,7 +225,7 @@ SyntaxNode* Parser::ParseStatement()
|
||||
res = new ListFunctionsStatement();
|
||||
break;
|
||||
case symeval:
|
||||
res = new EvalStatement(ParseExpression());
|
||||
res = new EvalStatement(ParseExpression(), ResultOnly);
|
||||
break;
|
||||
default:
|
||||
PutToken();
|
||||
@ -266,7 +267,7 @@ SyntaxNode* Parser::ParseEvaluation()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
StatementNode* sta = new EvalStatement(exp);
|
||||
StatementNode* sta = new EvalStatement(exp, ResultOnly);
|
||||
if (exp->IsSilent())
|
||||
{
|
||||
sta = new SilentStatement(sta);
|
||||
|
@ -52,6 +52,11 @@ public:
|
||||
explicit Parser(const char* input);
|
||||
~Parser();
|
||||
|
||||
/**
|
||||
* @brief Do not include expression string in evaluation result.
|
||||
*/
|
||||
bool ResultOnly;
|
||||
|
||||
/**
|
||||
* @brief Parses the input into a syntax tree.
|
||||
*
|
||||
|
@ -32,9 +32,10 @@
|
||||
#include "amathc.h"
|
||||
#include "system/program.h"
|
||||
|
||||
EvalStatement::EvalStatement(ExpressionNode* expression) :
|
||||
EvalStatement::EvalStatement(ExpressionNode *expression, bool resultOnly) :
|
||||
StatementNode(), expression(expression)
|
||||
{
|
||||
this->resultOnly = resultOnly;
|
||||
}
|
||||
|
||||
EvalStatement::~EvalStatement()
|
||||
@ -49,12 +50,21 @@ char* EvalStatement::Execute()
|
||||
{
|
||||
Number *result = expression->Evaluate();
|
||||
Number *temp = result->Clone();
|
||||
const char* text = expression->GetText();
|
||||
const char *val = Program->Output->GetText(result);
|
||||
|
||||
Program->SetLastResult(temp);
|
||||
delete temp;
|
||||
|
||||
if (resultOnly)
|
||||
{
|
||||
output->Empty();
|
||||
output->EnsureSize(StrLen(val) + 1);
|
||||
output->Append(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *text = expression->GetText();
|
||||
|
||||
output->Empty();
|
||||
output->EnsureSize(
|
||||
StrLen(text) + 3 +
|
||||
@ -65,6 +75,7 @@ char* EvalStatement::Execute()
|
||||
output->Append(" = ");
|
||||
output->Append(val);
|
||||
output->Append(NEWLINE);
|
||||
}
|
||||
|
||||
return output->GetString();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
class EvalStatement : public virtual StatementNode
|
||||
{
|
||||
public:
|
||||
explicit EvalStatement(ExpressionNode* expression);
|
||||
explicit EvalStatement(ExpressionNode* expression, bool resultOnly);
|
||||
~EvalStatement();
|
||||
|
||||
char* Execute();
|
||||
@ -50,6 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
ExpressionNode* expression;
|
||||
bool resultOnly;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -193,15 +193,17 @@ bool AmigaARexx::HandleMessage(struct RexxMsg *message)
|
||||
|
||||
message->rm_Result1 = 0;
|
||||
|
||||
Evaluator *evaluator = new Evaluator(message->rm_Args[0]);
|
||||
evaluator->ResultOnly = true;
|
||||
evaluator->Evaluate();
|
||||
|
||||
if (message->rm_Action & RXFF_RESULT)
|
||||
{
|
||||
Evaluator *evaluator = new Evaluator(message->rm_Args[0]);
|
||||
evaluator->Evaluate();
|
||||
const char *result = evaluator->GetResult();
|
||||
message->rm_Result2 = (LONG)CreateArgstring((STRPTR)result, (LONG)StrLen(result));
|
||||
delete evaluator;
|
||||
}
|
||||
|
||||
delete evaluator;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,11 @@ void AmigaShellConsole::ReadLine()
|
||||
{
|
||||
Flush(Input());
|
||||
FGets(Input(), line, linesize);
|
||||
|
||||
if (CheckSignal(SIGBREAKF_CTRL_C))
|
||||
{
|
||||
exit = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AmigaShellConsole::WriteString(const char* string)
|
||||
|
@ -104,7 +104,12 @@ char* AmigaLanguage::Translate(identhelpdef *def)
|
||||
|
||||
char AmigaLanguage::GetFractionPoint()
|
||||
{
|
||||
#if defined(STRICT_LOCAL)
|
||||
return locale->loc_DecimalPoint[0];
|
||||
#else
|
||||
// To ensure compatibility, set fraction point to full stop / period
|
||||
return '.';
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AmigaLanguage::CharIsAlNum(long unsigned int character)
|
||||
|
@ -71,7 +71,7 @@ static struct GfxBase *GfxBase = nullptr;
|
||||
static struct LocaleBase *LocaleBase = nullptr;
|
||||
static struct IntuitionBase *IntuitionBase = nullptr;
|
||||
|
||||
#define ARGS_FORMAT "SHELL/S,NOANSI/S,INPUT/F"
|
||||
#define ARGS_FORMAT "SHELL/S,NOANSI/S,AREXX/S,INPUT/F"
|
||||
|
||||
#if defined(AOS3)
|
||||
#define RDPTR LONG *
|
||||
@ -90,6 +90,7 @@ AmigaProgram::AmigaProgram()
|
||||
rdargs = nullptr;
|
||||
args.shell = FALSE;
|
||||
args.noansi = FALSE;
|
||||
args.arexx = FALSE;
|
||||
args.input = nullptr;
|
||||
Console = nullptr;
|
||||
}
|
||||
@ -179,7 +180,14 @@ void AmigaProgram::Start()
|
||||
AmigaARexx *arexx = new AmigaARexx();
|
||||
arexx->Start();
|
||||
|
||||
if (args.arexx)
|
||||
{
|
||||
Wait(SIGBREAKF_CTRL_C);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console->Start();
|
||||
}
|
||||
|
||||
arexx->Stop();
|
||||
delete arexx;
|
||||
|
@ -37,6 +37,7 @@ struct amathargs
|
||||
{
|
||||
long shell;
|
||||
long noansi;
|
||||
long arexx;
|
||||
char* input;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user