[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie requestion on operator precedence and how to resolve an s/r c
From: |
Arlen Cuss |
Subject: |
Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly. |
Date: |
Wed, 20 Feb 2008 23:55:28 +1100 |
Well, I solved my problem. Quickly enough, I know, but it was a week or so
before this of thinking. I'll explain it if anyone's interested.
In Ruby, since an identifier could be a local variable or method at runtime,
and we don't know which, we can't differentiate the two in the parser.
Hence, function calls have a rule such as IDENTIFIER '(' ')', e.g.
"do_something()", hence we'll assume at compile time that it's a function.
If we see just an IDENTIFIER, it's an expression, and at runtime we may
execute a function by that name. ("do_something" is a valid function call)
Though I picked not the best way (at all), I scratch it down to my lack of
experience. But, it works [alas. ><]. I previously used a token
FUNCTION_CALL to denote an identifier-like token that was certainly a
function name - i.e. it ended in ! or ?. (e.g. some_obj.nil? returns true if
some_obj is nil. some `dangerous' methods end in !, or methods that alter
the object being called on, rather than returning a new modified one;
string.strip vs string.strip!). It'd be incorrect to define them as
identifiers, anyway, and so we catch invalid statements like "a! = 6" in the
parser.
I changed the lexer to first try to capture something identifier or
function-call like, but optionally ending in an opening bracket. If the
opening bracket's there, it'll emit the identifier as a FUNCTION_CALL, and
then emit a different token for the '(' - ARG_BRACKET. Hence we have rules:
funccall: FUNCTION_CALL ARG_BRACKET arglist ')'. Since there's no conflict
with '(' expr ')', all is well. :)
Hope this could help future generations, and sorry for rabbiting on so much.
Thanks for your hospitality. :)
Arlen
- Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., Arlen Cuss, 2008/02/20
- Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., Arlen Cuss, 2008/02/20
- Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., lfinsto1, 2008/02/20
- Message not available
- Fwd: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., Arlen Cuss, 2008/02/20
- Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly.,
Arlen Cuss <=
- Re: Fwd: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., lfinsto1, 2008/02/20
- Message not available
- Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., Arlen Cuss, 2008/02/20
- Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., lfinsto1, 2008/02/20
- Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., lfinsto1, 2008/02/20
Re: Newbie requestion on operator precedence and how to resolve an s/r conflict correctly., Hans Aberg, 2008/02/20