src/Parser.h
author David Anderson <dvander@alliedmods.net>
Sun Sep 16 19:02:23 2012 -0700 (2012-09-16)
changeset 187 9308d52205a0
parent 172 48cffae8c9e0
permissions -rw-r--r--
Add support for SP1-style fixed array initializers.
     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 *arrayLiteral(TokenKind kind);
    62     Expression *call(Expression *callee);
    63     Expression *field(Expression *left);
    64     Expression *index(Expression *left);
    65     Expression *prefix();
    66     Expression *primary();
    67     Expression *unary();
    68     Expression *multiplication();
    69     Expression *addition();
    70     Expression *shift();
    71     Expression *bitand_();
    72     Expression *bitxor();
    73     Expression *bitor_();
    74     Expression *relational();
    75     Expression *equals();
    76     Expression *and_();
    77     Expression *or_();
    78     Expression *ternary();
    79     Expression *assignment();
    80     Expression *expression();
    81 
    82     Statement *switch_();
    83     Statement *struct_();
    84     Statement *enum_();
    85     Statement *if_();
    86     Statement *block(Scope *scope = NULL);
    87     Statement *function(TokenKind tok);
    88     Statement *expressionStatement();
    89     Statement *while_();
    90     Statement *do_();
    91     Statement *forStatement();
    92     Statement *localStatement();
    93     Statement *globalStatement();
    94     Statement *returnStatement();
    95 
    96     bool setupIntrinsics();
    97 
    98   public:
    99     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
   100 
   101     ParseTree *parse();
   102 };
   103 
   104 }
   105 
   106 #endif // _include_jitcraft_parser_h_