diff --git a/samples/fun.wes b/samples/fun.wes new file mode 100644 index 0000000..d142090 --- /dev/null +++ b/samples/fun.wes @@ -0,0 +1,14 @@ +//functions of zero params don't need them: +def meet { + print("Hello") +} + +def greet(x) { + print("Hello, " + x.to_string()) +} + +//but you need parens for invocation: +meet() + +//multiple commands per line: +greet(1); greet("bob") diff --git a/samples/hello.wes b/samples/hello.wes new file mode 100644 index 0000000..2f9a147 --- /dev/null +++ b/samples/hello.wes @@ -0,0 +1 @@ +print("Hello") diff --git a/samples/if.wes b/samples/if.wes new file mode 100644 index 0000000..cbbde8c --- /dev/null +++ b/samples/if.wes @@ -0,0 +1,10 @@ +i = 0 +if (i == 0) { + print("i is 0") +} +elseif (i == 1) { + print("i is 1") +} +else { + print("i is not 0 or 1") +} diff --git a/samples/oper.wes b/samples/oper.wes new file mode 100644 index 0000000..c697fa7 --- /dev/null +++ b/samples/oper.wes @@ -0,0 +1,8 @@ +x = -(1 + 2 - 3 * 4 / 2) +print("Answer: " + x.to_string()) + +if (x >= 2 && x <= 4) { + print("x is between 2 and 4") +} + + diff --git a/samples/while.wes b/samples/while.wes new file mode 100644 index 0000000..f86fa9a --- /dev/null +++ b/samples/while.wes @@ -0,0 +1,5 @@ +i = 0 +while (i < 10) { + print("i: " + i.to_string()) + i = i + 1 +} diff --git a/wesley/main.cpp b/wesley/main.cpp index 516ab04..745112c 100644 --- a/wesley/main.cpp +++ b/wesley/main.cpp @@ -365,7 +365,7 @@ Rule build_parser_rules() { fundef = Ign(Str("def")) >> Id(TokenType::Identifier) >> ~(Ign(Id(TokenType::Parens_Open)) >> ~params >> Ign(Id(TokenType::Parens_Close))) >> block >> ~Ign(Id(TokenType::Semicolon)); params = Id(TokenType::Identifier) >> *(Ign(Str(",")) >> Id(TokenType::Identifier)); - block = *(Ign(Id(TokenType::Semicolon))) >> Ign(Id(TokenType::Curly_Open)) >> *(Ign(Id(TokenType::Semicolon))) >> ~statements >> Ign(Id(TokenType::Curly_Close)); + block = *(Ign(Id(TokenType::Semicolon))) >> Ign(Id(TokenType::Curly_Open)) >> *(Ign(Id(TokenType::Semicolon))) >> ~statements >> Ign(Id(TokenType::Curly_Close)) >> *(Ign(Id(TokenType::Semicolon))); equation = *((Id(TokenType::Identifier) >> Str("=")) | (Id(TokenType::Identifier) >> Str("+=")) | (Id(TokenType::Identifier) >> Str("-=")) | (Id(TokenType::Identifier) >> Str("*=")) | (Id(TokenType::Identifier) >> Str("/="))) >> boolean; boolean = comparison >> *((Str("&&") >> comparison) | (Str("||") >> comparison)); @@ -465,7 +465,7 @@ Boxed_Value evaluate_string(Lexer &lexer, Rule &parser, BoxedCPP_System &ss, con } catch (ParserError &pe) { if (filename != std::string("__EVAL__")) { - std::cout << "Parsing error: \"" << pe.reason << "\" in '" << pe.location->filename << "' line: " << pe.location->start.line << std::endl; + std::cout << "Parsing error: \"" << pe.reason << "\" in '" << pe.location->filename << "' line: " << pe.location->start.line+1 << std::endl; } else { std::cout << "Parsing error: \"" << pe.reason << "\"" << std::endl; @@ -473,7 +473,7 @@ Boxed_Value evaluate_string(Lexer &lexer, Rule &parser, BoxedCPP_System &ss, con } catch (EvalError &ee) { if (filename != std::string("__EVAL__")) { - std::cout << "Eval error: \"" << ee.reason << "\" in '" << ee.location->filename << "' line: " << ee.location->start.line << std::endl; + std::cout << "Eval error: \"" << ee.reason << "\" in '" << ee.location->filename << "' line: " << ee.location->start.line+1 << std::endl; } else { std::cout << "Eval error: \"" << ee.reason << "\"" << std::endl;