Interactive mode, bug with looping while parsing some incorrect input corrected.`

devel
Justyna Att Ilczuk 2012-11-04 16:21:51 +01:00
parent e124120121
commit 8dc5802c2b
9 changed files with 93 additions and 31 deletions

18
Sencha-lang/ASTNode.cpp Normal file
View File

@ -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
}

17
Sencha-lang/ASTNode.h Normal file
View File

@ -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.

View File

@ -1,5 +1,6 @@
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:
@ -12,3 +13,5 @@ main.d: ../main.cpp ../Token.h ../Lexer.h ../Parser.h \
../Tests/TestSuite.h:
../Tests/minunit.h:
../Tests/../Lexer.h:

Binary file not shown.

View File

@ -55,34 +55,39 @@ void Parser::interpret()
{
expr();
report(" :=\n");
}
}
if(accept(";"))
{
report("Variable definition\n");
continue;
}
expect("(");
int argc = 0;
while(true)
{
argc++;
is_type();
report("function argument: " + tok_value + "\n");
read_next();
if(peek(")"))
{
break;
}
expect(",");
if(expect("("))
{
int argc = 0;
while(tok_value!= ")")
{
argc++;
is_type();
report("function argument: " + tok_value + "\n");
read_next();
if(peek(")"))
{
break;
}
expect(",");
}
expect(")");
if(!accept(";"))
{
report("function body:\n");
statement();
}
}
expect(")");
else expect(";");
if(!accept(";"))
{
report("function body:\n");
statement();
}
}
else {
@ -179,7 +184,7 @@ void Parser::statement()
else
{
expr();
while(!expect(";")) read_next();
while(!expect(";") && tok_value != "") read_next();
}
}

View File

@ -23,18 +23,14 @@ void test_lexer()
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()
{
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("{ i like bananas; string hello = \"hello\"; hello(); }");
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("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}");
Lexer lexer;
vector<Token> tokens;
for(int i=0; i<lines.size(); i++)
@ -49,15 +45,38 @@ void test_parser()
cout << parser.error_message << endl;
}
}
}
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()
{
cout << "Hello world!" << endl;
TestLexer test_l;
test_l.run_tests();
//test_l.run_tests();
//test_parser();
//test_lexer();
//test_lexer();
interactive();
return 0;
}