src/Parser.h
author David Anderson <dvander@alliedmods.net>
Sat Aug 04 19:33:06 2012 -0700 (2012-08-04)
changeset 147 9c544823d090
parent 146 dc7d3b7a918c
child 148 c0740249963c
permissions -rw-r--r--
Structure declaration support.
     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 *variableDeclaration(TokenKind kind);
    51     bool matchName(String **name, TokenKind kind = TOK_NAME);
    52 
    53     NameProxy *bind(Handle<String> name);
    54     BoundName *bindType(Handle<String> string);
    55 
    56     ExpressionList *dimensions();
    57     String *expectName();
    58 
    59     Expression *primitive();
    60     Expression *call(Expression *callee);
    61     Expression *index(Expression *left);
    62     Expression *prefix();
    63     Expression *primary();
    64     Expression *unary();
    65     Expression *multiplication();
    66     Expression *addition();
    67     Expression *shift();
    68     Expression *bitand_();
    69     Expression *bitxor();
    70     Expression *bitor_();
    71     Expression *relational();
    72     Expression *equals();
    73     Expression *and_();
    74     Expression *or_();
    75     Expression *ternary();
    76     Expression *assignment();
    77     Expression *expression();
    78 
    79     Statement *struct_();
    80     Statement *enum_();
    81     Statement *if_();
    82     Statement *block(Scope *scope = NULL);
    83     Statement *function(TokenKind tok);
    84     Statement *expressionStatement();
    85     Statement *while_();
    86     Statement *do_();
    87     Statement *forStatement();
    88     Statement *localStatement();
    89     Statement *globalStatement();
    90     Statement *returnStatement();
    91 
    92     bool setupIntrinsics();
    93 
    94   public:
    95     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
    96 
    97     ParseTree *parse();
    98 };
    99 
   100 }
   101 
   102 #endif // _include_jitcraft_parser_h_