const std::shared_ptr<TAstNode> TAstNodeForSentence::GetAstNode(TLexer* const lexer)
{
	auto token = lexer->GetToken();
	if (token->Type()!=TOKEN_TYPE::STRUCTURE_FOR)
	{
		throw TInterpreterException(TInterpreterException::WRONG_GRAMMAR, token->LineNumber());
	}

	std::shared_ptr<TAstNode> result(new TAstNodeForSentence(token));

	result->AddChild(TAstNodeAssignSentence::GetAssignException(lexer));

	AddToNode(lexer, token, result);
	AddStepNode(lexer, token, result);

	CheckLeftBrace(lexer);
	CheckLineBreak(lexer);

	AddSentenceNodes(lexer, result);

	int line = lexer->PeekToken()->LineNumber();
	CheckRightBrace(lexer);
	CheckEofEol(lexer);

	result->AddChild(TAstNodeNextSentence::GetAstNode(std::make_shared<TToken>(TOKEN_TYPE::STRUCTURE_NEXT, line)));

	return result;
}
Exemple #2
0
List AddToHead(List list, Item item)
{
    Node* pnode;
    pnode=(Node*)malloc(sizeof(Node));
    if(pnode==NULL)
        printf("Add Item failed!\n");
   
    AddToNode(pnode, item);
    pnode->next=list;
    
    return pnode;
}