xsawyerx / guacamole

Guacamole is a parser toolkit for Standard Perl. It provides fully static BNF-based parsing capability to a reasonable subset of Perl.
https://metacpan.org/pod/Guacamole
20 stars 8 forks source link

Why does it need parentheses for some built in functions but not for others? #111

Closed anonyno closed 2 years ago

anonyno commented 3 years ago

maybe i just don't understand Perl but why is print; okay but not die;. i need to use die(); for it not to complain.

Also print 'example' is okay even though "All subroutines must use parentheses".

xsawyerx commented 3 years ago

maybe i just don't understand Perl but why is print; okay but not die;. i need to use die(); for it not to complain.

This is indeed a bug. I've marked this ticket as such.

Also print 'example' is okay even though "All subroutines must use parentheses".

print (and die) are not "subroutines," they are "keywords." Keywords are the reserved barewords provided by the language, also referred to as "builtins" or "builtin functions." They do not need parenthesis by default because we are aware of their parsing rules.

User-created functions ("subroutines") require parenthesis so we can adequately figure out how to lex and parse them. Subroutine prototypes allow the user to give the perl lexer additional parsing rules so it can avoid parenthesis but that makes it very difficult to statically parse because you need to go into compilation mode to introduce these new prototypes and understand them. This is why Guacamole doesn't support subroutine prototypes and requires all subroutines (user-provided functions) to include parenthesis.

xsawyerx commented 2 years ago

die is now supported.