[antlr-interest] virtual semicolons again: JavaScript, ECMAScript, ActionScript

Gyula László gyula.laszlo at profund.hu
Wed Dec 27 11:15:45 PST 2006


Hello,

I know, this has been a topic on the list before (2005), however this  
keeps coming back at me:

http://www.antlr.org/pipermail/antlr-interest/2005-October/ 
014116.html
http://www.antlr.org/pipermail/antlr-interest/2005-April/ 
011916.html


shmuel siegel wrote:
 >
 >> One aspect that is different is that Javascript expressions end
 >> either at a semi colon, or at the earliest new line that makes a
 >> valid expression.
 >
 >
 > As far as I know, this is not a valid definition for javascript
 > statements. It is true for control statements like "return" or  
"break"
 > but not for arithmetic statements.
 >
 > Consider,
 >     <script>
 >         a=3
 >         +4
 >         alert(a);
 >     </script>
 >
 > It is legal and will result in an alert with the value 7. In general,
 > a new line only marks the end of a statement if the next token cannot
 > be part of the previous pattern.

This might be true for standardized JS, however, during my AS3 parser  
construction and testing on the flex SDK, I've learnt my lesson.

Setup: My expression statements were like this



	level1expression
		:	level0expression
			(	(level1expressionOperator NL* level0expression)+
			|
			)
		;

	statement
		: 	expressionStatement statementEnd
		;

	statementEnd
		:	';' NL*
		|	NL+
		;




(the last rule generates a warning, I don't really care about :)

this worked on 99% of the flex SDK source code. However, the rest  
contains the weird Adobe vibe:

Operator after a newline, like:




	something.getHerProperty()
		.YetAnotherMethodAccessorAfterTheNewLine()

or:

	if ( (this.width > 0) && (this.height > 200)
		&& (this.doesMrBunnyHaveAHat ) )
	{
		beatTheBunny()
	}




I really can't put the newline into the expressions themselves (FYI:  
the operator with the lowest precedence swallows
the newline tokens insted of the (unknown to the parser!) real  
statement end), because there are statement lists like with the  
following:



	var showStopper:Object =
		{
			foreground:0xff0000,
			background:0x550000
		}

	var theParserNeverMakesItToHere:int = 0



I could exclude the newline, and try with virtual semicolons, however  
I found, that none of the examples for the virtual semicolons (ASDT's  
AS2 & 3 grammar, ECMAScript grammar) could handle these cases AND the  
flex sdk AND not being an ANTLR-freezer, so I feel like there's  
something here.

Any kind of help is really appreciated,
Thank you for your time,

Gyula László

email:gyula.laszlo AT profund.hu
http://profund.hu



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061227/7579ea57/attachment-0001.html 


More information about the antlr-interest mailing list