src/compiler/Parser.h
author David Anderson <dvander@alliedmods.net>
Mon Dec 24 02:49:20 2012 -0800 (2012-12-24)
changeset 234 26e3035cdffc
parent 212 443d24cfdf2d
child 241 18f3010a358c
permissions -rw-r--r--
Get string literals working again.
     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 "../Strings.h"
    24 #include "AST.h"
    25 #include "Scanner.h"
    26 #include "Scopes.h"
    27 
    28 namespace ke {
    29 
    30 class Parser
    31 {
    32     Zone *zone_;
    33     CompileContext &cc_;
    34     PoolAllocator &pool_;
    35     Scanner scanner_;
    36     PoolList<NameProxy *> *unbound_;
    37     PoolList<ImportStatement *> *imports_;
    38     bool encounteredReturn_;
    39 
    40   private:
    41     bool peek(TokenKind kind);
    42     bool match(TokenKind kind);
    43     bool expect(TokenKind kind);
    44     bool matchSemicolon();
    45 
    46     enum DeclKind {
    47         DeclArg,
    48         DeclFun,
    49         DeclField
    50     };
    51 
    52     VariableDeclaration *var(TypeQualifiers qual);
    53     Statement *vars(TypeQualifiers qual);
    54     bool matchName(String **name, TokenKind kind = TOK_NAME);
    55     bool typeAndName(Expression **type, String **namep);
    56     bool fullTypeAndName(Expression **type, String **namep, DeclKind kind);
    57 
    58     ExpressionList *dimensions();
    59     String *expectName();
    60 
    61     Expression *primitive();
    62     Expression *fixedArrayLiteral();
    63     Expression *call(Expression *callee);
    64     Expression *field(Expression *left);
    65     Expression *index(Expression *left);
    66     Expression *prefix();
    67     Expression *primary();
    68     Expression *unary();
    69     Expression *multiplication();
    70     Expression *addition();
    71     Expression *shift();
    72     Expression *bitand_();
    73     Expression *bitxor();
    74     Expression *bitor_();
    75     Expression *relational();
    76     Expression *equals();
    77     Expression *and_();
    78     Expression *or_();
    79     Expression *ternary();
    80     Expression *assignment();
    81     Expression *expression();
    82 
    83     Statement *switch_();
    84     Statement *struct_();
    85     Statement *enum_();
    86     Statement *if_();
    87     Statement *block();
    88     Statement *function(TokenKind tok);
    89     Statement *expressionStatement();
    90     Statement *while_();
    91     Statement *do_();
    92     Statement *forStatement();
    93     Statement *localStatement();
    94     Statement *globalStatement();
    95     Statement *returnStatement();
    96     ImportStatement *import();
    97 
    98     bool setupIntrinsics();
    99 
   100   public:
   101     Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
   102 
   103     ParseTree *parse();
   104 };
   105 
   106 }
   107 
   108 #endif // _include_jitcraft_parser_h_