bool Parser::parseStart(StartAst **yynode) { *yynode = create<StartAst>(); (*yynode)->startToken = tokenStream->index() - 1; if (yytoken == Token_LBRACE) { do { ObjectAst *__node_19 = 0; if (!parseObject(&__node_19)) { expectedSymbol(AstNode::ObjectKind, "object"); return false; } (*yynode)->objectsSequence = snoc((*yynode)->objectsSequence, __node_19, memoryPool); } while (yytoken == Token_LBRACE); if (Token_EOF != yytoken) { return false; } } else { return false; } (*yynode)->endToken = tokenStream->index() - 2; return true; }
int main( void ) { char name[] = "Kate"; snoc_list res = snoc( snoc( snoc( snoc(NULL, name), name + 1), name + 2), name + 3); sprint( print_char, res ); printf("\n"); return 0; }
ntree lfs( int n, ... ) { ntree res = malloc( ntree_size ); res->tag = Br; va_list args; va_start( args, n ); int i; snoc_list list = NULL; for ( i = 0; i < n; i++ ) { int elem = va_arg( args, int ); list = snoc( list, lf(elem) ); } va_end( args ); res->at.br = list; return res; }
int main( void ) { printf("snoc list:\n"); char name[] = "Kate"; snoc_list res0 = snoc( snoc( snoc( snoc(NULL, name), name + 1), name + 2), name + 3); sprint( print_char, res0 ); printf("\n"); printf("\nntree :\n"); ntree res1 = br(snoc( snoc( NULL, lf(1) ), lfs( 3, 2, 3, 4 ))); nprint( res1 ); printf("\n"); return 0; }
bool Parser::parseObject(ObjectAst **yynode) { *yynode = create<ObjectAst>(); (*yynode)->startToken = tokenStream->index() - 1; (*yynode)->type = -1; (*yynode)->name = -1; if (yytoken == Token_LBRACE) { if (yytoken != Token_LBRACE) { expectedToken(yytoken, Token_LBRACE, "LBRACE"); return false; } yylex(); if (yytoken != Token_IDENTIFIER) { expectedToken(yytoken, Token_IDENTIFIER, "IDENTIFIER"); return false; } (*yynode)->type = tokenStream->index() - 1; yylex(); if (yytoken != Token_LPAREN) { expectedToken(yytoken, Token_LPAREN, "LPAREN"); return false; } yylex(); if (yytoken != Token_VALUE) { expectedToken(yytoken, Token_VALUE, "VALUE"); return false; } (*yynode)->name = tokenStream->index() - 1; yylex(); if (yytoken != Token_RPAREN) { expectedToken(yytoken, Token_RPAREN, "RPAREN"); return false; } yylex(); while (yytoken == Token_IDENTIFIER || yytoken == Token_LBRACE) { if (yytoken == Token_IDENTIFIER) { PropertyAst *__node_1 = 0; if (!parseProperty(&__node_1)) { expectedSymbol(AstNode::PropertyKind, "property"); return false; } (*yynode)->propertiesSequence = snoc((*yynode)->propertiesSequence, __node_1, memoryPool); } else if (yytoken == Token_LBRACE) { ObjectAst *__node_2 = 0; if (!parseObject(&__node_2)) { expectedSymbol(AstNode::ObjectKind, "object"); return false; } (*yynode)->objectsSequence = snoc((*yynode)->objectsSequence, __node_2, memoryPool); } else { return false; } } if (yytoken != Token_RBRACE) { expectedToken(yytoken, Token_RBRACE, "RBRACE"); return false; } yylex(); } else { return false; } (*yynode)->endToken = tokenStream->index() - 2; return true; }
bool Parser::parseList_type(List_typeAst **yynode) { *yynode = create<List_typeAst>(); (*yynode)->startToken = tokenStream->index() - 1; if (yytoken == Token_LIST) { if (yytoken != Token_LIST) { expectedToken(yytoken, Token_LIST, "LIST"); return false; } yylex(); if (yytoken != Token_LPAREN) { expectedToken(yytoken, Token_LPAREN, "LPAREN"); return false; } yylex(); if (yytoken != Token_LBRACKET) { expectedToken(yytoken, Token_LBRACKET, "LBRACKET"); return false; } yylex(); do { Property_typeAst *__node_0 = 0; if (!parseProperty_type(&__node_0)) { expectedSymbol(AstNode::Property_typeKind, "property_type"); return false; } (*yynode)->valuesSequence = snoc((*yynode)->valuesSequence, __node_0, memoryPool); if (yytoken != Token_SEMICOLON) { expectedToken(yytoken, Token_SEMICOLON, "SEMICOLON"); return false; } yylex(); } while (yytoken == Token_BOOLEAN || yytoken == Token_FLOAT || yytoken == Token_IDENTIFIER || yytoken == Token_INTEGER || yytoken == Token_LONG_LONG || yytoken == Token_QUATERNION || yytoken == Token_RGBA || yytoken == Token_SIZE_TWOD || yytoken == Token_STRING || yytoken == Token_UNSIGNED_INT || yytoken == Token_URL || yytoken == Token_VECTOR_FOURD || yytoken == Token_VECTOR_THREED || yytoken == Token_VECTOR_TWOD); if (yytoken != Token_RBRACKET) { expectedToken(yytoken, Token_RBRACKET, "RBRACKET"); return false; } yylex(); if (yytoken != Token_RPAREN) { expectedToken(yytoken, Token_RPAREN, "RPAREN"); return false; } yylex(); } else { return false; } (*yynode)->endToken = tokenStream->index() - 2; return true; }
int main( void ) { ntree res = br(snoc( snoc( NULL, lf(1) ), lfs( 3, 2, 3, 4 ))); nprint( res ); return 0; }