src/Parser.h
author David Anderson <dvander@alliedmods.net>
Sun Sep 02 13:06:09 2012 -0700 (2012-09-02)
changeset 177 56f7e5b0243c
parent 172 48cffae8c9e0
child 187 9308d52205a0
permissions -rw-r--r--
Fix bug in bytecode resizing.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of SourcePawn.
     6  *
     7  * SourcePawn is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * SourcePawn. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #ifndef _include_jitcraft_parser_h_
    20 #define _include_jitcraft_parser_h_
    21 
    22 #include <stdio.h>
    23 #include "AST.h"
    24 #include "Scanner.h"
    25 #include "Scopes.h"
    26 #include "Strings.h"
    27 
    28 namespace ke {
    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     bool encounteredReturn_;
    39 
    40   private:
    41     void redeclarationError(BoundName *name);
    42     bool peek(TokenKind kind);
    43     bool match(TokenKind kind);
    44     bool expect(TokenKind kind);
    45     bool matchSemicolon();
    46 
    47     Scope *enterScope(Scope::Kind kind);
    48 
    49 
    50     VariableDeclaration *var(TokenKind scope, TokenKind kind);
    51     Statement *vars(TokenKind scope, TokenKind kind);
    52     bool matchName(String **name, TokenKind kind = TOK_NAME);
    53 
    54     NameProxy *bind(Handle<String> name);
    55     BoundName *bindType(Handle<String> string);
    56 
    57     ExpressionList *dimensions();
    58     String *expectName();
    59 
    60     Expression *primitive();
    61     Expression *call(Expression *callee);
    62     Expression *field(Expression *left);
    63     Expression *index(Expression *left);
    64     Expression *prefix();
    65     Expression *primary();
    66     Expression *unary();
    67     Expression *multiplication();
    68     Expression *addition();
    69     Expression *shift();
    70     Expression *bitand_();
    71     Expression *bitxor();
    72     Expression *bitor_();
    73     Expression *relational();
    74     Expression *equals();
    75     Expression *and_();
    76     Expression *or_();
    77     Expression *ternary();
    78     Expression *assignment();
    79     Expression *expression();
    80 
    81     Statement *switch_();
    82     Statement *struct_();
    83     Statement *enum_();
    84     Statement *if_();
    85     Statement *block(Scope *scope = NULL);
    86     Statement *function(TokenKind tok);
    87     Statement *expressionStatement();
    88     Statement *while_();
    89     Statement *do_();
    90     Statement *forStatement();
    91     Statement *localStatement();
    92     Statement *globalStatement();
    93     Statement *returnStatement();
    94 
    95     bool setupIntrinsics();
    96 
    97   public:
    98     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
    99 
   100     ParseTree *parse();
   101 };
   102 
   103 }
   104 
   105 #endif // _include_jitcraft_parser_h_