Added wesley samples
This commit is contained in:
parent
99b84c0fab
commit
9ca43e6290
14
samples/fun.wes
Normal file
14
samples/fun.wes
Normal file
@ -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")
|
1
samples/hello.wes
Normal file
1
samples/hello.wes
Normal file
@ -0,0 +1 @@
|
||||
print("Hello")
|
10
samples/if.wes
Normal file
10
samples/if.wes
Normal file
@ -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")
|
||||
}
|
8
samples/oper.wes
Normal file
8
samples/oper.wes
Normal file
@ -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")
|
||||
}
|
||||
|
||||
|
5
samples/while.wes
Normal file
5
samples/while.wes
Normal file
@ -0,0 +1,5 @@
|
||||
i = 0
|
||||
while (i < 10) {
|
||||
print("i: " + i.to_string())
|
||||
i = i + 1
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user