@@ -27,7 +27,6 @@ struct Token
27
27
COMMA,
28
28
LPAREN,
29
29
RPAREN,
30
- PROPERTY_ACCESS,
31
30
EQUALS,
32
31
EOL
33
32
} type;
@@ -224,21 +223,6 @@ namespace ast
224
223
std::string name_;
225
224
};
226
225
227
- class PropertyAccess : public Expr
228
- {
229
- public:
230
- PropertyAccess (Expr *owner, Expr *property)
231
- : owner_(owner), property_(property) {}
232
- std::string toString ()
233
- {
234
- return owner_->toString () + " " + property_->toString ();
235
- }
236
-
237
- private:
238
- Expr *owner_;
239
- Expr *property_;
240
- };
241
-
242
226
class Dim : public Node
243
227
{
244
228
public:
@@ -393,45 +377,33 @@ ast::Expr *parseIdentifier(TokenIt &it, const TokenIt &end)
393
377
394
378
std::string identifier = current->value ;
395
379
current = nextToken (it, end);
396
- if (!current || (current->type != Token::LPAREN &&
397
- current->type != Token::PROPERTY_ACCESS))
380
+ if (!current || current->type != Token::LPAREN)
398
381
return new ast::Identifier (identifier);
399
382
400
- if (current->type == Token::LPAREN)
401
- {
402
- current = nextToken (it, end);
403
- EXPECT_ANY_TOKEN (current, errorE, " Expression or ')' expected" );
383
+ current = nextToken (it, end);
384
+ EXPECT_ANY_TOKEN (current, errorE, " Expression or ')' expected" );
404
385
405
- std::vector<ast::Expr *> args;
406
- if (current->type != Token::RPAREN)
407
- while (1 )
408
- {
409
- ast::Expr *arg = parseExpr (it, end);
410
- if (!arg) return NULL ;
411
- args.push_back (arg);
412
-
413
- current = currentToken (it, end);
414
- EXPECT_ANY_TOKEN (current, errorE, " Expected ')' or ','" );
415
-
416
- if (current->type == Token::RPAREN)
417
- break ;
418
- else if (current->type != Token::COMMA)
419
- return errorE (" Expected ')' or ','" );
386
+ std::vector<ast::Expr *> args;
387
+ if (current->type != Token::RPAREN)
388
+ while (1 )
389
+ {
390
+ ast::Expr *arg = parseExpr (it, end);
391
+ if (!arg) return NULL ;
392
+ args.push_back (arg);
420
393
421
- current = nextToken (it, end);
422
- }
394
+ current = currentToken (it, end);
395
+ EXPECT_ANY_TOKEN (current, errorE, " Expected ')' or ',' " );
423
396
424
- nextToken (it, end);
425
- return new ast::CallExpr (identifier, args);
426
- }
397
+ if (current->type == Token::RPAREN)
398
+ break ;
399
+ else if (current->type != Token::COMMA)
400
+ return errorE (" Expected ')' or ','" );
427
401
428
- current = nextToken (it, end);
429
- EXPECT_TOKEN_E (current, Token::IDENTIFIER, " Identifier expected after '.' " );
402
+ current = nextToken (it, end);
403
+ }
430
404
431
- ast::Expr *property = parseIdentifier (it, end);
432
- // if(!property)
433
- return errorE (" Identifier expected after '.'" );
434
- // return new ast::PropertyAccess(identifier, property);
405
+ nextToken (it, end);
406
+ return new ast::CallExpr (identifier, args);
435
407
}
436
408
437
409
ast::Expr *parsePrimary (TokenIt &it, const TokenIt &end)
@@ -589,20 +561,32 @@ ASTNodeList *generateAST(const TokenList &tokens)
589
561
{
590
562
node = parseTopLevel (it, end);
591
563
if (node)
592
- ast->push_back (node);
564
+ ast->push_front (node);
593
565
else break ;
594
566
}
595
567
return ast;
596
568
}
597
569
598
- int main (int /* argc*/ , char */* argv*/ [])
570
+ int main (int argc, char *argv[])
599
571
{
600
- std::list<Token *> tokens;
572
+ bool showPrompt = true ;
573
+ for (int i = 1 ; i < argc; i++)
574
+ {
575
+ if (!std::strcmp (argv[i], " --no-prompt" ))
576
+ {
577
+ showPrompt = false ;
578
+ continue ;
579
+ }
580
+
581
+ std::cout << " unhandled: " << argv[i] << std::endl;
582
+ }
583
+
584
+ TokenList tokens;
601
585
602
586
do
603
587
{
604
588
tokens.clear ();
605
- std::cout << " > " ;
589
+ if (showPrompt) std::cout << " > " ;
606
590
607
591
while (1 )
608
592
{
@@ -622,6 +606,6 @@ int main(int /*argc*/, char */*argv*/[])
622
606
std::cin.clear ();
623
607
} while (tokens.size ());
624
608
625
- std::cout << std::endl;
609
+ if (showPrompt) std::cout << std::endl;
626
610
return 0 ;
627
611
}
0 commit comments