Interactive mode, bug with looping while parsing some incorrect input corrected.`
parent
e124120121
commit
8dc5802c2b
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* ASTNode.cpp
|
||||||
|
*
|
||||||
|
* Created on: Nov 4, 2012
|
||||||
|
* Author: attero
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ASTNode.h"
|
||||||
|
|
||||||
|
ASTNode::ASTNode() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTNode::~ASTNode() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* ASTNode.h
|
||||||
|
*
|
||||||
|
* Created on: Nov 4, 2012
|
||||||
|
* Author: attero
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ASTNODE_H_
|
||||||
|
#define ASTNODE_H_
|
||||||
|
|
||||||
|
class ASTNode {
|
||||||
|
public:
|
||||||
|
ASTNode();
|
||||||
|
virtual ~ASTNode();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ASTNODE_H_ */
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,6 @@
|
||||||
main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \
|
main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \
|
||||||
../Tests/TestLexer.h ../Tests/TestSuite.h ../Tests/minunit.h
|
../Tests/TestLexer.h ../Tests/TestSuite.h ../Tests/minunit.h \
|
||||||
|
../Tests/../Lexer.h
|
||||||
|
|
||||||
../Token.h:
|
../Token.h:
|
||||||
|
|
||||||
|
@ -12,3 +13,5 @@ main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \
|
||||||
../Tests/TestSuite.h:
|
../Tests/TestSuite.h:
|
||||||
|
|
||||||
../Tests/minunit.h:
|
../Tests/minunit.h:
|
||||||
|
|
||||||
|
../Tests/../Lexer.h:
|
||||||
|
|
Binary file not shown.
|
@ -56,15 +56,17 @@ void Parser::interpret()
|
||||||
expr();
|
expr();
|
||||||
report(" :=\n");
|
report(" :=\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(accept(";"))
|
if(accept(";"))
|
||||||
{
|
{
|
||||||
report("Variable definition\n");
|
report("Variable definition\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect("(");
|
if(expect("("))
|
||||||
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
while(true)
|
while(tok_value!= ")")
|
||||||
{
|
{
|
||||||
argc++;
|
argc++;
|
||||||
is_type();
|
is_type();
|
||||||
|
@ -84,6 +86,9 @@ void Parser::interpret()
|
||||||
statement();
|
statement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else expect(";");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
report("Regular statement:\n");
|
report("Regular statement:\n");
|
||||||
|
@ -179,7 +184,7 @@ void Parser::statement()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
expr();
|
expr();
|
||||||
while(!expect(";")) read_next();
|
while(!expect(";") && tok_value != "") read_next();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,14 @@ void test_lexer()
|
||||||
|
|
||||||
tokens = lexer.parse_line(test_line2);
|
tokens = lexer.parse_line(test_line2);
|
||||||
|
|
||||||
/*for(int i=0; i< tokens.size(); i++)
|
|
||||||
{
|
|
||||||
cout << tokens[i].get_value() << " type: " << tokens[i].get_type() << endl;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_parser()
|
void test_parser()
|
||||||
{
|
{
|
||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
lines.push_back("def i; bulb; i + 3; string banan = \"kartofel\"; banan = \"banan\"; string kaboom(num how_many_times) { def z; }");
|
lines.push_back("def i; bulb; i + 3; string banan = \"kartofel\"; banan = \"banan\"; string kaboom(num how_many_times) { def z; }");
|
||||||
lines.push_back("{ i like bananas; string hello = \"hello\"; hello(); }");
|
lines.push_back("num pun");
|
||||||
lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1;}");
|
lines.push_back("def how_many_trees = 1; how_many_trees + 3 == 2; num cut_tree(num how_many) {return how_many -1}");
|
||||||
Lexer lexer;
|
Lexer lexer;
|
||||||
vector<Token> tokens;
|
vector<Token> tokens;
|
||||||
for(int i=0; i<lines.size(); i++)
|
for(int i=0; i<lines.size(); i++)
|
||||||
|
@ -50,14 +46,37 @@ void test_parser()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void interactive()
|
||||||
|
{
|
||||||
|
Lexer lexer;
|
||||||
|
|
||||||
|
vector<Token> tokens;
|
||||||
|
|
||||||
|
string input = "start";
|
||||||
|
while(input != "end\n")
|
||||||
|
{
|
||||||
|
cout << "I'm waiting for your input, Master!\n";
|
||||||
|
getline(cin, input);
|
||||||
|
tokens = lexer.parse_line(input);
|
||||||
|
Parser parser(tokens);
|
||||||
|
parser.interpret();
|
||||||
|
cout << parser.report_message;
|
||||||
|
cout << parser.error_message << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
cout << "Hello world!" << endl;
|
cout << "Hello world!" << endl;
|
||||||
|
|
||||||
TestLexer test_l;
|
TestLexer test_l;
|
||||||
test_l.run_tests();
|
//test_l.run_tests();
|
||||||
|
|
||||||
//test_parser();
|
//test_parser();
|
||||||
//test_lexer();
|
//test_lexer();
|
||||||
|
interactive();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue