Implement unusual syntax rules in grammar

Austin Hastings Austin_Hastings at Yahoo.com
Sun Aug 9 11:36:17 UTC 2009


Igor V. Burago wrote:
>  1. The language's control structures ('if', 'while', etc.) always ends with keyword 'end'.  It's
>     prohibited to use this reserved word for other purposes... except indexing!  It's allowed to use
>     it in array subscript to represent length of corresponding array dimension.
>
>     For example,
>         if <condition>
>             <block of code>
>         end
>     but
>         array(1, end - 3, 5) = 1
>   

Maintain 'end' as a reserved word, so that it cannot be used as an 
identifier. Recognize it explicitly in if/for/while, and make it a 
'term' in expressions. Rakudo does the same thing with 'self' in its 
grammar. You will need to process it specially anyway, to insert 
array-size lookup code, so you can afford to detect when it is not a 
part of an array, and attach an error.


>  2. Due to Matlab compatibility the language also has inconsistent use of whitespace.  In most cases
>     whitespace is not important and can be easily ignored by <ws> rule.  But there is an exception
>     --- array constructor where it's used as delimiter between elements.
>
>     For example,
>         [ 1 2 3 ]               three elements
>         [ 1 -2 3 ]              still three elements
>         [ 1-2 3 ]               two elements
>         [ 1- 2 ]                one element
>         [ 1 - 2 ]               again, one element
>
>     How whitespace matching behavior can be changed (for example, switched from one meaning to
>     another inside and outside of expressions in array constructor) to parse such a weird
>     constructions?
>   

That doesn't seem very strange, except in the "1 -2" case. You might 
have to define your unary-negative as excluding whitespace, but then 
<expr> [ \s <expr>]* should work.

This is sufficiently weird that I'd recommend you just don't worry about 
it. When you get the rest of the language working, someone can fill out 
an official bug report for you. :)

=Austin



More information about the parrot-dev mailing list