src/Parser.h
author David Anderson <dvander@alliedmods.net>
Sat Aug 04 20:12:20 2012 -0700 (2012-08-04)
changeset 148 c0740249963c
parent 146 dc7d3b7a918c
child 165 b67697fba413
permissions -rw-r--r--
All but interpreter support for getting and setting struct fields.
     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 *field(Expression *left);
    62     Expression *index(Expression *left);
    63     Expression *prefix();
    64     Expression *primary();
    65     Expression *unary();
    66     Expression *multiplication();
    67     Expression *addition();
    68     Expression *shift();
    69     Expression *bitand_();
    70     Expression *bitxor();
    71     Expression *bitor_();
    72     Expression *relational();
    73     Expression *equals();
    74     Expression *and_();
    75     Expression *or_();
    76     Expression *ternary();
    77     Expression *assignment();
    78     Expression *expression();
    79 
    80     Statement *struct_();
    81     Statement *enum_();
    82     Statement *if_();
    83     Statement *block(Scope *scope = NULL);
    84     Statement *function(TokenKind tok);
    85     Statement *expressionStatement();
    86     Statement *while_();
    87     Statement *do_();
    88     Statement *forStatement();
    89     Statement *localStatement();
    90     Statement *globalStatement();
    91     Statement *returnStatement();
    92 
    93     bool setupIntrinsics();
    94 
    95   public:
    96     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
    97 
    98     ParseTree *parse();
    99 };
   100 
   101 }
   102 
   103 #endif // _include_jitcraft_parser_h_