Ejemplo n.º 1
0
/************************ convertSubTaskOperator *******************************
void convertSubTaskOperator(Stack stack, Out out, Element *pElement)
Purpose:
    This function handles the case of an operator token.
    The operators in the stack with a higher or equal precedence get outted 
    and the new operator gets pushed to the stack.		
Parameters:
    I/O Stack stack	    The current stack.
    O Out out		    The out structure used in the conversion.
    I Element *pElement	    The operator element.
Returns:
    stack parm - the updated stack.
    out parm - the updated out structure.
Notes:
    This is a sub task of the query conversion from infix format to 
    postfix format.
*******************************************************************************/
void convertSubTaskOperator(Stack stack, Out out, Element *pElement)
{
    while(isEmpty(stack) == FALSE && pElement->iPrecedence <= topElement(stack).iPrecedence)
    //loop until the stack is empty or there's no more operator in the stack with a lower
    //precedence than the top of the stack 
    {
        addOut(out, pop(stack)); //POP and OUT the higher precedence operator from the stack
    }
    push(stack, *pElement);
}
Ejemplo n.º 2
0
types::Function::ReturnValue sci_macrovar(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "macrovar" , 1);
        return types::Function::Error;
    }

    if (_iRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "macrovar" , 1);
        return types::Function::Error;
    }

    types::Macro* pM = NULL;
    switch (in[0]->getType())
    {
        case types::InternalType::ScilabMacro:
        {
            pM = in[0]->getAs<types::Macro>();
            break;
        }
        case types::InternalType::ScilabMacroFile:
        {
            types::MacroFile* pMF = in[0]->getAs<types::MacroFile>();
            pM = pMF->getMacro();
            break;
        }
        default :
            Scierror(999, _("%s: Wrong type for input arguments: macro expected.\n"), "macrovar");
            return types::Function::Error;
    }


    ast::MacrovarVisitor visit;

    addIn(visit, pM->getInputs());
    addOut(visit, pM->getOutputs());

    pM->getBody()->accept(visit);

    types::List* pL = new types::List();

    pL->append(createString(visit.getIn()));
    pL->append(createString(visit.getOut()));
    pL->append(createString(visit.getExternal()));
    pL->append(createString(visit.getCalled()));
    pL->append(createString(visit.getLocal()));

    out.push_back(pL);
    return types::Function::OK;
}
Ejemplo n.º 3
0
/*********************** convertSubTaskRemainingStack **************************
int convertSubTaskRemainingStack(Stack stack, Out out)
Purpose:
    This function handles the rest of the stack once we've gone through 
    all of the tokens in the input. It also handles the case of a leftover
    unmatched parenthesis in the stack.
Parameters:
    I/O Stack stack	The current stack.
    O Out out	        The out structure used in the conversion.
Returns:
    stack parm - the freed stack.
    out parm - the final out structure.
Notes:
    This is a sub task of the query conversion from infix format to 
    postfix format.
*******************************************************************************/
int convertSubTaskRemainingStack(Stack stack, Out out)
{
    while (isEmpty(stack) == FALSE)	//goes through the remaining stack until empty
    {
        if (topElement(stack).iCategory == CAT_LPAREN)//if an unmatched ( is found
  	{
  	    freeStack(stack); //at this point we are done using the stack
  	    return WARN_MISSING_RPAREN; //return error
  	}	
  	addOut(out, pop(stack)); //POP and OUT the stack
    }
    freeStack(stack); //at this point we are done using the stack		
}
Ejemplo n.º 4
0
/************************** convertSubTaskRParen *******************************
int convertSubTaskRParen(Stack stack, Out out)
Purpose:
    This function handles the case of a right parenthesis token.
    The elements in the stack get outted until we find the matching 
    right parenthesis if there is one.
Parameters:
    I/O Stack stack	The current stack.
    O Out out		The out structure used in the conversion.
Returns:
    stack parm - the updated stack.
    out parm - the updated out structure.
Notes:
    This is a sub task of the query conversion from infix format to 
    postfix format.
*******************************************************************************/
int convertSubTaskRParen(Stack stack, Out out)
{
    while (isEmpty(stack) == FALSE && topElement(stack).iCategory != CAT_LPAREN)
    {
        addOut(out, pop(stack)); //POP and OUT content of the stack until left parenthesis is found
    }
    if (isEmpty(stack) == TRUE) //if we didn't find a (
    {
        freeStack(stack); //at this point we are done using the stack
  	return WARN_MISSING_LPAREN; //return error
    }
    pop(stack); //POP and get rid of (
}
Ejemplo n.º 5
0
/************************** convertSubTaskOperand *******************************
void convertSubTaskOperand(Out out, Element *pElement)
Purpose:
    This function handles the case of an operand token.
    The operand element simply gets added to the out.
Parameters:
    O Out out		    The out structure used in the conversion.
    I Element *pElement	    The operand element.
Returns:
    out parm - the updated out structure.
Notes:
    This is a sub task of the query conversion from infix format to 
    postfix format.
*******************************************************************************/
void convertSubTaskOperand(Out out, Element *pElement)
{
    addOut(out, *pElement);
}