Exemplo n.º 1
0
void Parser::Statement(string functionName) {

    _message.print(DBUG, "PARSER: In Statement()\n");

    //    ExpressionStatement
    //    | CompoundStatement
    //    | SelectionStatement
    //    | RepetitionStatement
    //    | ReturnStatement

    static tokenType statementFirstSet[] = {SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, SYM_SEMICOLON, (tokenType) - 1};

    static tokenType followSet[] = {TOK_EOF, KW_ELSE, SYM_CURLY_CLOSE, KW_VOID, KW_INT, KW_FLOAT, SYM_PLUS, SYM_MINUS, SYM_NOT, SYM_CURLY_OPEN, KW_IF, KW_WHILE, KW_RETURN, SYM_OPEN, LIT_INT, LIT_FLOAT, LIT_STR, TOK_IDENT, (tokenType) - 1};

    if ( synchronized(statementFirstSet, followSet, "Expected Statement") ) {
        if ( _lookAhead.getTokenType() == SYM_CURLY_OPEN ) {
            _symbolTable->openScope();
            CompoundStatement(functionName);
//            _symbolTable->dump();
            _symbolTable->closeScope();
        } else if ( _lookAhead.getTokenType() == KW_IF ) {
            SelectionStatement(functionName);
        } else if ( _lookAhead.getTokenType() == KW_WHILE ) {
            RepetitionStatement(functionName);
        } else if ( _lookAhead.getTokenType() == KW_RETURN ) {
            ReturnStatement(functionName);
        } else {
            ExpressionStatement();
        }
    }
    _message.print(DBUG, "PARSER: End of Statement()\n");
}
Exemplo n.º 2
0
void Statement()
{
   switch (Symb.type) {
   case IDENT: {
      Gener(TA, varAddr(Symb.ident));
      Symb = readLexem();
      Compare(ASSIGN, __LINE__);
      Expression();
      Gener(ST);
      break;
   }
   case kwWRITE:
      Symb = readLexem();
      Expression();
      Gener(WRT);
      break;
   case kwREAD:
      Symb = readLexem();
      char id[MAX_IDENT_LEN];
      Compare_IDENT(id, __LINE__);
      Gener(TA, varAddr(id));
      Gener(RD);
      Gener(ST);
      break;
   case kwIF: {
      Symb = readLexem();
      Condition();
      int adrIFJ = Gener(IFJ);
      Compare(kwTHEN, __LINE__);
      Statement();
      ElsePart(adrIFJ);
      break;
   }
   case kwWHILE: {
      int a1 = GetIC();
      Symb = readLexem();
      Condition();
      int aIFJ = Gener(IFJ);
      Compare(kwDO, __LINE__);
      Statement();
      Gener(JU, a1);
      PutIC(aIFJ);
      break;
   }
   case kwBEGIN:
      CompoundStatement();
      break;
   default:
      break;
   }
}
Exemplo n.º 3
0
Statm *Statement()
{
   switch (Symb.type) {
   case IDENT: {
      Var *var = new Var(varAddr(Symb.ident),false);
      Symb = readLexem();
      Compare(ASSIGN, __LINE__);
      return new Assign(var, Expression());
   }
   case kwWRITE:
      Symb = readLexem();
      return new Write(Expression());
   case kwREAD:
      Symb = readLexem();
      char id[MAX_IDENT_LEN];
      Compare_IDENT(id, __LINE__);
      return new Read(new Var(varAddr(id), false));
   case kwIF: {
      Symb = readLexem();
      Expr *cond = Condition();
      Compare(kwTHEN, __LINE__);
      Statm *prikaz = Statement();
      return new If(cond, prikaz, ElsePart());
   }
   case kwWHILE: {
      Expr *cond;
      Symb = readLexem();
      cond = Condition();
      Compare(kwDO, __LINE__);
      return new While(cond, Statement());
   }
   case kwBEGIN:
      return CompoundStatement();
   default:
      return new Empty;
   }
}
Exemplo n.º 4
0
void Parser::TranslationUnit() {

    _message.print(DBUG, "PARSER: In TranslationUnit()\n");

    // fill with tokens, -1 must be the last one!
    static tokenType translationUnitFirstSet[] = {KW_EXTERN, KW_FLOAT, KW_INT, KW_VOID, (tokenType) - 1 };

    static tokenType parameterFirstSet[] = {KW_FLOAT, KW_INT, KW_VOID, (tokenType) - 1 };

    static tokenType followSet[] = {TOK_EOF, (tokenType) - 1 };

    // grammar rule
    //    { [ “extern” ] TypeSpecifier, identifier,
    //        ( [ “[”, integer, “]”],
    //        { “,”, identifier, [ “[”, integer, “]” ] }, “;”
    //         | “(”, [ Parameter, { “,”, Parameter } ], “)”,
    //         CompoundStatement
    //         )
    //    }

    bool externDef = false; // extern keyword protection
    string type; // identifier type information container
    string identifier; // identifier attribute for functions
    while ( synchronized(translationUnitFirstSet, followSet, "Expected TranslationUnit") ) {

        if ( _lookAhead.getTokenType() == KW_EXTERN ) {
            match(KW_EXTERN);
            externDef = true;
        }

        type = TypeSpecifier();

        identifier = _lookAhead.getLexeme();

        if (_lookAhead.getTokenType() == TOK_IDENT)
            if(!_symbolTable->define(_lookAhead.getLexeme(), type))
                _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Redifinition of '%s'", _lookAhead.getRow() , _lookAhead.getCol(), _lookAhead.getLexeme());

        match(TOK_IDENT);
        if( _lookAhead.getTokenType() == SYM_SQ_OPEN ||
                _lookAhead.getTokenType() == SYM_COMMA ||
                _lookAhead.getTokenType() == SYM_SEMICOLON ) {  // VARIABLE DECLARATION

            if (type == "v") {
                _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Variable has incomplete type 'void'", _lookAhead.getRow() , _lookAhead.getCol());
                _symbolTable->remove(identifier);
            }

            if ( _lookAhead.getTokenType() == SYM_SQ_OPEN ) {  // ARRAY

                match(SYM_SQ_OPEN);
                match(LIT_INT);
                if (_lookAhead.getTokenType() == SYM_SQ_CLOSE) {
                    match(SYM_SQ_CLOSE); // MUST MATCH SQUARE BRACKET CLOSE
                }

                if (type != "v") {
                    _symbolTable->reDefine(identifier, type == "i" ? "I" : "F");
                }
            }

            while ( _lookAhead.getTokenType() == SYM_COMMA ) {

                match(SYM_COMMA);

                identifier = _lookAhead.getLexeme();

                if (_lookAhead.getTokenType() == TOK_IDENT)
                    if(type != "v" &&
                            !_symbolTable->define(_lookAhead.getLexeme(), type))
                        _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Redifinition of '%s'", _lookAhead.getRow() , _lookAhead.getCol(), _lookAhead.getLexeme());

                match(TOK_IDENT);

                if( _lookAhead.getTokenType() == SYM_SQ_OPEN ) {
                    match(SYM_SQ_OPEN);
                    match(LIT_INT);
                    if (_lookAhead.getTokenType() == SYM_SQ_CLOSE) {
                        match(SYM_SQ_CLOSE);
                    }

                    if (type != "v") {
                        _symbolTable->reDefine(identifier, type == "i" ? "I" : "F");
                    }
                }
            }

            match(SYM_SEMICOLON);

        } else if ( _lookAhead.getTokenType() == SYM_OPEN ) { // FUNCTION DECLARATION OR DEFINITION

            _symbolTable->openScope();

            match(SYM_OPEN);

            if ( memberOf(_lookAhead.getTokenType(), parameterFirstSet) ) {

                type += Parameter();

                while( _lookAhead.getTokenType() == SYM_COMMA ) {
                    match(SYM_COMMA);
                    type += Parameter();
                }

            } else {
                type += "v";
            }

            match(SYM_CLOSE);

            _symbolTable->reDefine(identifier, type);

            if ( _lookAhead.getTokenType() == SYM_SEMICOLON )
                match(SYM_SEMICOLON); // FUNCTION DECLARATION
            else {
                if (externDef) {
                    _message.print(ERROR, "SEMANTIC-ANALYZER: Semantic issue on line: %i col: %i. Function defition can not be of 'extern' type", _lookAhead.getRow() , _lookAhead.getCol());
                }
                CompoundStatement(identifier); // FUNCTION DEFINITION
            }
//            _symbolTable->dump();
            _symbolTable->closeScope();
        }
    }

    _message.print(DBUG, "PARSER: End of TranslationUnit()\n");
}
Exemplo n.º 5
0
int Statement (int* PendingToken)
/* Statement parser. Returns 1 if the statement does a return/break, returns
** 0 otherwise. If the PendingToken pointer is not NULL, the function will
** not skip the terminating token of the statement (closing brace or
** semicolon), but store true if there is a pending token, and false if there
** is none. The token is always checked, so there is no need for the caller to
** check this token, it must be skipped, however. If the argument pointer is
** NULL, the function will skip the token.
*/
{
    ExprDesc Expr;
    int GotBreak;
    CodeMark Start, End;

    /* Assume no pending token */
    if (PendingToken) {
        *PendingToken = 0;
    }

    /* Check for a label. A label is always part of a statement, it does not
    ** replace one.
    */
    while (CurTok.Tok == TOK_IDENT && NextTok.Tok == TOK_COLON) {
        /* Handle the label */
        DoLabel ();
        if (CheckLabelWithoutStatement ()) {
            return 0;
        }
    }

    switch (CurTok.Tok) {

        case TOK_LCURLY:
            NextToken ();
            GotBreak = CompoundStatement ();
            CheckTok (TOK_RCURLY, "`{' expected", PendingToken);
            return GotBreak;

        case TOK_IF:
            return IfStatement ();

        case TOK_WHILE:
            WhileStatement ();
            break;

        case TOK_DO:
            DoStatement ();
            break;

        case TOK_SWITCH:
            SwitchStatement ();
            break;

        case TOK_RETURN:
            ReturnStatement ();
            CheckSemi (PendingToken);
            return 1;

        case TOK_BREAK:
            BreakStatement ();
            CheckSemi (PendingToken);
            return 1;

        case TOK_CONTINUE:
            ContinueStatement ();
            CheckSemi (PendingToken);
            return 1;

        case TOK_FOR:
            ForStatement ();
            break;

        case TOK_GOTO:
            GotoStatement ();
            CheckSemi (PendingToken);
            return 1;

        case TOK_SEMI:
            /* Ignore it */
            CheckSemi (PendingToken);
            break;

        case TOK_PRAGMA:
            DoPragma ();
            break;

        case TOK_CASE:
            CaseLabel ();
            CheckLabelWithoutStatement ();
            break;

        case TOK_DEFAULT:
            DefaultLabel ();
            CheckLabelWithoutStatement ();
            break;

        default:
            /* Remember the current code position */
            GetCodePos (&Start);
            /* Actual statement */
            ExprWithCheck (hie0, &Expr);
            /* Load the result only if it is an lvalue and the type is
            ** marked as volatile. Otherwise the load is useless.
            */
            if (ED_IsLVal (&Expr) && IsQualVolatile (Expr.Type)) {
                LoadExpr (CF_NONE, &Expr);
            }
            /* If the statement didn't generate code, and is not of type
            ** void, emit a warning.
            */
            GetCodePos (&End);
            if (CodeRangeIsEmpty (&Start, &End) &&
                !IsTypeVoid (Expr.Type)         &&
                IS_Get (&WarnNoEffect)) {
                Warning ("Statement has no effect");
            }
            CheckSemi (PendingToken);
    }
    return 0;
}
Exemplo n.º 6
0
Prog *Program()
{
   Decl();
   return new Prog(CompoundStatement());
}
Exemplo n.º 7
0
int			Tdi0Decompile_R(
struct descriptor_r	*pin,
int			prec,
struct descriptor_d	*pout)
{
struct descriptor_r	*r_ptr;
char		 	*ptext;
struct TdiFunctionStruct *fun_ptr;
int			narg = pin->ndesc;
int			m, lorr, newone, status = 1;
struct op_rec		*pop;
unsigned int		dtype;
enum OpcOpcodes        opcode;

	switch (pin->dtype) {
	default :
		status = Append("%Unknown%", pout);
		break;

	case DTYPE_PARAM :
	case DTYPE_SIGNAL :
	case DTYPE_DIMENSION :
	case DTYPE_WINDOW :
	case DTYPE_SLOPE :
	case DTYPE_CONGLOM :
	case DTYPE_ACTION :
	case DTYPE_DISPATCH :
	case DTYPE_PROGRAM :
	case DTYPE_ROUTINE :
	case DTYPE_PROCEDURE :
	case DTYPE_METHOD :
	case DTYPE_DEPENDENCY :
	case DTYPE_CONDITION :
	case DTYPE_WITH_UNITS :
	case DTYPE_WITH_ERROR :
        case DTYPE_OPAQUE :
build:		status = Append("Build_", pout);
		if (status&1)	status = Append(bname[pin->dtype - DTYPE_PARAM], pout);
		if (status&1)	status = Append("(", pout);
		if (pin->length) {
			if (pin->length == 1) opcode = (enum OpcOpcodes)(*(unsigned char *)pin->pointer);
			else if (pin->length == 2) opcode = (enum OpcOpcodes)(*(unsigned short *)pin->pointer);
			else if (pin->length == 4) opcode = (enum OpcOpcodes)(*(unsigned int *)pin->pointer);
			else opcode = (enum OpcOpcodes)-1;
			if (status&1)	status = TdiSingle(opcode, pout);
			if (status&1)	status = Append(", ", pout);
		}
		if (status&1)	status = Arguments(0, 0, ")", pin, pout);
		break;

	case DTYPE_RANGE :
		opcode = OpcDtypeRange;
		goto range;

	case DTYPE_FUNCTION :
		opcode = (enum OpcOpcodes)(*(unsigned short *)pin->pointer);
		if ((int)opcode >= TdiFUNCTION_MAX) return (int)(opcode = (enum OpcOpcodes)0);

range:		fun_ptr = (struct TdiFunctionStruct *)&TdiRefFunction[opcode];
		if (narg < fun_ptr->m1 || narg > fun_ptr->m2) goto cannot;
		else if (fun_ptr->token == LEX_CONST) status = Append(fun_ptr->name, pout);

		/*****************************************
		Functions, subscripts, and constructors.
		*****************************************/
		else switch (opcode) {
		default :		/*intrinsic(arg, ...)*/
cannot:			status = Append(fun_ptr->name, pout);
			if (status&1)	status = Arguments(0, "(", ")", pin, pout);
			break;
		case OpcFun :	/*fun ident(arg, ...) stmt*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("Fun ", pout);
			if (!(status&1)) break;
			r_ptr = (struct descriptor_r *)pin->dscptrs[0];
			if (r_ptr->dtype == DTYPE_T) status = StrAppend(pout, r_ptr);
			else status = Tdi0Decompile(r_ptr, P_SUBS, pout);
			if (status&1)	status = Arguments(2, " (", ") ", pin, pout);
			if (status&1)	status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (status&1 && prec < P_STMT)	status = Append(")", pout);
			break;
		case OpcIn :		/*input argument*/
		case OpcInOut :	/*input and output argument*/
		case OpcOptional :	/*optional argument*/
		case OpcOut :	/*output argument*/
		case OpcPrivate :	/*private ident*/
		case OpcPublic :	/*public ident*/
			status = Append(fun_ptr->name, pout);
			if (status & 1) status = Append(" ", pout);
			r_ptr = (struct descriptor_r *)pin->dscptrs[0];
			if (status & 1)
			if (r_ptr->dtype == DTYPE_T) status = StrAppend(pout, r_ptr);
			else	status = Tdi0Decompile(r_ptr, P_SUBS, pout);
			break;
		case OpcExtFunction : /*_label(arg, ...)*/
			if (pin->dscptrs[0] != 0
			|| pin->dscptrs[1] == 0
			|| pin->dscptrs[1]->dtype != DTYPE_T) goto cannot;
			status = StrAppend(pout, pin->dscptrs[1]);
			if (status&1)	status = Arguments(2, "(", ")", pin, pout);
			break;
		case OpcSubscript :	/*postfix[subscript, ...]*/
					status = Tdi0Decompile(pin->dscptrs[0], P_SUBS, pout);
			if (status&1)	status = Arguments(1, "[", "]", pin, pout);
			break;
		case OpcVector :	/*[elem, ...]*/
			status = Arguments(0, "[", "]", pin, pout);
			break;
		/****************
		Unary operations.
		****************/
		case OpcInot :	case OpcNot :
		case OpcPreDec :	case OpcPreInc :
		case OpcUnaryMinus :case OpcUnaryPlus :
		case OpcPostDec :	case OpcPostInc :
			for (pop = unary; pop->opcode; pop++) if ((enum OpcOpcodes)pop->opcode == opcode) break;
			newone = pop->prec;
			lorr = pop->lorr;
			if (		lorr > 0)	status = Append(pop->symbol, pout);
			if (status&1 && prec <= newone)	status = Append("(", pout);
			if (status&1)			status = Tdi0Decompile(pin->dscptrs[0], newone + lorr, pout);
			if (status&1 && prec <= newone)	status = Append(")", pout);
			if (status&1 && lorr < 0)	status = Append(pop->symbol, pout);
			break;

		/***********************
		Binary/n-ary operations.
		***********************/
		case OpcEqualsFirst :
			r_ptr = (struct descriptor_r *)pin->dscptrs[0];
			newone = *(unsigned short *)r_ptr->pointer;
			narg = r_ptr->ndesc;
			goto first;
		case OpcPower :
		case OpcDivide :	case OpcMultiply :
		case OpcAdd :	case OpcSubtract :
		case OpcShiftLeft :	case OpcShiftRight :
		case OpcConcat :
		case OpcIsIn :
		case OpcGe :		case OpcGt :		case OpcLe :		case OpcLt :
		case OpcEq :		case OpcNe :
		case OpcAnd :	case OpcNand :
		case OpcOr :		case OpcNor :
		case OpcEqv :	case OpcNeqv :
		case OpcPromote :
		case OpcEquals :
		case OpcDtypeRange :
		case OpcComma :
		case OpcConditional :
			r_ptr = (struct descriptor_r *)pin;
			newone = (int)opcode;
first:			for (pop = binary; pop->opcode; pop++) if (pop->opcode == newone) break;
			newone = pop->prec;
			lorr = pop->lorr;
			if (opcode == OpcEqualsFirst) {
				newone = binary[2].prec;
				lorr = binary[2].lorr;
			}
			if (prec <= newone) status = Append("(", pout);
			if (opcode == OpcConditional) {
				if (status&1)	status = Tdi0Decompile(r_ptr->dscptrs[2], newone - lorr, pout);
				if (status&1)	status = Append(pop->symbol, pout);
				if (status&1)	status = Tdi0Decompile(r_ptr->dscptrs[0], newone, pout);
				if (status&1)	status = Append(" : ", pout);
				if (status&1)	status = Tdi0Decompile(r_ptr->dscptrs[1], newone + lorr, pout);
			}
			else {
				if (status&1)	status = Tdi0Decompile(r_ptr->dscptrs[0], newone - lorr, pout);
				for (m = 1; m < narg; m++) {
					if (status&1)	status = Append(pop->symbol, pout);
					if (status&1 && pin != r_ptr) status = Append("= ", pout);
					if (status&1)	status = Tdi0Decompile(r_ptr->dscptrs[m], newone + lorr, pout);
				}
			}
			if (status&1 && prec <= newone) status = Append(")", pout);
			break;

		/*****************************************
		C-language constructs followed by newline.
		Plus WHERE.
		*****************************************/
		case OpcBreak :	/*break;*/
		case OpcContinue :	/*continue;*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append(fun_ptr->name, pout);
			if (status&1)	status = OneStatement(0, pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcCase :	/*case (xxx) stmt ...*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("Case (", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout);
			if (status&1)	status = Append(") ", pout);
			if (status&1)	status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcDefault :	/*case default stmt ...*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("Case Default ", pout);
			if (status&1)	status = MultiStatement(narg, (struct descriptor_r **)&pin->dscptrs[0], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcDo :		/*do {stmt} while (exp); Note argument order is (exp,stmt,...)*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("DO {", pout);
			if (status&1)	status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (status&1)	status = Append("} While ", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout);
			if (status&1)	status = MultiStatement(0, (struct descriptor_r **)0, pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcFor :	/*for (init;test;step) stmt*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("For (", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout);
			if (status&1)	status = Append("; ", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[1], P_STMT, pout);
			if (status&1)	status = Append("; ", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[2], P_STMT, pout);
			if (status&1)	status = Append(") ", pout);
			if (status&1)	
                           status = CompoundStatement(narg-3, (struct descriptor_r **)&pin->dscptrs[3], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcGoto :	/*goto xxx;*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("GoTo ", pout);
			if (status&1)	status = StrAppend(pout, pin->dscptrs[0]);
			if (status&1)	status = OneStatement(0, pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcIf :		/*if (exp) stmt else stmt*/
		case OpcWhere :	/*where (exp) stmt elsewhere stmt*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append((opcode == OpcIf) ? "If (" : "Where (", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout);
			if (status&1)	status = Append(") ", pout);
			if (status&1)	status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (status&1 && narg >= 3) {
						status = Append((opcode == OpcIf) ? " Else " : " ElseWhere ", pout);
				if (status&1)	
                                   status = CompoundStatement(1, (struct descriptor_r **)&pin->dscptrs[2], pout);
			}
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcLabel :	/*xxx : stmt ...*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("Label ", pout);
			if (status&1)	status = StrAppend(pout, pin->dscptrs[0]);
			if (status&1)	status = Append(" : ", pout);
			if (status&1)	status = MultiStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcReturn :	/*return (optional-exp);*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append("Return (", pout);
			if (status&1)	status = Tdi0Decompile(pin->ndesc ? pin->dscptrs[0] : 0, P_STMT, pout);
			if (status&1)	status = Append(")", pout);
			if (status&1)	status = OneStatement(0, pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcStatement :	/*{stmt ...}*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = MultiStatement(narg, (struct descriptor_r **)&pin->dscptrs[0], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		case OpcSwitch :	/*switch (exp) stmt*/
		case OpcWhile :	/*while (exp) stmt*/
			if (prec < P_STMT) status = Append("(", pout);
			if (status&1)	status = Append((opcode == OpcSwitch) ? "Switch (" : "While (", pout);
			if (status&1)	status = Tdi0Decompile(pin->dscptrs[0], P_STMT, pout);
			if (status&1)	status = Append(") ", pout);
			if (status&1)	
                           status = CompoundStatement(narg-1, (struct descriptor_r **)&pin->dscptrs[1], pout);
			if (prec < P_STMT && status&1) status = Append(")", pout);
			break;
		}
		/********************
		End of opcode switch.
		********************/
		break;
	case DTYPE_CALL : /*label->label(arg, ...) or label->label:type(arg, ...)*/
		if (pin->dscptrs[0] == 0 || pin->dscptrs[0]->dtype != DTYPE_T) goto build;
		if (pin->dscptrs[1] == 0 || pin->dscptrs[1]->dtype != DTYPE_T) goto build;
		status = StrConcat((struct descriptor *)pout, (struct descriptor *)pout, pin->dscptrs[0], &ARROW, pin->dscptrs[1] MDS_END_ARG);
		if (status&1 && pin->length && pin->pointer) {
			dtype = *(char *)pin->pointer;
			if (dtype < TdiCAT_MAX)  ptext = TdiREF_CAT[dtype].name;
			else if (dtype == DTYPE_NID) ptext = "Nid";
			else if (dtype == DTYPE_PATH) ptext = "Path";
			else ptext = "%Unknown%";
					status = Append(":", pout);
			if (status&1)	status = Append(ptext , pout);
		}
		if (status&1)	status = Arguments(2, "(", ")", pin, pout);
		break;
	}
	/*******************
	End of dtype switch.
	*******************/
	return status;
}
Exemplo n.º 8
0
void Program()
{
   Decl();
   CompoundStatement();
   Gener(STOP);
}