diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-21 14:05:50 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-21 14:05:50 (GMT) |
| commit | 939a04d3c77bf9aa8d54e912f5e12817de51756c (patch) | |
| tree | 750119bf74b8fbcb409eaf02d03877c00056613d /src/pim/Parser.h | |
| parent | 6e44ebc358d1206c147f514225373da07b43c015 (diff) | |
| download | powder-939a04d3c77bf9aa8d54e912f5e12817de51756c.zip powder-939a04d3c77bf9aa8d54e912f5e12817de51756c.tar.gz | |
Testing new vm/language WIP
Diffstat (limited to 'src/pim/Parser.h')
| -rw-r--r-- | src/pim/Parser.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/pim/Parser.h b/src/pim/Parser.h new file mode 100644 index 0000000..c66011e --- /dev/null +++ b/src/pim/Parser.h @@ -0,0 +1,78 @@ +#pragma once + +#include <string> +#include <cstring> +#include <sstream> +#include "Scanner.h" +#include "Generator.h" +#include "Token.h" +namespace pim +{ + namespace compiler + { + class ParserExpectException: public std::exception + { + char * error; + public: + ParserExpectException(Token token, int expectingSymbol) { + error = strdup(std::string("Expecting " + Token::SymbolNames[expectingSymbol] + " got " + token.Source).c_str()); + } + ParserExpectException(Token token, std::string expectingString) { + error = strdup(std::string("Expecting " + expectingString + " got " + token.Source).c_str()); + } + const char * what() const throw() + { + return error; + } + ~ParserExpectException() throw() {}; + }; + class Parser + { + std::stringstream & source; + Generator * generator; + Scanner * scanner; + Token token; + Token lastToken; + std::string breakLabel; + std::string continueLabel; + std::stack<Token> previousTokens; + + void program(); + void functionList(); + void function(); + void functionCall(); + void block(); + void argumentList(); + void argument(); + void declarationList(); + void declaration(); + void identifierList(); + void statementList(); + void statement(); + void neighbourStatement(); + void ifStatement(); + void condition(); + void conditionalOperator(); + void assigmentStatement(); + void particleAction(); + void killStatement(); + void getStatement(); + void createStatement(); + void transformStatement(); + void expressionList(); + void expression(); + void term(); + void factor(); + void variableValue(); + + bool accept(int symbol); + bool look(int symbol); + void back(); + void expect(int symbol); + public: + Parser(std::stringstream & source_); + + std::vector<unsigned char> Compile(); + }; + } +}
\ No newline at end of file |
