Exemple #1
0
Block* Parser :: ParseBlock(){

    Block *block = new Block(new SymTable());
    symStack->push(block->table);
    blocks.push(block);
    if(isEq(scan.Get(), _SEPARATION, "{")){
        Token *token =scan.GetNext();
        while(!isEq(scan.Get(), _SEPARATION, "}") && !scan.isEnd()){
            if((token->Value == "const" || token->Value == "struct" || symStack->find_type(token->Value)||token->Value == ";"
                )
               &&(!dynamic_cast<FuncSymbol*>(symStack->find_type(token->Value))))
            {
                ParseDeclaration();


            }
            else {
                //ParseDeclaration(dynamic_cast<SymbolType*>(symStack->find_type(token->Value)));
                block->AddStatement(ParseStatement());
                //isCanUseBreak = false;
              //  scan.Next();
            }
            token = scan.Get();
        }
    }
    else
    {
        Token *token = scan.Get();
        if(token->Value == "const" || token->Value == "struct" || symStack->find_type(token->Value))
            ParseDeclaration();
        else {
            block->AddStatement(ParseStatement());
            //scan.Next();
            symStack->pop();
            return block;
        }
    }
    errorIf (!isEq(scan.Get(), _SEPARATION, "}"),"Unexpected brace", scan.Get());
    blocks.pop();
    symStack->pop();
    return block;
}
Exemple #2
0
Statement *ParseForeverStatement() 
{
	Statement *snp; 
    snp = NewStatement(st_forever, TRUE);
    snp->stype = st_forever; 
    snp->s1 = ParseStatement(); 
	// Empty statements return NULL
	if (snp->s1)
		snp->s1->outer = snp;
    return snp; 
} 
void TParser::ParseStatementList(TTokenCode terminator)
{
    //--Loop to parse statements and to check for and skip semicolons.
    do {
	ParseStatement();

	if (TokenIn(token, tlStatementStart)) {
	    Error(errMissingSemicolon);
	}
	else while (token == tcSemicolon) GetTokenAppend();
    } while ((token != terminator) && (token != tcEndOfFile));
}
void CParser::ParseStatementList(int nTabs)
{
	m_sProgress = m_sProgress + GetTabs(nTabs) 
		+ "ParseStatementList\r\n";
	CString sToken = m_oToken.GetCurrentToken();
	while(sToken != "End" && sToken != "Wend" && sToken != "")
	{
		ParseStatement(nTabs+1);
		sToken = m_oToken.GetCurrentToken();
	}
	//m_oToken.GetNextToken();
}
asCScriptNode *asCParser::ParseDoWhile()
{
	asCScriptNode *node = new asCScriptNode(snDoWhile);

	sToken t;
	GetToken(&t);
	if( t.type != ttDo )
	{
		Error(ExpectedToken("do").AddressOf(), &t);
		return node;
	}

	node->UpdateSourcePos(t.pos, t.length);

	node->AddChildLast(ParseStatement());
	if( isSyntaxError ) return node;

	GetToken(&t);
	if( t.type != ttWhile )
	{
		Error(ExpectedToken("while").AddressOf(), &t);
		return node;
	}

	GetToken(&t);
	if( t.type != ttOpenParanthesis )
	{
		Error(ExpectedToken("(").AddressOf(), &t);
		return node;
	}

	node->AddChildLast(ParseAssignment());
	if( isSyntaxError ) return node;

	GetToken(&t);
	if( t.type != ttCloseParanthesis )
	{
		Error(ExpectedToken(")").AddressOf(), &t);
		return node;
	}

	GetToken(&t);
	if( t.type != ttEndStatement )
	{
		Error(ExpectedToken(";").AddressOf(), &t);
		return node;
	}
	node->UpdateSourcePos(t.pos, t.length);

	return node;
}
Exemple #6
0
    sptr<Node> Parser::ParseWith()
    {
        sptr<StmntNode> root(new StmntNode(currToken));
        NextToken(); // Skip with
        sptr<Node> subroot(new VarListNode(ParseVar(), "Var list"));

        while(MatchSkip(COMMA, -1))
            subroot->PushChild(ParseVar());

        root->PushChild(subroot);
        Expect(DO, -1);
        root->PushChild(ParseStatement());
        return root;
    }
