<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>namespace &#8211; Alessandro Crugnola &#8211; sephiroth.it</title>
	<atom:link href="https://blog.sephiroth.it/tag/namespace/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.sephiroth.it</link>
	<description>programmer by pure chance</description>
	<lastBuildDate>Mon, 21 Jun 2010 20:16:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://blog.sephiroth.it/wp-content/uploads/2019/03/cropped-sepy-big-32x32.png</url>
	<title>namespace &#8211; Alessandro Crugnola &#8211; sephiroth.it</title>
	<link>https://blog.sephiroth.it</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Scripting Flash apps: scanning the input file</title>
		<link>https://blog.sephiroth.it/2008/12/16/scripting-flash-apps-scanning-the-input-file/</link>
					<comments>https://blog.sephiroth.it/2008/12/16/scripting-flash-apps-scanning-the-input-file/#comments</comments>
		
		<dc:creator><![CDATA[Alessandro Crugnola]]></dc:creator>
		<pubDate>Tue, 16 Dec 2008 17:06:54 +0000</pubDate>
				<category><![CDATA[scripting languages]]></category>
		<category><![CDATA[aif]]></category>
		<category><![CDATA[lexer]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[token]]></category>
		<category><![CDATA[yacc]]></category>
		<guid isPermaLink="false">http://blog.sephiroth.it/?p=269</guid>

					<description><![CDATA[Here we go. I know that probably I should have started this new topic talking about the grammar of the language we are going to implement, but as long as I see grammar strictly related to parsing, I&#8217;ve preferred to talk about scanning first. We will go back to the grammar the next time, when &#8230; <a href="https://blog.sephiroth.it/2008/12/16/scripting-flash-apps-scanning-the-input-file/" class="more-link">Continue reading <span class="screen-reader-text">Scripting Flash apps: scanning the input file</span></a>]]></description>
										<content:encoded><![CDATA[<p>Here we go. I know that probably I should have started this new topic talking about the grammar of the language we are going to implement, but as long as I see grammar strictly related to parsing, I&#8217;ve preferred to talk about <strong>scanning</strong> first.</p>
<p>We will go back to the grammar the next time, when talking about how to parse an input file.</p>
<p>I wrote about scanning (or <strong>lexing</strong> if you prefer) a while ago, when blogging about expression evalution in ActionScript. Scanning an input file is quite always the same (although some languages might require unusual features), and what I wrote about expressions works also for a general language.</p>
<p>The goal of the scanning process is to group some characters together, skipping the ones that have no meaning for the language like spaces. Each group of characters is usually called <strong>token</strong>. So a <strong>Scanner</strong> converts a textual input into a stream of tokens, each one rappresenting a possible valid word for our language. While scanning you don&#8217;t take care about the meaning of what you are grouping or about the fact that a sequence of tokens is meaningful. This is a task for the <strong>Parser</strong> as we will see.</p>
<p>When talking about expressions, I showed a manual implementation for a Lexer. Now I want to take a different approach and show you a possible implementation for a simple dynamic scanner. This scanner will be based on <em>regular expressions</em>: each regular expression will rappresent a given token, and we will be able to assign callbacks to the scanner that will be executed each time a given token is extracted from the input.<br />
Writing a general and reusable scanner is usually a good practice. A common approach is to use some <strong>scanner generators</strong>, that are usually regular expression based too but are able to generate the code for a scanner at compile time. Our approach is different (and generates slower scanners) because regular expressions are evaluated at runtime; but it is fine for a test project.</p>
<p>You can download the source code for the regular expression based lexer (<em>RegexLexer</em>) <strong><a href="https://blog.sephiroth.it/wp-content/uploads/2008/12/scriptingflash.zip">here</a></strong>, as long as a simple usage example. Let&#8217;s see this example together so we can briefly discuss it (<em>PBLexer.as</em>):</p>
<p><span id="more-269"></span><br />
<code>package test<br />
{<br />
import it.sephiroth.scripting.utils.RegexLexer;<br />
import it.sephiroth.scripting.utils.RegexLexerContext;<br />
import it.sephiroth.scripting.utils.Token;<br />
public class PBLexer extends RegexLexer<br />
{<br />
private static const keyword_map: Object = {<br />
languageVersion:  TokensTable.LANGUAGE_VERSION,<br />
kernel:        TokensTable.KERNEL,<br />
parameter:      TokensTable.PARAMETER,<br />
input:        TokensTable.INPUT,<br />
image1:        TokensTable.IMAGE1,<br />
image2:        TokensTable.IMAGE2,<br />
image3:        TokensTable.IMAGE3,<br />
image4:        TokensTable.IMAGE4,<br />
"void":        TokensTable.VOID,<br />
output:        TokensTable.OUTPUT,<br />
evaluatePixel:    TokensTable.EVALUATE_PIXEL,<br />
"if":        TokensTable.IF,<br />
"else":        TokensTable.ELSE,<br />
"const":      TokensTable.CONST,<br />
"int":        TokensTable.INT,<br />
int2:        TokensTable.INT2,<br />
int3:        TokensTable.INT3,<br />
int4:        TokensTable.INT4,<br />
float:        TokensTable.FLOAT,<br />
float2:        TokensTable.FLOAT2,<br />
float3:        TokensTable.FLOAT3,<br />
float4:        TokensTable.FLOAT4,<br />
float2x2:      TokensTable.FLOAT2X2,<br />
float3x3:      TokensTable.FLOAT3X3,<br />
float4x4:      TokensTable.FLOAT4X4,<br />
pixel1:        TokensTable.PIXEL1,<br />
pixel2:        TokensTable.PIXEL2,<br />
pixel3:        TokensTable.PIXEL3,<br />
pixel4:        TokensTable.PIXEL4  };<br />
public function PBLexer( source_name: String, input: String )<br />
{<br />
super( source_name, input );<br />
addRule( "nl",      "\n",            -1,          RegexLexer.NL );<br />
addRule( "space",    "[ \t]+",           -1,          RegexLexer.SKIP );<br />
addRule( "comment",    "//.*",           -1,          RegexLexer.SKIP );<br />
addRule( "start_cmt",  "/\\*",           -1,          RegexLexer.START_EAT );<br />
addRule( "stop_cmt",  "\\*/",           -1,          RegexLexer.STOP_EAT );<br />
addRule( "ident",    "[a-zA-Z_][a-zA-Z_0-9]*",  TokensTable.IDENT,  onIdent );<br />
addRule( "number",    "0|([1-9][0-9]*(\\.[0-9]*)?)",  TokensTable.NUMBER, onNumber );<br />
addRule( "string",    "\"(\\\\\"|[^\"])+\"",    TokensTable.STRING, onString );<br />
addRule( "symbol",    "\\+\\+|\\-\\-|< =|>=|==|" +<br />
"!=|&amp;&amp;|\\|\\||\\*=|/=|" +<br />
"\\+=|\\-=|\\(|\\)|\\*|" +<br />
"\\+|,|\\-|\\.|/|:|;|#|" +<br />
"\\< |=|\\>|\\{|\\}|\\[|" +<br />
"\\]|\\?|!",          -1,          onSymbol );<br />
}<br />
private function onSymbol( context: RegexLexerContext ): void<br />
{<br />
var token: Token;<br />
token = new Token(<br />
context.token.value.charCodeAt( 0 ),<br />
context.token.value,<br />
context.token.sourceName,<br />
context.token.charno,<br />
context.token.lineno,<br />
context.token.columnno );<br />
context.token = token;<br />
}<br />
private function onIdent( context: RegexLexerContext ): void<br />
{<br />
var type: int;<br />
var token: Token;<br />
type = context.token.type;<br />
if( keyword_map[ context.token.value ] )<br />
{<br />
type = keyword_map[ context.token.value ];<br />
}<br />
token = new Token(<br />
type,<br />
context.token.value,<br />
context.token.sourceName,<br />
context.token.charno,<br />
context.token.lineno,<br />
context.token.columnno );<br />
context.token = token;<br />
}<br />
private function onNumber( context: RegexLexerContext ): void<br />
{<br />
var token: Token;<br />
var value: Number;<br />
value = parseFloat( context.token.value );<br />
token = new Token(<br />
context.token.type,<br />
value,<br />
context.token.sourceName,<br />
context.token.charno,<br />
context.token.lineno,<br />
context.token.columnno );<br />
context.token = token;<br />
}<br />
private function onString( context: RegexLexerContext ): void<br />
{<br />
var token: Token;<br />
var value: String;<br />
value = context.token.value.substr( 1, context.token.value.length - 2 );<br />
token = new Token(<br />
context.token.type,<br />
value,<br />
context.token.sourceName,<br />
context.token.charno,<br />
context.token.lineno,<br />
context.token.columnno );<br />
context.token = token;<br />
}<br />
}<br />
}</code><br />
As you may imagine, this example is a simple Lexer that is able to scan Pixel Bender input files. The Lexer is composed by a serie of rules registered using the function <em>addRule( name: String, regex: String, id: int, callback: Function )</em>. The callback function can be a user defined callback or a standard callback.<br />
There are some standard callbacks:</p>
<ul>
<li><strong>RegexLexer.NL</strong>: tells the Lexer that a new line token have been matched. This action increase an internal counter that keeps track of the line number;</li>
<li><strong>RegexLexer.SKIP</strong>: skip the current token;</li>
<li><strong>RegexLexer.START_EAT</strong>: start eating the tokens;</li>
<li><strong>RegexLexer.STOP_EAT</strong>: stop eating the tokens;</li>
</ul>
<p>Custom actions instead can be used to change the state of the Lexer or to generate a custom Token; take for instance the <em>onIdent</em> calback: each time an identifier is matched, we check if it is a keyword and if so, we generate the proper.</p>
<p>Here is an simple usage example:<br />
<code>package {<br />
import flash.display.Sprite;<br />
import it.sephiroth.scripting.utils.Token;<br />
import test.PBLexer;<br />
public class test extends Sprite<br />
{<br />
private static var INPUT: XML = <input />< ![CDATA[
/*****************************************************************************
*
* Copyright (C) 2008 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE:  All information contained  herein is,  and remains the property of
* Adobe Systems Incorporated and its suppliers, if any.  The intellectual and
* technical  concepts  contained  herein  are  proprietary  to  Adobe Systems
* Incorporated  and  its suppliers  and may  be covered  by U.S.  and Foreign
* Patents, patents in process, and are protected by trade secret or copyright
* law.  Dissemination of this information or reproduction of this material is
* strictly forbidden  unless prior  written permission is obtained from Adobe
* Systems Incorporated.
*
*****************************************************************************/
<languageVersion: 1.0;><br />
// basicBoxBlur: A simple example to demonstrate how to implement a 1<br />
//                iteration box blur.  The kernel is a good example to<br />
//                demonstrate how to implement a convolution using for loops.<br />
kernel basicBoxBlur<br />
< namespace : "AIF";
vendor : "Adobe Systems";
version : 2;
description : "variable Radius Box Blur"; ><br />
{<br />
// A parameter that represents the radius of the blur in both the X and Y<br />
// directions.<br />
parameter float blurRadius<br />
< minValue:float(0.0);
maxValue:float(25.0);
defaultValue:float(5.0);
>;<br />
// A dependent value.  These are calculated in the evaluateDependents()<br />
// function and save us from having to perform repetitive calculations<br />
// for each pixel.<br />
dependent int radiusAsInt;<br />
// evaluateDependents(): Built-in function to do any pre-processing of the<br />
//                       parameters.  Usage of this function helps avoid<br />
//                       repeating any necessary instructions per pixel.<br />
//                       In a filter as simple as this, the extra cycles<br />
//                       are probably not necessary, but it serves as a<br />
//                       good example.<br />
void<br />
evaluateDependents()<br />
{<br />
// Convert the dimension into a integer value for use in the iteration<br />
// over the kernel window.  All type conversions are required to be<br />
// explicit.<br />
radiusAsInt = int(ceil(blurRadius));<br />
}<br />
input image4 src;<br />
output float4 dst;<br />
// Region functions are not available in Flash targets, so we only define<br />
// the functions if we are executing on a different backend.<br />
#if !AIF_FLASH_TARGET<br />
// needed(): Indicates what area of the input is needed to fulfill the<br />
//           requested output region.  In this case, we consider a<br />
//           radius sized area of the input for each output pixel, so we<br />
//           need to outset the area by one.<br />
region needed(region outputRegion, imageRef inputRef)<br />
{<br />
float2 singlePixel = pixelSize(src);<br />
return outset(outputRegion, float2(singlePixel.x * ceil(blurRadius), singlePixel.y * ceil(blurRadius)));<br />
}<br />
// changed(): Indicates what area of the output is affected by the<br />
//            specified input.  In this case, we will blur out the image<br />
//            by the size of the radius, so the output is the input outset by<br />
//            one.<br />
region changed(region inputRegion, imageRef inputRef)<br />
{<br />
float2 singlePixel = pixelSize(src);<br />
return outset(inputRegion, float2(singlePixel.x * ceil(blurRadius), singlePixel.y * ceil(blurRadius)));<br />
}<br />
#endif<br />
// evaluatePixel(): The function of the filter that actually does the<br />
//                  processing of the image.  This function is called once<br />
//                  for each pixel of the output image.<br />
void<br />
evaluatePixel()<br />
{<br />
// Containers for both the accumulated color as well as the number of<br />
// pixels touched.<br />
float denominator = 0.0;<br />
float4 colorAccumulator = float4(0.0, 0.0, 0.0, 0.0);<br />
float2 singlePixel = pixelSize(src);<br />
// Iterate through the kernel window, adding up the samples in<br />
// that location.<br />
for(int i = -radiusAsInt; i < = radiusAsInt; i++)
{
for(int j = -radiusAsInt; j <= radiusAsInt; j++)
{
colorAccumulator += sampleNearest(src,
outCoord() + float2(float(i) * singlePixel.x, float(j) * singlePixel.y));
denominator++;
}
}
// calculate the resultant pixel value which is the accumulated color
// divided by the total number of pixels.
// In this case, the denominator is 9.
dst = colorAccumulator / denominator;
}
}
]]&gt;<br />
public function test()<br />
{<br />
super();<br />
var token: Token;<br />
var lexer: PBLexer;<br />
lexer = new PBLexer( "<file>", INPUT.text() );<br />
while( token = lexer.next() )<br />
{<br />
if( token.type == Token.EOF )<br />
{<br />
break;<br />
}<br />
trace( token );<br />
}<br />
}<br />
}<br />
}</file></code><br />
Next week we will move further and start discussing the grammar, implementing a simple Parser using a custom version of <a href="http://en.wikipedia.org/wiki/Yacc">Yacc</a> that generates ActionScript code.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.sephiroth.it/2008/12/16/scripting-flash-apps-scanning-the-input-file/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>PHP6?</title>
		<link>https://blog.sephiroth.it/2006/10/23/php6/</link>
					<comments>https://blog.sephiroth.it/2006/10/23/php6/#comments</comments>
		
		<dc:creator><![CDATA[Alessandro Crugnola]]></dc:creator>
		<pubDate>Mon, 23 Oct 2006 22:51:56 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[php6]]></category>
		<category><![CDATA[strict]]></category>
		<category><![CDATA[unicode]]></category>
		<guid isPermaLink="false">http://blog.sephiroth.it/?p=177</guid>

					<description><![CDATA[waiting for php6<br />
]]></description>
										<content:encoded><![CDATA[<p>Have you already play with <strong>PHP6</strong>?<br />
Today I discovered the PHP6 CVS snapshots and I decided to take a look at it (still not tested).</p>
<p>I read some unhappy comment to the fact php want to put the <strong>Unicode </strong>settings into the php.ini, but if this change will make PHP faster  I would prefer in this way, expecially if unicode will be always set to on.<br />
Is there a reason to put unicode support off in this world? (for example I haven&#8217;t still understood why wxPython continues to releases both ansi and unicode builds&#8230;)<br />
Finally <strong>register globals</strong>&#8216; PHP3 BC to go!<br />
<strong>Namespaces</strong>. Maybe they will add namespace.. I really hope so! This is indeed one of the most awaited features for me! (<a title="php6 namespaces" href="http://blog.bitflux.ch/archive/2005/11/29/php-is-most-presumably-getting-namespaces.html" target="_blank">read</a> about a discussion on namespaces)<br />
Support for <strong>delegates.</strong></p>
<p>My big hope is also to see a &#8220;real&#8221; strict type language, but this is only my though.<br />
Backward Compatibility. Well this could cause a flame for many developers but if they really want to make a solid new product from scratch probably they dont have to take care about BC.</p>
<p>Read more about the <a title="php6 meeting in Paris" href="http://www.php.net/~derick/meeting-notes.html" target="_blank">PHP6 Novermber meeting</a> and all the proposals.<br />
<a title="php6 snapshot" href="http://snaps.php.net/" target="_blank">Download</a> the PHP6 snapshot</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.sephiroth.it/2006/10/23/php6/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Flex2 and namespaces extending components</title>
		<link>https://blog.sephiroth.it/2006/09/15/flex2-and-namespaces-extending-components/</link>
					<comments>https://blog.sephiroth.it/2006/09/15/flex2-and-namespaces-extending-components/#comments</comments>
		
		<dc:creator><![CDATA[Alessandro Crugnola]]></dc:creator>
		<pubDate>Fri, 15 Sep 2006 17:48:26 +0000</pubDate>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[namespace]]></category>
		<guid isPermaLink="false">http://blog.sephiroth.it/?p=169</guid>

					<description><![CDATA[flex2 use namespace mx_internal
]]></description>
										<content:encoded><![CDATA[<p><a href="https://blog.sephiroth.it/wp-content/uploads/2006/09/setStyle_mx_internal.png"><img decoding="async" class="size-full wp-image-860 alignright" style="margin: 4px;" title="setStyle_mx_internal" src="https://blog.sephiroth.it/wp-content/uploads/2006/09/setStyle_mx_internal.png" alt="" width="257" height="97" /></a>I took 2 hours to find a solution for that and I decided to blog it..<br />
I was creating my new <a href="http://www.adobe.com/products/flex/">Flex2</a> component extending the <a href="http://livedocs.macromedia.com/flex/2/langref/mx/core/UIComponent.html">UIComponent</a> class and I need to define new custom styles for my own component&#8230;<br />
Ok, i opened the &#8220;<a href="http://download.macromedia.com/pub/documentation/en/flex/2/flex2_createextendcomponents.pdf">create and extend components</a>&#8221; PDF guide and found that I need to put this code to accomplish it:<br />
<code lang="actionscript">private static function classConstruct():Boolean<br />
{<br />
if (!StyleManager.getStyleDeclaration("ResizeManager"))<br />
{<br />
var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration();<br />
newStyleDeclaration.setStyle("boxSize", 4);<br />
StyleManager.setStyleDeclaration("ResizeManager", newStyleDeclaration, true);<br />
}<br />
return true;<br />
}</code><br />
That&#8217;s all, but at this time the compiler die with that error message &#8220;1000: Riferimento ambiguo a setStyle&#8221;, which in english should be: &#8220;<strong>1000: Ambiguous reference to setStyle</strong>&#8220;.<br />
I google for some time but without finding a solution, then I discovered the problem. I was using in my component the mx_internal <a href="http://livedocs.macromedia.com/flex/2/langref/statements.html#use_namespace">namespace</a>, that was the problem. Once changed namespace everything was ok.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.sephiroth.it/2006/09/15/flex2-and-namespaces-extending-components/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
