Exemple #1
0
 void Parser::ParseTypeDecl()
 {
     if (MatchSkip(TYPE, -1))
     {
         do
         {
             sptr<SymType> buff;
             string typeName(currToken->lexeme);
             NextToken(); // Skip ident
             Expect(EQUAL, -1);
             if (MatchSkip(ARRAY, -1))
             {
                 Expect(OF, -1);
                 currSymTable->PushType(new SymTypeArray(typeName, currSymTable->GetType(currToken->lexeme)));
             }
             else if (MatchSkip(POINTER, -1))
             {
                 currSymTable->PushType(new SymTypePointer(typeName, currSymTable->GetType(currToken->lexeme)));
             }
             else if (MatchSkip(RECORD, -1))
             {
                 sptr<SymTable> fields(new SymTable(currSymTable));
                 ParseVarSymbols(fields, true);
                 currSymTable->PushType(new SymTypeRecord(typeName, fields));
             }
             else if (buff = currSymTable->GetType(currToken->lexeme))
             {
                 currSymTable->PushAliasType(typeName, buff);
             }
             else throw ParserException(GetPos() + "expected type");
             NextToken();
         } while (MatchSkip(SEMICOLON, -1));
     }
 }
Exemple #2
0
    void TcpClient::connect(const IpAddress& address, NetPort port, const Duration& timeout, const Duration& pause)
    {
        Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
        Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));

        int ret;
        Clock clock;

        Socket::create(address.getProtocol());

        prv::SockAddrBuffer buffer(address, port);

        clock.start();

        do
        {
            ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());

            if(ret != 0)
            {
                std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(pause.asMilliseconds())));
            }
        }while(ret != 0 && clock.getElapsedTime() < timeout);

        Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
    }
bool Parse4DWORDS(char** sIn, unsigned long* p1, unsigned long* p2, unsigned long* p3, unsigned long* p4)
{
    if (Expect(sIn, '('))
    {
        if (GetDWORD(sIn, p1))
        {
            if (Expect(sIn, ','))
            {
                if (GetDWORD(sIn, p2))
                {
                    if (Expect(sIn, ','))
                    {
                        if (GetDWORD(sIn, p3))
                        {
                            if (Expect(sIn, ','))
                            {
                                if (GetDWORD(sIn, p4))
                                {
                                    if (Expect(sIn, ')'))
                                    {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return false;
}
Exemple #4
0
void CObjectIStreamJson::ReadBitString(CBitString& obj)
{
#if BITSTRING_AS_VECTOR
    ThrowError(fNotImplemented, "Not Implemented");
#else
    if (TopFrame().HasMemberId() && TopFrame().GetMemberId().IsCompressed()) {
        ThrowError(fNotImplemented, "Not Implemented");
        return;
    }
    Expect('\"');
    obj.clear();
    obj.resize(0);
    CBitString::size_type len = 0;
    for ( ;; ++len) {
        char c = GetChar();
        if (c == '1') {
            obj.resize(len+1);
            obj.set_bit(len);
        } else if (c != '0') {
            if ( c != 'B' ) {
                ThrowError(fFormatError, "invalid char in bit string");
            }
            break;
        }
    }
    obj.resize(len);
    Expect('\"');
#endif
}
Exemple #5
0
//=========================================================
bool Parser::Function () {
    PrintRule rule("Function");
    if (Accept(TokenType::Function) == false) {
        return false;
    }
    Expect(TokenType::Identifier);
    Expect(TokenType::OpenParentheses);

    if (Parameter()) {
        while (Accept(TokenType::Comma)) {
            if (!Parameter()) {
                throw ParsingException("Expected parameter after comma in function sig");
            }
        }
    }

    Expect(TokenType::CloseParentheses);

    SpecifiedType();

    if (!Scope()) {
        throw ParsingException("Expected scope after function");
    }

    return rule.Accept();
}
Exemple #6
0
void Parser::ProcDecl() {
    wchar_t* name;
    Obj *obj;
    int adr;
    Expect(9);
    Ident(name);
    obj = tab->NewObj(name, proc, undef);
    obj->adr = gen->pc;
    if (coco_string_equal(name, L"Main")) gen->progStart = gen->pc;
    tab->OpenScope();
    Expect(10);
    Expect(11);
    Expect(12);
    gen->Emit(ENTER, 0);
    adr = gen->pc - 2;
    while (StartOf(1)) {
        if (la->kind == 28 || la->kind == 29) {
            VarDecl();
        } else {
            Stat();
        }
    }
    Expect(13);
    gen->Emit(LEAVE);
    gen->Emit(RET);
    gen->Patch(adr, tab->topScope->nextAdr);
    tab->CloseScope();
}
TEST(SyncEngineTest, TestBatch)
{
	vector<SyncEngine::EmailStub> batch1, batch2;
	vector<UID> remote;

	for(int i = 10; i < 100; i += 10) {
		remote.push_back(i);
	}

	TestSyncEngine engine(remote);

	batch1.push_back(MakeStub(5, "id5"));
	batch1.push_back(MakeStub(15, "id15"));
	batch1.push_back(MakeStub(20, "id20"));

	engine.Diff(batch1, true);
	// Local:  5  N 15 20 ...
	// Remote: D 10  D 20 30
	Expect(engine, 1, 2);

	engine.Clear();

	batch2.push_back(MakeStub(40, "id45"));
	batch2.push_back(MakeStub(45, "id45"));
	batch2.push_back(MakeStub(50, "id50"));
	batch2.push_back(MakeStub(65, "id65"));

	engine.Diff(batch2, false);
	// Local:   N 40 45 50  N 65  N  N  N
	// Remote: 30 40  D 50 60  D 70 80 90
	Expect(engine, 5, 2);
}
void Parser::Parse() {
	t = NULL;
	la = dummyToken = new Token();
	la->val = coco_string_create(L"Dummy Token");
	Get();
	Calc();
	Expect(0);
	Expect(0);
}
Exemple #9
0
bool Disasm::ParsePJL() {
	if (!Expect("\033%-12345X") || !SkipTo(") HP-PCL XL;")) return false;
	// version";"minor";" ... \n
	int32 version, minor;
	if (ReadNumber(version) && Expect(";") && ReadNumber(minor) && Expect(";") && SkipTo("\n")) {
		printf("PCL XL %d ; %d\n", (int)version, (int)minor);
		return true;
	}
	return false;	
}
Exemple #10
0
    std::size_t TcpClient::receive(void* data, std::size_t length)
    {
        Expect(data && length, Throw(InvalidParameter, "Invalid buffer"));
        Expect(isConnected(), Throw(LogicError, "TcpClient is not connected"));

        int received = ::recv(getHandler(), reinterpret_cast<char*>(data), length, 0);

        Expect(received >= 0, Throw(InternalError, "Failed to receive data from the remote host"));

        return received;
    }
Exemple #11
0
 sptr<Node> Parser::ParseBlock(bool begin)
 {
     begin && Expect(BEGIN, -1);
     sptr<Node> list(new BlockNode(ParseStatement(), "Block node"));
     while (MatchSkip(SEMICOLON, -1))
     {
         list->PushChild(ParseStatement());
     }
     begin && Expect(END, -1);
     return list;
 }
CForStatement::CForStatement(tokenItor &itor)
{
	Expect(For, *itor++);
	m_init = StatementPtr(new CAssignmentStatement(itor));			//초기식
	Expect(To, *itor++);
	m_condition = CExpression::Parse(itor);					//조건식
	Expect(Step, *itor++);
	m_increment = StatementPtr(new CAssignmentStatement(itor));			//증감문

	m_statement = StatementPtr(CStatement::Create(itor));
}
Exemple #13
0
    std::size_t TcpClient::send(const void* data, std::size_t length)
    {
        Expect(data && length, Throw(InvalidParameter, "Invalid buffer"));
        Expect(isConnected(), Throw(LogicError, "TcpClient is not connected"));

        int sent = ::send(getHandler(), reinterpret_cast<const char*>(data), length, 0);

        Expect(sent >= 0, Throw(InternalError, "Failed to send data to the remote host"));

        return sent;
    }
Exemple #14
0
    void TcpClient::connect(const IpAddress& address, NetPort port)
    {
        Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
        Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));

        Socket::create(address.getProtocol());

        prv::SockAddrBuffer buffer(address, port);

        int ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());

        Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
    }
Exemple #15
0
 void Parser::ParseConstDecl()
 {
     if (MatchSkip(CONST, -1))
     {
         do
         {
             string name = currToken->lexeme;
             Expect(IDENT, -1);
             Expect(EQUAL, -1);
             sptr<ExprNode> exprValue(ParseExp()); // TODO get value
             currSymTable->Push(sptr<SymVar>(new SymVar(name, exprValue->GetType(), true)));
         } while (MatchSkip(SEMICOLON, -1));
     }
 }
Exemple #16
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;
 }
Exemple #17
0
// Private SMS methods
bool Modem::ClearSmsMemory(){
	if(debug) Serial.println("Clearing all sms records");
	serial->println("AT+CMGD=1,4"); // delete all SMS -- ik vertrouw die 4 niet.. is dit niet verwijder 1 tot en met 4.. wat nou als er vijf zijn..?

	if(!Expect("OK")) return false;
	return true;
}
Exemple #18
0
const char *
vcc_regexp(struct vcc *tl)
{
	char buf[BUFSIZ], *p;
	vre_t *t;
	const char *error;
	int erroroffset;
	struct inifin *ifp;

	Expect(tl, CSTR);
	if (tl->err)
		return (NULL);
	t = VRE_compile(tl->t->dec, 0, &error, &erroroffset);
	if (t == NULL) {
		VSB_printf(tl->sb,
		    "Regexp compilation error:\n\n%s\n\n", error);
		vcc_ErrWhere(tl, tl->t);
		return (NULL);
	}
	VRE_free(&t);
	bprintf(buf, "VGC_re_%u", tl->unique++);
	p = TlAlloc(tl, strlen(buf) + 1);
	strcpy(p, buf);

	Fh(tl, 0, "static void *%s;\n", buf);
	ifp = New_IniFin(tl);
	VSB_printf(ifp->ini, "\tVRT_re_init(&%s, ",buf);
	EncToken(ifp->ini, tl->t);
	VSB_printf(ifp->ini, ");");
	VSB_printf(ifp->fin, "\t\tVRT_re_fini(%s);", buf);
	vcc_NextToken(tl);
	return (p);
}
Exemple #19
0
bool Modem::ReadSms(){
	if(debug) Serial.println("Set modem to text mode.");
	serial->println("AT+CMGF=1");
	if(!Expect("OK")) return false;

	if(debug) Serial.println("requesting all stored sms messages.");
	serial->println("AT+CMGL=\"ALL\"");

	String s = "";
	while(true){
		/* Hier moeten we dus loopen door de regels die we binnen krijgen totdat we een OK ontvangen.. dan hebben we alle messages... */

		if(serial->available() > 0) {
			char c = (char)serial->read();
			s = s + c;
			Serial.print(c);
		}

		// if(debug){
		// 	Serial.println(GetMessage());
		// }

		//if(Expect("OK")) break;
	}
	Serial.println(s);

	if(debug) Serial.println("All messages read.");

	//if(debug) Serial.println("All messages processed, clearing memory.");
	//ClearSmsMemory();
	return true;
}
Exemple #20
0
void Parser::Taste() {
    wchar_t* name;
    InitDeclarations();
    Expect(27);
    Ident(name);
    tab->OpenScope();
    Expect(12);
    while (la->kind == 28 || la->kind == 29) {
        VarDecl();
    }
    while (la->kind == 9) {
        ProcDecl();
    }
    Expect(13);
    tab->CloseScope();
}
Exemple #21
0
static void
vcc_NumVal(struct vcc *tl, double *d, int *frac)
{
	double e = 0.1;
	const char *p;

	*frac = 0;
	*d = 0.0;
	Expect(tl, CNUM);
	if (tl->err) {
		*d = NAN;
		return;
	}
	for (p = tl->t->b; p < tl->t->e; p++) {
		*d *= 10;
		*d += *p - '0';
	}
	vcc_NextToken(tl);
	if (tl->t->tok != '.')
		return;
	*frac = 1;
	vcc_NextToken(tl);
	if (tl->t->tok != CNUM)
		return;
	for (p = tl->t->b; p < tl->t->e; p++) {
		*d += (*p - '0') * e;
		e *= 0.1;
	}
	vcc_NextToken(tl);
}
Exemple #22
0
//=========================================================
bool Parser::Statement () {
    PrintRule rule("Statement");
    return rule.Accept(
        FreeStatement() ||
        (DelimitedStatement() && Expect(TokenType::Semicolon))
    );
}
Exemple #23
0
//=========================================================
bool Parser::Class () {
    PrintRule rule("Class");
    if (Accept(TokenType::Class) == false) {
        return false;
    }

    Expect(TokenType::Identifier);
    Expect(TokenType::OpenCurley);

    while (
        (Var() && Expect(TokenType::Semicolon)) ||
        Function()
    );

    return rule.Accept(Expect(TokenType::CloseCurley));
}
Exemple #24
0
//=========================================================
bool Parser::Goto () {
    PrintRule rule("Goto");
    if (Accept(TokenType::Goto) == false) {
        return false;
    }
    return rule.Accept(Expect(TokenType::Identifier));
}
Exemple #25
0
//=========================================================
bool Parser::Label () {
    PrintRule rule("Label");
    if (Accept(TokenType::Label) == false) {
        return false;
    }
    return rule.Accept(Expect(TokenType::Identifier));
}
Exemple #26
0
/**
 *  conditional-expression:
 *      logical-OR-expression
 *      logical-OR-expression ? expression : conditional-expression
 */
static AstExpression ParseConditionalExpression(void)
{
	AstExpression expr;

	expr = ParseBinaryExpression(Prec[OP_OR]);
	if (CurrentToken == TK_QUESTION)
	{
		AstExpression condExpr;

		CREATE_AST_NODE(condExpr, Expression);

		condExpr->op = OP_QUESTION;
		condExpr->kids[0] = expr;
		NEXT_TOKEN;

		CREATE_AST_NODE(condExpr->kids[1], Expression);

		condExpr->kids[1]->op = OP_COLON;
		condExpr->kids[1]->kids[0] = ParseExpression();
		Expect(TK_COLON);
		condExpr->kids[1]->kids[1] = ParseConditionalExpression();

		return condExpr;
	}

	return expr;
}
Exemple #27
0
    IpAddressV6::IpAddressV6(const ByteArray& bytes) :
        IpAddress(16, true)
    {
        Expect(bytes.getCapacity() == 16, Throw(InvalidParameter, "Invalid buffer size"));

        m_bytes = bytes;
    }
Exemple #28
0
//=========================================================
bool Parser::MemberAccess () {
    PrintRule rule("MemberAccess");
    if (!Accept(TokenType::Dot) && !Accept(TokenType::Arrow)) {
        return false;
    }
    return rule.Accept(Expect(TokenType::Identifier));
}
 Value Parse()
 {
     Value v = ParseFactor();
     Gobble('LF');
     Expect('EOF');
     return v;
 }
Exemple #30
0
int main()
{
    SomeStruct myThing;
    myThing.expect()->to->be->equal();
    
    Expect().to->be->equal();
}