#ifndef __SCANNERS_SHUNTING_YARD_PARSER_H #define __SCANNERS_SHUNTING_YARD_PARSER_H /* 5D programming language Copyright (C) 2011 Danny Milosavljevic This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "Scanners/Scanner" #include "Values/Values" #include "Values/Symbols" namespace Scanners { struct LOperatorPrecedenceList; class ShuntingYardParser { private: Scanner* scanner; LOperatorPrecedenceList* OPL; Values::NodeT bound_symbols; Values::NodeT parse_abstraction_parameter(void); int get_operator_precedence_and_associativity(Values::NodeT node, Values::NodeT& outAssociativity); int get_operator_precedence(Values::NodeT node); Values::NodeT expand_macro(Values::NodeT op1, Values::NodeT suffix); bool macro_standin_P(Values::NodeT op1); Values::NodeT expand_simple_macro(Values::NodeT value); bool simple_macro_P(Values::NodeT value) const; protected: Values::NodeT parse_exports_macro(void); Values::NodeT parse_exports_macro_body(void); Values::NodeT parse_imports_macro_body(void); Values::NodeT parse_list_macro(void); Values::NodeT parse_list_macro_body(void); Values::NodeT parse_value(void); /* what the macros think constitutes an atom */ Values::NodeT parse_let_macro(Values::NodeT operator_); Values::NodeT parse_import_macro(void); Values::NodeT parse_define_macro(Values::NodeT operator_); Values::NodeT parse_macro(void); Values::NodeT parse_quote_macro(void); Values::NodeT parseExpression(LOperatorPrecedenceList* OPL, Values::NodeT terminator); public: ShuntingYardParser(void); Values::NodeT parse(Values::NodeT operator_precedence_list, Values::NodeT terminator); Values::NodeT parseOptionalShebang(void); bool any_operator_P(Values::NodeT node); public: inline bool EOFP(void) const { return(scanner->EOFP()); } void push(FILE* input_file, int line_number, const char* input_name); void pop(void); int getPosition(void) const; protected: Values::NodeT handle_unary_operator(Values::NodeT operator_); void enter_abstraction(Values::NodeT name); void leave_abstraction(Values::NodeT name); }; extern Values::NodeT dispatchShuntingYardParser; DECLARE_SIMPLE_OPERATION(makeShuntingYardParser) }; /* end namespace */ #endif /* ndef __SCANNERS_SHUNTING_YARD_PARSER_H */