jitcraft/Parser.cpp
changeset 21 af5d8e985502
parent 14 0784ac5cc347
child 22 765ab1b672a3
     1.1 --- a/jitcraft/Parser.cpp	Sun Jul 01 11:25:36 2012 -0700
     1.2 +++ b/jitcraft/Parser.cpp	Sun Jul 01 14:52:57 2012 -0700
     1.3 @@ -17,6 +17,9 @@
     1.4   */
     1.5  #include "Zone.h"
     1.6  #include "Parser.h"
     1.7 +#include "FixedArray.h"
     1.8 +#include "Heap.h"
     1.9 +#include "Heap-inl.h"
    1.10  
    1.11  using namespace jc;
    1.12  
    1.13 @@ -112,6 +115,18 @@
    1.14          return new (pool_) IntegerLiteral(value);
    1.15        }
    1.16  
    1.17 +      case TOK_STRING_LITERAL:
    1.18 +      {
    1.19 +        // :TODO: Local
    1.20 +        scanner_.scan();
    1.21 +        ByteArray *array = ByteArray::New(ZONE(), scanner_.literal_length());
    1.22 +        if (!array)
    1.23 +            return NULL;
    1.24 +        memcpy(array->raw(), scanner_.literal(), scanner_.literal_length());
    1.25 +
    1.26 +        return new (pool_) StringLiteral(array);
    1.27 +      }
    1.28 +
    1.29        default:
    1.30        {
    1.31          fprintf(stderr, "error: expected expression!\n");
    1.32 @@ -497,10 +512,8 @@
    1.33  Parser::expressionStatement()
    1.34  {
    1.35      Expression *left = primary();
    1.36 -    if (!left) {
    1.37 -        fprintf(stderr, "expected expression or statement\n");
    1.38 +    if (!left)
    1.39          return NULL;
    1.40 -    }
    1.41  
    1.42      if (match(TOK_ASSIGN)) {
    1.43          Expression *expr = expression();
    1.44 @@ -604,7 +617,8 @@
    1.45  
    1.46      switch (scanner_.peek()) {
    1.47          case TOK_NEW:
    1.48 -          statement = variableDeclaration();
    1.49 +          if ((statement = variableDeclaration()) == NULL)
    1.50 +              return NULL;
    1.51            break;
    1.52  
    1.53          case TOK_FOR:
    1.54 @@ -629,11 +643,13 @@
    1.55            break;
    1.56  
    1.57          case TOK_RETURN:
    1.58 -          statement = returnStatement();
    1.59 +          if ((statement = returnStatement()) == NULL)
    1.60 +              return NULL;
    1.61            break;
    1.62  
    1.63          case TOK_ENUM:
    1.64 -          statement = enum_();
    1.65 +          if ((statement = enum_()) == NULL)
    1.66 +              return NULL;
    1.67            break;
    1.68  
    1.69          case TOK_IF:
    1.70 @@ -979,6 +995,10 @@
    1.71          prefix();
    1.72          fprintf(fp_, "[ ContinueStatement\n");
    1.73      }
    1.74 +    void visit(StringLiteral *node) {
    1.75 +        prefix();
    1.76 +        fprintf(fp_, "[ StringLiteral\n");
    1.77 +    }
    1.78  };
    1.79  
    1.80  void