Skip to content

Logical and/or #22

@MickeyDelp

Description

@MickeyDelp

I have added logical and/or functions and operators with a low precedence. It makes relational operators more C/C++/C#/Java/JavaScript/Python -like. Using bitwise and/or for comparison requires parenthesis that logical and/or does not. (see code snippet below)

print "a=", 2>1 & 3>1
print "b=", (2>1) & (3>1)
print "c=", 2>1 && 3>1
ouputs:
a=0
b=1
c=1
{ "&&",    BINOP(5), (intptr_t)logicaland },
{ "||",    BINOP(5), (intptr_t)logicalor },

static Val logicaland(Val x, Val y) { return x&&y; }
static Val logicalor(Val x, Val y) { return x||y; }

Speaking of being C-like, the BNF in the readme.md shows '==' for the equality operator, but the code actually uses '='. I have changed mine to '=='. I have also changed the inequality operator from the BASIC/Pascal-like '<>' to the C-like '!='. I realize changing them would break existing scripts, but for new users of TinyScript I think it makes sense.

I've also added a bitwise not and an Elvis operator. Maybe I am getting operator crazy?

I would rather discuss all this before submitting a pull request, as I want to improve the language, not change it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions