some work on a 'program mode'
git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@1136 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
c825c85878
commit
a6b767a223
|
@ -58,6 +58,7 @@ public:
|
||||||
virtual bool Parse(const std::wstring & str) = 0;
|
virtual bool Parse(const std::wstring & str) = 0;
|
||||||
virtual bool LastResultToBool() = 0;
|
virtual bool LastResultToBool() = 0;
|
||||||
virtual std::wstring LastResult() = 0;
|
virtual std::wstring LastResult() = 0;
|
||||||
|
virtual int LastError() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1448,13 +1448,13 @@ void Generator<StreamType>::EvaluateProgramNode(Item & item)
|
||||||
if( output_stream )
|
if( output_stream )
|
||||||
{
|
{
|
||||||
if( item.type == Item::item_function )
|
if( item.type == Item::item_function )
|
||||||
*output_stream << " expression: " << item.text << "\n";
|
*output_stream << " expression: " << item.text;
|
||||||
|
|
||||||
if( item.type == Item::item_if )
|
if( item.type == Item::item_if )
|
||||||
*output_stream << " if: " << item.text << "\n";
|
*output_stream << " if: " << item.text;
|
||||||
|
|
||||||
if( item.type == Item::item_for )
|
if( item.type == Item::item_for )
|
||||||
*output_stream << " for: " << item.text << "\n";
|
*output_stream << " for: " << item.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_res = false;
|
last_res = false;
|
||||||
|
@ -1464,16 +1464,25 @@ void Generator<StreamType>::EvaluateProgramNode(Item & item)
|
||||||
if( expression_parser->Parse(item.text) )
|
if( expression_parser->Parse(item.text) )
|
||||||
{
|
{
|
||||||
last_res = expression_parser->LastResultToBool();
|
last_res = expression_parser->LastResultToBool();
|
||||||
|
|
||||||
|
if( output_stream )
|
||||||
|
{
|
||||||
|
*output_stream << " -> " << expression_parser->LastResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( output_stream )
|
if( output_stream )
|
||||||
{
|
{
|
||||||
*output_stream << " syntax error when evaluating expression\n";
|
*output_stream << " -> syntax error when evaluating expression: error code: " << (int)expression_parser->LastError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( output_stream )
|
||||||
|
{
|
||||||
|
*output_stream << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -886,9 +886,9 @@ int c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PatternParser::CreateTreeReadDirectiveExpression(Item & item, wchar_t starting_terminator, wchar_t ending_terminator)
|
void PatternParser::CreateTreeReadDirectiveExpression(Item & item, bool is_statement)
|
||||||
{
|
{
|
||||||
long terminator_counter = 1;
|
int brackets_counter = is_statement ? 1 : 0;
|
||||||
|
|
||||||
while( *itext )
|
while( *itext )
|
||||||
{
|
{
|
||||||
|
@ -897,19 +897,25 @@ void PatternParser::CreateTreeReadDirectiveExpression(Item & item, wchar_t start
|
||||||
if( c == 10 || c == 13 )
|
if( c == 10 || c == 13 )
|
||||||
c = ' ';
|
c = ' ';
|
||||||
|
|
||||||
if( c == starting_terminator )
|
if( c == ';' && brackets_counter == 0 )
|
||||||
{
|
|
||||||
terminator_counter += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( c == ending_terminator )
|
|
||||||
{
|
|
||||||
terminator_counter -= 1;
|
|
||||||
|
|
||||||
if( terminator_counter == 0 )
|
|
||||||
{
|
{
|
||||||
itext += 1;
|
itext += 1;
|
||||||
return; // end of expression;
|
return; // end of normal expression (not in a statement such as 'for' or 'if')
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c == '(' )
|
||||||
|
{
|
||||||
|
brackets_counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c == ')' )
|
||||||
|
{
|
||||||
|
brackets_counter -= 1;
|
||||||
|
|
||||||
|
if( is_statement && brackets_counter == 0 )
|
||||||
|
{
|
||||||
|
itext += 1;
|
||||||
|
return; // end of statement expression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,6 +929,8 @@ void PatternParser::CreateTreeReadDirectiveExpression(Item & item, wchar_t start
|
||||||
|
|
||||||
bool PatternParser::CreateTreeCheckProgramDirective(Item & item)
|
bool PatternParser::CreateTreeCheckProgramDirective(Item & item)
|
||||||
{
|
{
|
||||||
|
const wchar_t * old_itext = itext;
|
||||||
|
|
||||||
if( PT::IsSubStringNoCasep(L"if", itext) )
|
if( PT::IsSubStringNoCasep(L"if", itext) )
|
||||||
{
|
{
|
||||||
itext += 2;
|
itext += 2;
|
||||||
|
@ -934,11 +942,6 @@ bool PatternParser::CreateTreeCheckProgramDirective(Item & item)
|
||||||
item.type = Item::item_if;
|
item.type = Item::item_if;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
item.type = Item::item_err;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( PT::IsSubStringNoCasep(L"while", itext) )
|
if( PT::IsSubStringNoCasep(L"while", itext) )
|
||||||
|
@ -952,13 +955,9 @@ bool PatternParser::CreateTreeCheckProgramDirective(Item & item)
|
||||||
item.type = Item::item_for;
|
item.type = Item::item_for;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
item.type = Item::item_err;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itext = old_itext;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,15 +985,12 @@ bool PatternParser::CreateTreeReadExpression(Item & item)
|
||||||
|
|
||||||
if( CreateTreeCheckProgramDirective(item) )
|
if( CreateTreeCheckProgramDirective(item) )
|
||||||
{
|
{
|
||||||
CreateTreeReadDirectiveExpression(item, '(', ')');
|
CreateTreeReadDirectiveExpression(item, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( item.type == Item::item_err )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
item.type = Item::item_function;
|
item.type = Item::item_function;
|
||||||
CreateTreeReadDirectiveExpression(item, 0, ';');
|
CreateTreeReadDirectiveExpression(item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -177,7 +177,7 @@ private:
|
||||||
void ReadDirectiveReturn(Item & item);
|
void ReadDirectiveReturn(Item & item);
|
||||||
void ReadNormalStatement(Item & item);
|
void ReadNormalStatement(Item & item);
|
||||||
|
|
||||||
void CreateTreeReadDirectiveExpression(Item & item, wchar_t starting_terminator, wchar_t ending_terminator);
|
void CreateTreeReadDirectiveExpression(Item & item, bool is_statement);
|
||||||
bool CreateTreeCheckProgramDirective(Item & item);
|
bool CreateTreeCheckProgramDirective(Item & item);
|
||||||
bool CreateTreeReadExpression(Item & item);
|
bool CreateTreeReadExpression(Item & item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue