Example #1
0
Statement *ParseIfStatement() 
{
	Statement *snp; 

	currentFn->UsesPredicate = TRUE;
    snp = NewStatement(st_if, TRUE); 
	snp->predreg = iflevel;
	iflevel++;
    if( lastst != openpa ) 
        error(ERR_EXPREXPECT); 
    else {
        NextToken(); 
        if( expression(&(snp->exp)) == 0 ) 
            error(ERR_EXPREXPECT); 
        needpunc( closepa ); 
		if (lastst==kw_then)
			NextToken();
        snp->s1 = ParseStatement(); 
        if( lastst == kw_else ) { 
            NextToken(); 
            snp->s2 = ParseStatement(); 
        } 
		else if (lastst == kw_elsif) {
            snp->s2 = ParseIfStatement(); 
		}
        else 
            snp->s2 = 0; 
    } 
	iflevel--;
    return snp; 
} 
Example #2
0
Statement *ParseStatement() 
{
	Statement *snp; 
    switch( lastst ) { 
    case semicolon: 
        NextToken(); 
        snp = NULL; 
        break; 
    case begin: 
		NextToken(); 
        snp = ParseCompoundStatement();
        return snp; 
    case kw_if: snp = ParseIfStatement(); break; 
    case kw_while: snp = ParseWhileStatement(); break; 
    case kw_until: snp = ParseUntilStatement(); break; 
    case kw_for:   snp = ParseForStatement();   break; 
    case kw_forever: snp = ParseForeverStatement(); break; 
    case kw_firstcall: snp = ParseFirstcallStatement(); break; 
    case kw_return: snp = ParseReturnStatement(); break; 
    case kw_break: snp = ParseBreakStatement(); break; 
    case kw_goto: snp = ParseGotoStatement(); break; 
    case kw_continue: snp = ParseContinueStatement(); break; 
    case kw_do:
	case kw_loop: snp = ParseDoStatement(); break; 
    case kw_switch: snp = ParseSwitchStatement(); break;
	case kw_try: snp = ParseTryStatement(); break;
	case kw_throw: snp = ParseThrowStatement(); break;
	case kw_vortex:
			snp = vortex_stmt();
			break;
	case kw_intoff: snp = ParseIntoffStatement(); break;
	case kw_inton: snp = ParseIntonStatement(); break;
	case kw_stop: snp = ParseStopStatement(); break;
	case kw_asm:
		snp = ParseAsmStatement(); break;
	case kw_critical: snp = ParseCriticalStatement(); break;
	case kw_spinlock: snp = ParseSpinlockStatement(); break;
	case kw_spinunlock: snp = ParseSpinunlockStatement(); break;
    case id:
			SkipSpaces();
            if( lastch == ':' ) 
                return ParseLabelStatement(); 
            // else fall through to parse expression
    default: 
            snp = ParseExpressionStatement(); 
            break; 
    } 
    if( snp != NULL ) 
        snp->next = NULL;
    return snp; 
} 
Sentencia* Sintactico::ParseSelectionStatement()
{
	//Utilizamos Primeros

	if ( proximo_token.GetTipo() == kw_if )
	{
		return ParseIfStatement();
	}
	else if ( proximo_token.GetTipo() == kw_case )
	{
		return ParseCaseStatement();
	}
	return 0;
}
Example #4
0
Statement *ParseIfStatement() 
{
	Statement *snp; 

  dfs.puts("<ParseIfStatement>");
	NextToken();
	if (lastst == kw_firstcall)
	   return ParseFirstcallStatement();
	currentFn->UsesPredicate = TRUE;
  snp = NewStatement(st_if, FALSE);
	snp->predreg = iflevel;
	iflevel++;
	if ((iflevel > maxPn-1) && isThor)
	    error(ERR_OUTOFPREDS);
    if( lastst != openpa ) 
        error(ERR_EXPREXPECT); 
    else {
        NextToken(); 
        if( expression(&(snp->exp)) == 0 ) 
            error(ERR_EXPREXPECT); 
        needpunc( closepa,19 ); 
		if (lastst==kw_then)
			NextToken();
        snp->s1 = ParseStatement(); 
		if (snp->s1)
			snp->s1->outer = snp;
        if( lastst == kw_else ) { 
            NextToken(); 
            snp->s2 = ParseStatement(); 
			if (snp->s2)
				snp->s2->outer = snp;
        } 
		else if (lastst == kw_elsif) {
            snp->s2 = ParseIfStatement(); 
			if (snp->s2)
				snp->s2->outer = snp;
		}
        else 
            snp->s2 = 0; 
    } 
	iflevel--;
  dfs.puts("</ParseIfStatement>");
  return snp; 
} 
Example #5
0
AST* ParseOperator(ParserState* parser) {
	AST* ast;
	switch(parser->currentToken.type) {
		case TOKEN_BEGIN:
			return ParseBlock(parser);
		case TOKEN_ID:
			ast = parser->nextToken.type == TOKEN_LEFTBRACKET ? ParseFunctionCall(parser) : ParseAssignment(parser);
			Match(parser, TOKEN_SEMICOLON);
			return ast;
		case TOKEN_LOCAL:
			ast = ParseAssignment(parser);
			Match(parser, TOKEN_SEMICOLON);
			return ast;
		case TOKEN_WHILE:
			return ParseWhileCycle(parser);
		case TOKEN_IF:
			return ParseIfStatement(parser);
		case TOKEN_FUNCTION:
			return ParseFunctionDefinition(parser);
		case TOKEN_RETURN:
			ast = ParseReturn(parser);
			Match(parser, TOKEN_SEMICOLON);
			return ast;
		case TOKEN_PRINT:
			ast =  ParsePrint(parser);
			Match(parser, TOKEN_SEMICOLON);
			return ast;
		case TOKEN_INCLUDE:
			return ParseInclude(parser);
		case TOKEN_LOAD:
			ast = ParseLoad(parser);
			Match(parser, TOKEN_SEMICOLON);
			return ast; /** TODO: Factor common parts out of switch */
	}

	FailWithUnexpectedToken(parser, parser->currentToken.type, TOKEN_ID);

	return NULL;
}