src/compiler/Parser.h
author Michael Busby <prodigysim@gmail.com>
Mon Jun 10 01:50:18 2013 +0100 (2013-06-10)
changeset 264 70b8f318c379
parent 263 ba85a47ee414
permissions -rw-r--r--
Parse assignment RTL instead of LTR, fixes multiple assignment (bug 5420).
asherkin@263
     1
/* vim: set ts=4 sw=4 tw=99 et:
asherkin@263
     2
 *
asherkin@263
     3
 * Copyright (C) 2012 David Anderson
asherkin@263
     4
 *
asherkin@263
     5
 * This file is part of SourcePawn.
asherkin@263
     6
 *
asherkin@263
     7
 * SourcePawn is free software: you can redistribute it and/or modify it under
asherkin@263
     8
 * the terms of the GNU General Public License as published by the Free
asherkin@263
     9
 * Software Foundation, either version 3 of the License, or (at your option)
asherkin@263
    10
 * any later version.
asherkin@263
    11
 * 
asherkin@263
    12
 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
asherkin@263
    13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
asherkin@263
    14
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
asherkin@263
    15
 *
asherkin@263
    16
 * You should have received a copy of the GNU General Public License along with
asherkin@263
    17
 * SourcePawn. If not, see http://www.gnu.org/licenses/.
asherkin@263
    18
 */
asherkin@263
    19
#ifndef _include_jitcraft_parser_h_
asherkin@263
    20
#define _include_jitcraft_parser_h_
asherkin@263
    21
asherkin@263
    22
#include <stdio.h>
asherkin@263
    23
#include "../Strings.h"
asherkin@263
    24
#include "AST.h"
asherkin@263
    25
#include "Scanner.h"
asherkin@263
    26
#include "Scopes.h"
asherkin@263
    27
asherkin@263
    28
namespace ke {
asherkin@263
    29
asherkin@263
    30
class Parser
asherkin@263
    31
{
asherkin@263
    32
    Zone *zone_;
asherkin@263
    33
    CompileContext &cc_;
asherkin@263
    34
    PoolAllocator &pool_;
asherkin@263
    35
    Scanner scanner_;
asherkin@263
    36
    PoolList<NameProxy *> *unbound_;
asherkin@263
    37
    PoolList<ImportStatement *> *imports_;
asherkin@263
    38
    bool encounteredReturn_;
asherkin@263
    39
asherkin@263
    40
  private:
asherkin@263
    41
    bool peek(TokenKind kind);
asherkin@263
    42
    bool match(TokenKind kind);
asherkin@263
    43
    bool expect(TokenKind kind);
asherkin@263
    44
    bool matchSemicolon();
asherkin@263
    45
asherkin@263
    46
    enum DeclKind {
asherkin@263
    47
        DeclArg,
asherkin@263
    48
        DeclFun,
asherkin@263
    49
        DeclField
asherkin@263
    50
    };
asherkin@263
    51
asherkin@263
    52
    VariableDeclaration *var(TypeQualifiers qual);
asherkin@263
    53
    Statement *vars(TypeQualifiers qual);
asherkin@263
    54
    bool matchName(String **name, TokenKind kind = TOK_NAME);
asherkin@263
    55
    bool typeAndName(Expression **type, String **namep);
asherkin@263
    56
    bool fullTypeAndName(Expression **type, String **namep, DeclKind kind);
asherkin@263
    57
asherkin@263
    58
    ExpressionList *dimensions();
asherkin@263
    59
    String *expectName();
asherkin@263
    60
asherkin@263
    61
    Expression *primitive();
asherkin@263
    62
    Expression *fixedArrayLiteral();
asherkin@263
    63
    Expression *call(Expression *callee);
asherkin@263
    64
    Expression *field(Expression *left);
asherkin@263
    65
    Expression *index(Expression *left);
asherkin@263
    66
    Expression *prefix();
asherkin@263
    67
    Expression *primary();
asherkin@263
    68
    Expression *unary();
asherkin@263
    69
    Expression *multiplication();
asherkin@263
    70
    Expression *addition();
asherkin@263
    71
    Expression *shift();
asherkin@263
    72
    Expression *bitand_();
asherkin@263
    73
    Expression *bitxor();
asherkin@263
    74
    Expression *bitor_();
asherkin@263
    75
    Expression *relational();
asherkin@263
    76
    Expression *equals();
asherkin@263
    77
    Expression *and_();
asherkin@263
    78
    Expression *or_();
asherkin@263
    79
    Expression *ternary();
asherkin@263
    80
    Expression *assignment();
asherkin@263
    81
    Expression *expression();
asherkin@263
    82
asherkin@263
    83
    Statement *switch_();
asherkin@263
    84
    Statement *struct_();
asherkin@263
    85
    Statement *enum_(TokenKind kind);
asherkin@263
    86
    Statement *if_();
asherkin@263
    87
    Statement *block();
asherkin@263
    88
    Statement *function(TokenKind tok);
asherkin@263
    89
    Statement *expressionStatement();
asherkin@263
    90
    Statement *while_();
asherkin@263
    91
    Statement *do_();
asherkin@263
    92
    Statement *forStatement();
asherkin@263
    93
    Statement *localStatement();
asherkin@263
    94
    Statement *globalStatement();
asherkin@263
    95
    Statement *returnStatement();
asherkin@263
    96
    ImportStatement *import(TokenKind kind);
asherkin@263
    97
asherkin@263
    98
  public:
asherkin@263
    99
    Parser(Zone *zone, CompileContext &cc, const char *stream, size_t length);
asherkin@263
   100
asherkin@263
   101
    ParseTree *parse();
asherkin@263
   102
};
asherkin@263
   103
asherkin@263
   104
}
asherkin@263
   105
asherkin@263
   106
#endif // _include_jitcraft_parser_h_