jitcraft/Parser.h
author David Anderson <dvander@alliedmods.net>
Sat Jul 07 21:01:39 2012 -0700 (2012-07-07)
changeset 57 8f1e74d35718
parent 54 8e22792a3921
child 58 4d6265f95ff1
permissions -rw-r--r--
Convert AST std::vector to PoolList.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #ifndef _include_jitcraft_parser_h_
    19 #define _include_jitcraft_parser_h_
    20 
    21 #include <stdio.h>
    22 #include <vector>
    23 #include "AST.h"
    24 #include "Scanner.h"
    25 #include "Scopes.h"
    26 #include "Strings.h"
    27 
    28 namespace jc {
    29 
    30 class Parser
    31 {
    32     Zone *zone_;
    33     CompileContext &cc_;
    34     PoolAllocator &pool_;
    35     Scanner scanner_;
    36     Scope *scope_;
    37     PoolList<NameProxy *> *unbound_;
    38 
    39   private:
    40     void redeclarationError(BoundName *name);
    41     bool match(TokenKind kind);
    42     bool expect(TokenKind kind);
    43 
    44     Scope *enterScope(Scope::Kind kind);
    45 
    46     VariableDeclaration *variableDeclaration();
    47     bool matchName(String **name, TokenKind kind = TOK_NAME);
    48     String *expectName();
    49     NameProxy *bind(Handle<String> name);
    50     Expression *primitive();
    51     Expression *call(Expression *callee);
    52     Expression *index(Expression *left);
    53     Expression *prefix();
    54     Expression *primary();
    55     Expression *unary();
    56     Expression *multiplication();
    57     Expression *addition();
    58     Expression *shift();
    59     Expression *bitand_();
    60     Expression *bitxor();
    61     Expression *bitor_();
    62     Expression *relational();
    63     Expression *equals();
    64     Expression *assignment();
    65     Expression *expression();
    66 
    67     Statement *enum_();
    68     Statement *if_();
    69     Statement *block(Scope *scope = NULL);
    70     Statement *function();
    71     Statement *expressionStatement();
    72     Statement *while_();
    73     Statement *do_();
    74     Statement *forStatement();
    75     Statement *localStatement();
    76     Statement *globalStatement();
    77     Statement *returnStatement();
    78 
    79   public:
    80     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
    81 
    82     ParseTree *parse();
    83 };
    84 
    85 }
    86 
    87 #endif // _include_jitcraft_parser_h_