--
You received this message because you are subscribed to the Google Groups "FalconPL" group.
To post to this group, send email to falc...@googlegroups.com.
To unsubscribe from this group, send email to falconpl+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/falconpl?hl=en.
Yep. the parser is brand new, and hand-made. If any incongruence is
found, unless there is a very good reason to change it, it should be
made 100% backward compatible.
In other words, since you're at it you may have a try at fixing it. All
the grammar is in engine)/sp/source_parser.cpp
Gian.
Ok cool, I'll take care of this by adding the grammar to support backward compatibility.
Thanks
Updated the array handling for strings. Using the Survival Guide array examples for test cases here is the result. Let me know if this is correct (it matches the what I see in the survival guide). Note: the general rule implemented is:
a='abcefg'
example: a[start:end]
if start or end are negative their position in the array is used. a[-5:4] converted to values = [1:4] giving the values of ('bce')
if start is less than end (I.E. [2:4], [-4:-1]) result is in order of the string
if start is greater than end (I.E. [4:2], [-1:-3] which converts to ィ [5:3]) result is in reverse order.
Here are the test cases:
pnema@1-LX-D620:~/Projects/build$ bin/falcon -i
Welcome to Falcon.
>>> a='abcefg'
"abcefg"
>>> a[2:4]
"ce"
>>> a[2:]
"cefg"
>>> a[0:3]
"abc"
>>> a[0:]
"abcefg"
>>> a[:] // This will be fixed soon in sourceparser.cpp
CP0153 at (interactive):6:4: Error in expression syntax
CP0001 at (interactive):6:6: Generic syntax error
>>> a[-2:-1]
"f"
>>> a[-4:]
"cefg"
>>> a[-1:]
"g"
>>> a[3:0]
"ecba"
>>> a[4:2]
"fec"
>>> a[-1:4]
"gf"
>>> a[-1:0]
"gfecba"
>>>
Not sure how place the result of a range array request onto the stack.
With string arrays, I created a new string, added the value in question and call VMContext->stackResult.
VMContext* ctx;
...stuff
String *s = new String();
c stuff
ctx->stackResult( 2, s->garbage() );
what class do I use for actual arrays?
Vmcontext.h defines stakcResult as: inline void stackResult( int count, const Item& result )
ClassArray is not derived from Item or has a method that returns an Item. So what is the correct way generate an array and place it onto the stack.
Does one create a new ItemArray? And place that on the stack using method elements()? This does not seem to work?
Code sample
VMContext* ctx;
...stuff
ItemArray *returnArray = new ItemArray( abs( (start - end) + 1 ) );
...stuff
loop:
returnArray->append( array[cnt] )
stuff...
ctx->stackResult( 2, *(returnArray->elements()) );
pnema@1-LX-D620:~/Projects/build$ !b
bin/falcon -i
Welcome to Falcon.
>>> a=[1,2,3,4]
[1, 2, 3, 4]
>>> a[0:]
1
>>>
a[0:] should return [1,2,3,4]
Need some help understanding the how to add a production rule for array ranges.
I looked at the code but don't fully understand it.
I'm looking to add the patterns and rule for an array range matching the pattern of [:]
So added the following:
end of parser_arraydecl.h
void apply_array_entry_range0( const Rule&, Parser& p );
sourceparser.h
Parsing::Rule r_array_entry_range0;
sourceparser.cpp
575 ArrayEntry << ( r_array_entry_range0 << "array_entry_range0" << apply_array_entry_range0.
576 << T_Colon << T_CloseSquare );
Is the above pattern correct? ( << T_Colon << T_CloseSquare ) to match [:]
parser_arraydecl.cpp
473 void apply_array_entry_range0( const Rule&, Parser& p )
474 {
475 // << T_Colon << T_CloseSquare
476 makeRange( p, 2,
477 0,
478 0,
479 0
480 );
481 }
Not sure what makeRange is doing? I assume 0's are passed as there are no expressions.
String::garbage() it's just a shortcut (which I don't even like too
much) for FALCON_GC_STORE macro applied to strings.
It should be:
ctx->stackResult( 2, FALCON_GC_STORE( coll, clsArray, theArray) );
where coll and clsArray are the Engine::instance()->collector() and
Engine::instance()->classArray() (or arrayClass()). You can create
static variables in the function so that this data is queried just once,
or put them as fields in the owning class, or ... well do anything you
like to keep them around.
The rest seems ok.
Gian.
It seems more or less correct. If it works, I'd say it's ok.
Gian.