asCScriptNode *asCParser::ParseFor()
{
	asCScriptNode *node = new asCScriptNode(snFor);

	sToken t;
	GetToken(&t);
	if( t.type != ttFor )
	{
		Error(ExpectedToken("for").AddressOf(), &t);
		return node;
	}

	node->UpdateSourcePos(t.pos, t.length);

	GetToken(&t);
	if( t.type != ttOpenParanthesis )
	{
		Error(ExpectedToken("(").AddressOf(), &t);
		return node;
	}

	if( IsVarDecl() )
		node->AddChildLast(ParseDeclaration());
	else
		node->AddChildLast(ParseExpressionStatement());
	if( isSyntaxError ) return node;

	node->AddChildLast(ParseExpressionStatement());
	if( isSyntaxError ) return node;

	GetToken(&t);
	if( t.type != ttCloseParanthesis )
	{
		RewindTo(&t);

		node->AddChildLast(ParseAssignment());
		if( isSyntaxError ) return node;

		GetToken(&t);
		if( t.type != ttCloseParanthesis )
		{
			Error(ExpectedToken(")").AddressOf(), &t);
			return node;
		}
	}

	node->AddChildLast(ParseStatement());
	
	return node;
}
Exemple #8
0
ACTIONRESULT DETOUR_CGameSprite::ActionAssign(Action& a) {
	IECString sStatement = a.m_s1;
	CGameSprite* pSpriteRef = NULL;
	if (!a.m_oObject.IsEqualIncludeEnum(*g_poAny)) {
		a.m_oObject.DecodeIdentifiers(*this);
		pSpriteRef = (CGameSprite*)&a.m_oObject.FindTargetOfType(*this, CGAMEOBJECT_TYPE_SPRITE, FALSE);
	} else {
		pSpriteRef = this;
	}
	if (pSpriteRef &&
		a.m_i2 >= 0 && a.m_i2 < BLOCK_VAR_ARRAY_SIZE) {
		std::map<ENUM, CBlockVariables*>::iterator it = pRuleEx->m_MapActionVars.find(m_e);
		if (it == pRuleEx->m_MapActionVars.end()) pRuleEx->m_MapActionVars[m_e] = new CBlockVariables();

		if (a.m_i == ARGTYPE_INT) {
			ParseStatement(a.m_i2, a.m_i, sStatement, *pSpriteRef, *pRuleEx->m_MapActionVars[m_e]);
		} else if (a.m_i == ARGTYPE_STR) {
			ParseStatement(a.m_i2, a.m_i, sStatement, *pSpriteRef, *pRuleEx->m_MapActionVars[m_e]);
		}
	}

	return ACTIONRESULT_DONE;
}
Exemple #9
0
 sptr<Node> Parser::ParseForLoop()
 {
     sptr<StmntNode> root(new StmntNode(currToken));
     NextToken();
     root->PushChild(ParseIdent());
     Expect(ASSIGN, -1);
     root->PushChild(ParseExp());
     root->PushChild(sptr<KeywordNode>(new KeywordNode(currToken)));
     Expect(TO, DOWNTO, -1);
     root->PushChild(ParseExp());
     Expect(DO, -1);
     root->PushChild(ParseStatement());
     return root;
 }
static void ParseLoop (void)
{
	dstatement_t	*patch1;
	def_t	tempDef;
	int	contStatement;

	contStatement = numstatements;
	patch1 = &statements[numstatements];
	ParseStatement(SCONTEXT_LOOP);
	tempDef.ofs = patch1 - &statements[numstatements];
	CO_GenCode(&pr_opcodes[OP_GOTO], &tempDef, 0);
	FixContinues(contStatement);
	FixBreaks();
}
static void ParseIf (void)
{
	def_t	*e;
	dstatement_t	*patch1, *patch2;
	int	ifOpcode;

	if (LX_CheckFetch("not"))
	{
		ifOpcode = OP_IF;
	}
	else
	{
		ifOpcode = OP_IFNOT;
	}

	LX_Require("(");
	e = EX_Expression(TOP_PRIORITY);
	LX_Require(")");

	patch1 = &statements[numstatements];
	CO_GenCode(&pr_opcodes[ifOpcode], e, 0);

	ParseStatement(SCONTEXT_IF);

	if (LX_CheckFetch("else"))
	{
		patch2 = &statements[numstatements];
		CO_GenCode(&pr_opcodes[OP_GOTO], 0, 0);
		patch1->b = &statements[numstatements] - patch1;
		ParseStatement(SCONTEXT_ELSE);
		patch2->a = &statements[numstatements] - patch2;
	}
	else
	{
		patch1->b = &statements[numstatements] - patch1;
	}
}
bool JSASTForStatement::Parse(const rapidjson::Value& value)
{
    JSASTStatement::Parse(value);

    if (value.FindMember("init") && !value.FindMember("init")->value.IsNull())
    {
        const Value::Member* member = value.FindMember("init");

        String type = member->value.FindMember("type")->value.GetString();
        if (type == "VariableDeclaration")
        {
            initVariable_ = (JSASTVariableDeclaration*) ParseStatement(member->value);
        }
        else
        {
            initExpression_ = ParseExpression(member->value);
        }
    }

    if (value.FindMember("test") && !value.FindMember("test")->value.IsNull())
    {
        test_ = ParseExpression(value["test"]);
    }

    if (value.FindMember("update") && !value.FindMember("update")->value.IsNull())
    {
        update_ = ParseExpression(value["update"]);
    }

    if (value.FindMember("body"))
    {
        body_ = ParseStatement(value["body"]);
    }

    return true;
}
bool JSASTNode::ParseStatementArray(const rapidjson::Value &value, Vector<JSASTStatement *> &statements)
{

    assert(value.IsArray());

    for (Value::ConstValueIterator itr = value.Begin(); itr != value.End(); itr++)
    {
        JSASTStatement* stmt = ParseStatement(*itr);
        //assert(stmt);
        statements.Push(stmt);

    }

    return true;
}
asCScriptNode *asCParser::ParseCase()
{
	asCScriptNode *node = new asCScriptNode(snCase);

	sToken t;
	GetToken(&t);
	if( t.type != ttCase && t.type != ttDefault )
	{
		Error(ExpectedTokens("case", "default").AddressOf(), &t);
		return node;
	}

	node->UpdateSourcePos(t.pos, t.length);

	if(t.type == ttCase)
	{
		node->AddChildLast(ParseExpression());
	}

	GetToken(&t);
	if( t.type != ttColon )
	{
		Error(ExpectedToken(":").AddressOf(), &t);
		return node;
	}

	// Parse statements until we find either of }, case, default, and break
	GetToken(&t);
	RewindTo(&t);
	while( t.type != ttCase && 
		   t.type != ttDefault && 
		   t.type != ttEndStatementBlock && 
		   t.type != ttBreak )
	{

		node->AddChildLast(ParseStatement());
		if( isSyntaxError ) return node;

		GetToken(&t);
		RewindTo(&t);
	}

	// If the case was ended with a break statement, add it to the node
	if( t.type == ttBreak )
		node->AddChildLast(ParseBreak());

	return node;
}
Sentencia* Sintactico::ParseElseStatement()
{
	if ( proximo_token.GetTipo() == kw_else )
	{
		proximo_token = analizador_lexico->ObtenerSiguienteToken();

		Sentencia* else_stmt = ParseStatement();

		if ( else_stmt == 0 )
			throw SyntaxException("Cuerpo de sentencia else vacio, puede haber ambiguedad",analizador_lexico->GetLineaActual() );

		return else_stmt;
	}
	else
		return 0;
}
Sentencia* Sintactico::_ParseStatementList()
{
	//Utilizamos Primeros
	if ( proximo_token.GetTipo() == id || proximo_token.GetTipo() == kw_begin || 
		proximo_token.GetTipo() == kw_while || proximo_token.GetTipo() == kw_repeat || proximo_token.GetTipo() == kw_for ||
		proximo_token.GetTipo() == kw_if || proximo_token.GetTipo() == kw_case || proximo_token.GetTipo() == kw_write || proximo_token.GetTipo() == kw_read )
	{
		Sentencia* stmt = ParseStatement();
		Sentencia* stmt_list = _ParseStatementList();

		stmt->SetSiguiente(stmt_list);
		ListaSentencias* lista = new ListaSentencias(stmt);
		return lista;
	}

	return 0;
}
bool JSASTLabeledStatement::Parse(const rapidjson::Value& value)
{
    JSASTStatement::Parse(value);

    const Value::Member* body = value.FindMember("body");
    assert(body);

    const Value::Member* label = value.FindMember("label");
    assert(label);


    body_ = ParseStatement(body->value);
    label_ = (JSASTIdentifier*) ParseExpression(label->value,  JSAST_IDENTIFIER);

    return body_ && label_;

}
Exemple #18
0
/* ParseIf - parse the 'IF' statement */
static void ParseIf(ParseContext *c)
{
    Token tkn;
    ParseRValue(c);
    FRequire(c, T_THEN);
    PushBlock(c);
    c->bptr->type = BLOCK_IF;
    putcbyte(c, OP_BRF);
    c->bptr->u.IfBlock.nxt = putcword(c, 0);
    c->bptr->u.IfBlock.end = 0;
    if ((tkn = GetToken(c)) != T_EOL) {
        ParseStatement(c, tkn);
        fixupbranch(c, c->bptr->u.IfBlock.nxt, codeaddr(c));
        PopBlock(c);
    }
    else
        Require(c, tkn, T_EOL);
}
Preprocessor::LLITR Preprocessor::ParseDefineArguments( LLITR itr, LLITR end, LexemList& lexems, std::vector<LexemList>& args )
{
    if( itr == end || itr->Value != "(" )
    {
        PrintErrorMessage( "Expected argument list." );
        return itr;
    }
    LLITR begin_erase = itr;
    ++itr;

    while( itr != end )
    {
        LexemList argument;
        LLITR     prev = itr;
        itr = ParseStatement( itr, end, argument );
        if( itr == prev )
            return itr;

        args.push_back( argument );

        if( itr == end )
        {
            PrintErrorMessage( "0x0FA1 Unexpected end of file." );
            return itr;
        }
        if( itr->Value == "," )
        {
            ++itr;
            if( itr == end )
            {
                PrintErrorMessage( "0x0FA2 Unexpected end of file." );
                return itr;
            }
            continue;
        }
        if( itr->Value == ")" )
        {
            ++itr;
            break;
        }
    }

    return lexems.erase( begin_erase, itr );
}
Exemple #20
0
RecipeNode *Recipe::ParseStatementList()
{
RecipeNode *n=alloc(RecipeNode::statementlist);
Token::tokentype type;

	while ( (type=cur_tok.Type()) != cur_tok.rbrace && type != cur_tok.eof)
	{
		if (type == cur_tok.semicolon)
		{
			lex->token(cur_tok);
			continue;
		}

	RecipeNode *o=ParseStatement();

		n->AppendSibling(o);
	}
	return (n);
}
Exemple #21
0
void TParser::ParseWHILE(void)
{
    //--Append a placeholder location marker for the token that
    //--follows the WHILE statement.  Remember the location of this
    //--placeholder so it can be fixed up below.
    int atFollowLocationMarker = PutLocationMarker();

    //--<expr> : must be boolean
    GetTokenAppend();
    CheckBoolean(ParseExpression());

    //--DO
    Resync(tlDO, tlStatementStart);
    CondGetTokenAppend(tcDO, errMissingDO);

    //--<stmt>
    ParseStatement();
    FixupLocationMarker(atFollowLocationMarker);
}
Sentencia* Sintactico::ParseForStatement()
{
	if ( proximo_token.GetTipo() == kw_for )
	{
		proximo_token = analizador_lexico->ObtenerSiguienteToken();

		if ( proximo_token.GetTipo() == id )
		{
			string id = proximo_token.GetLexema();

			proximo_token = analizador_lexico->ObtenerSiguienteToken();

			if ( proximo_token.GetTipo() == op_asignacion )
			{
				proximo_token = analizador_lexico->ObtenerSiguienteToken();

				Expresion* inicializacion = ParseExpression();
				direccion dir = ParseDirection();
				Expresion* condicion = ParseExpression();

				if ( proximo_token.GetTipo() == kw_do )
				{
					proximo_token = analizador_lexico->ObtenerSiguienteToken();

					Sentencia* codigo = ParseStatement();
					list<Qualifier*> lista_vacia;
					Identificador* identificador = new Identificador(id,lista_vacia) ;
					return new SentenciaFor(identificador,inicializacion,dir,condicion,codigo);
				}
				else
					throw SyntaxException("Falta kw do: produccion for",analizador_lexico->GetLineaActual());

			}
			else
				throw SyntaxException("Falta un operador de asignacion: prodccion for",analizador_lexico->GetLineaActual());
		}
		else
			throw SyntaxException("Falta un id: produccion for statement",analizador_lexico->GetLineaActual());
	}
	else
		throw SyntaxException("Falta la kw FOR",analizador_lexico->GetLineaActual());
}
Exemple #23
0
Statement *ParseUntilStatement()
{
	Statement *snp; 

	currentFn->UsesPredicate = TRUE;
    snp = NewStatement(st_until, TRUE);
	snp->predreg = iflevel;
	iflevel++;
    if( lastst != openpa ) 
        error(ERR_EXPREXPECT); 
    else { 
        NextToken(); 
        if( expression(&(snp->exp)) == 0 ) 
            error(ERR_EXPREXPECT); 
        needpunc( closepa ); 
        snp->s1 = ParseStatement(); 
    } 
	iflevel--;
    return snp; 
} 
Exemple #24
0
/* parse interactively */
void PicocParseInteractiveNoStartPrompt(Picoc *pc, int EnableDebugger)
{
    struct ParseState Parser;
    enum ParseResult Ok;
    
    LexInitParser(&Parser, pc, NULL, NULL, pc->StrEmpty, TRUE, EnableDebugger);
    LexInteractiveClear(pc, &Parser);

    do
    {
        LexInteractiveStatementPrompt(pc);
        Ok = ParseStatement(&Parser, TRUE);
        LexInteractiveCompleted(pc, &Parser);
        
    } while (Ok == ParseResultOk);
    
    if (Ok == ParseResultError)
        ProgramFail(&Parser, "parse error");
    
    PlatformPrintf(pc, "\n");
}
Exemple #25
0
/* quick scan a source file for definitions */
void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource)
{
//    printf("in PicocParse function after IncludeFile %s\n",FileName);
    struct ParseState Parser;
    enum ParseResult Ok;
    struct CleanupTokenNode *NewCleanupNode;
    
    void *Tokens = LexAnalyse(FileName, Source, SourceLen, NULL);
    
    /* allocate a cleanup node so we can clean up the tokens later */
    if (!CleanupNow)
    {
        NewCleanupNode = HeapAllocMem(sizeof(struct CleanupTokenNode));
        if (NewCleanupNode == NULL)
            ProgramFail(NULL, "out of memory");
        
        NewCleanupNode->Tokens = Tokens;
        if (CleanupSource)
            NewCleanupNode->SourceText = Source;
        else
            NewCleanupNode->SourceText = NULL;
            
        NewCleanupNode->Next = CleanupTokenList;
        CleanupTokenList = NewCleanupNode;
    }
    
    /* do the parsing */
    LexInitParser(&Parser, Source, Tokens, FileName, RunIt);

    do {
        Ok = ParseStatement(&Parser, TRUE);
    } while (Ok == ParseResultOk);
    
    if (Ok == ParseResultError)
        ProgramFail(&Parser, "parse error");
    
    /* clean up */
    if (CleanupNow)
        HeapFreeMem(Tokens);
}
Exemple #26
0
/* quick scan a source file for definitions */
void PicocParse(Picoc *pc, const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger)
{
    struct ParseState Parser;
    enum ParseResult Ok;
    struct CleanupTokenNode *NewCleanupNode;
    char *RegFileName = TableStrRegister(pc, FileName);
    
    void *Tokens = LexAnalyse(pc, RegFileName, Source, SourceLen, NULL);
    
    /* allocate a cleanup node so we can clean up the tokens later */
    if (!CleanupNow)
    {
        NewCleanupNode = (struct CleanupTokenNode *) HeapCallocMem(pc, sizeof(struct CleanupTokenNode));
        if (NewCleanupNode == NULL)
            ProgramFailNoParser(pc, "out of memory");
        
        NewCleanupNode->Tokens = Tokens;
        if (CleanupSource)
            NewCleanupNode->SourceText = Source;
        else
            NewCleanupNode->SourceText = NULL;
            
        NewCleanupNode->Next = pc->CleanupTokenList;
        pc->CleanupTokenList = NewCleanupNode;
    }
    
    /* do the parsing */
    LexInitParser(&Parser, pc, Source, Tokens, RegFileName, RunIt, EnableDebugger);

    do {
        Ok = ParseStatement(&Parser, TRUE);
    } while (Ok == ParseResultOk);
    
    if (Ok == ParseResultError)
        ProgramFail(&Parser, "parse error");
    
    /* clean up */
    if (CleanupNow)
        HeapFreeMem(pc, Tokens);
}
Exemple #27
0
Statement *ParseForStatement() 
{
	Statement *snp; 

	currentFn->UsesPredicate = TRUE;
	snp = NewStatement(st_for, TRUE);
	snp->predreg = iflevel;
	iflevel++;
    needpunc(openpa); 
    if( expression(&(snp->initExpr)) == NULL ) 
        snp->initExpr = NULL; 
    needpunc(semicolon); 
    if( expression(&(snp->exp)) == NULL ) 
        snp->exp = NULL; 
    needpunc(semicolon); 
    if( expression(&(snp->incrExpr)) == NULL ) 
        snp->incrExpr = NULL; 
    needpunc(closepa); 
    snp->s1 = ParseStatement(); 
	iflevel--;
    return snp; 
} 
Exemple #28
0
/* parse interactively */
void PicocParseInteractive()
{
    struct ParseState Parser;
    enum ParseResult Ok;
    
    PlatformPrintf(INTERACTIVE_PROMPT_START);
    LexInitParser(&Parser, NULL, NULL, StrEmpty, TRUE);
//    PicocPlatformSetExitPoint();
    LexInteractiveClear(&Parser);
    do
    {
        LexInteractiveStatementPrompt();
        Ok = ParseStatement(&Parser, TRUE);
        LexInteractiveCompleted(&Parser);
        
    } while (Ok == ParseResultOk);
    
    if (Ok == ParseResultError)
        ProgramFail(&Parser, "parse error");
    
    PlatformPrintf("\n");
}
Exemple #29
0
/*
============
ParseImmediateStatements

Parse a function body
============
*/
function_t Compiler::ParseImmediateStatements( const type_t *type, const char parm_names[ MAX_PARMS ][ MAX_NAME ], 
		int numparms )
{
	int			i;
	function_t	f;
	def_t		   *defs[ MAX_PARMS ];
	
	//
	// define the parms
	//
	for( i = 0; i < numparms; i++ )
	{
		defs[ i ] = program.GetDef( type->parm_types[ i ], parm_names[ i ], pr_scope, true, &lex );
		
		f.parm_ofs[ i ] = defs[ i ]->ofs;
		if ( ( i > 0 ) && ( f.parm_ofs[ i ] < f.parm_ofs[ i - 1 ] ) )
		{
			gi.Error( ERR_DROP, "bad parm order" );
		}
	}
	
	f.code = program.numstatements;
	
	//
	// parse regular statements
	//
	// we've already passed the {
	//lex.Expect( "{" );
	
	while( !lex.Check( "}" ) )
	{
		ParseStatement();
	}
	
	// emit an end of statements opcode
	Statement( pr_opcodes, 0, 0 );
	
	return f;
}
static void ParseUntil (void)
{
	def_t	*e;
	dstatement_t	*patch1, *patch2;
	def_t	tempDef;
	int	contStatement;

	LX_Require("(");
	contStatement = numstatements;
	patch2 = &statements[numstatements];
	e = EX_Expression(TOP_PRIORITY);
	LX_Require(")");
	LX_CheckFetch("do");
	patch1 = &statements[numstatements];
	CO_GenCode(&pr_opcodes[OP_IF], e, 0);
	ParseStatement(SCONTEXT_UNTIL);
	tempDef.ofs = patch2 - &statements[numstatements];
	CO_GenCode(&pr_opcodes[OP_GOTO], &tempDef, 0);
	patch1->b = &statements[numstatements] - patch1;
	FixContinues(contStatement);
	FixBreaks();
}