April 2002 Draft
JavaScript 2.0
Formal Description
Unit Semantics
previousupnext

Thursday, February 7, 2002

The unit semantics describe the actions the lexer takes in order to interpret a quoted unit pattern. The input to these semantics is the unit string literal’s contents after the string literal has been processed. For convenience, the unit grammar is repeated here. See also the description of the semantic notation.

This document is also available as a Word 98 rtf file.

The start nonterminal is UnitPattern.

White Space

Syntax

σ ∈ {wsoptwsreq}
WhiteSpaceCharacter 
   «TAB» | «VT» | «FF» | «SP» | «u00A0»
|  «u2000» | «u2001» | «u2002» | «u2003» | «u2004» | «u2005» | «u2006» | «u2007»
|  «u2008» | «u2009» | «u200A» | «u200B»
|  «u3000»
LineTerminator ⇒ «LF» | «CR» | «u2028» | «u2029»
RequiredWhiteSpace 
   WhiteSpaceCharacter
|  LineTerminator
|  RequiredWhiteSpace WhiteSpaceCharacter
|  RequiredWhiteSpace LineTerminator
WhiteSpacewsopt 
   RequiredWhiteSpace
|  «empty»
WhiteSpacewsreq ⇒ RequiredWhiteSpace

Unit Patterns

Syntax

UnitPattern ⇒ WhiteSpacewsopt UnitQuotient
UnitQuotient 
   UnitProductwsopt
|  UnitProductwsopt / WhiteSpacewsopt UnitProductwsopt
UnitProductσ 
   UnitFactorσ
|  UnitProductwsopt * WhiteSpacewsopt UnitFactorσ
|  UnitProductwsreq UnitFactorσ
UnitFactorσ 
   1 WhiteSpaceσ
|  1 WhiteSpacewsopt ^ WhiteSpacewsopt SignedInteger WhiteSpaceσ
|  Identifier WhiteSpaceσ
|  Identifier WhiteSpacewsopt ^ WhiteSpacewsopt SignedInteger WhiteSpaceσ

Semantics

tuple UnitFactor
identifierString,
exponentInteger
end tuple;
UnitList = UnitFactor[];
proc unitReciprocal(valueUnitList): UnitList
return [UnitFactoridentifierf.identifierexponent: –(f.exponent) | f ∈ value]
end proc;
Value[UnitPattern ⇒ WhiteSpacewsopt UnitQuotient]: UnitList = Value[UnitQuotient];
Value[UnitQuotient]: UnitList;
Value[UnitQuotient ⇒ UnitProductwsopt] = Value[UnitProductwsopt];
Value[UnitQuotient ⇒ UnitProductwsopt1 / WhiteSpacewsopt UnitProductwsopt2] = Value[UnitProductwsopt1⊕ unitReciprocal(Value[UnitProductwsopt2]);
Value[UnitProductσ]: UnitList;
Value[UnitProductσ ⇒ UnitFactorσ] = Value[UnitFactorσ];
Value[UnitProductσ0 ⇒ UnitProductwsopt1 * WhiteSpacewsopt UnitFactorσ] = Value[UnitProductwsopt1⊕ Value[UnitFactorσ];
Value[UnitProductσ0 ⇒ UnitProductwsreq1 UnitFactorσ] = Value[UnitProductwsreq1⊕ Value[UnitFactorσ];
Value[UnitFactorσ]: UnitList;
Value[UnitFactorσ ⇒ 1 WhiteSpaceσ] = [];
Value[UnitFactorσ ⇒ 1 WhiteSpacewsopt ^ WhiteSpacewsopt SignedInteger WhiteSpaceσ] = [];
Value[UnitFactorσ ⇒ Identifier WhiteSpaceσ] = [UnitFactoridentifierName[Identifier], exponent: 1];
Value[UnitFactorσ ⇒ Identifier WhiteSpacewsopt ^ WhiteSpacewsopt SignedInteger WhiteSpaceσ] = [UnitFactoridentifierName[Identifier], exponentIntegerValue[SignedInteger]];

Signed Integers

Syntax

SignedInteger 
   DecimalDigits
|  + DecimalDigits
|  - DecimalDigits
DecimalDigits 
   ASCIIDigit
|  DecimalDigits ASCIIDigit
ASCIIDigit ⇒ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Semantics

IntegerValue[SignedInteger]: Integer;
IntegerValue[SignedInteger ⇒ DecimalDigits] = IntegerValue[DecimalDigits];
IntegerValue[SignedInteger ⇒ + DecimalDigits] = IntegerValue[DecimalDigits];
IntegerValue[SignedInteger ⇒ - DecimalDigits] = –IntegerValue[DecimalDigits];
IntegerValue[DecimalDigits]: Integer;
IntegerValue[DecimalDigits ⇒ ASCIIDigit] = DecimalValue[ASCIIDigit];
IntegerValue[DecimalDigits0 ⇒ DecimalDigits1 ASCIIDigit] = 10×IntegerValue[DecimalDigits1] + DecimalValue[ASCIIDigit];
DecimalValue[ASCIIDigit]: Integer = digitValue(ASCIIDigit);

Identifiers

Syntax

Identifier 
   InitialIdentifierCharacter
|  Identifier ContinuingIdentifierCharacter
InitialIdentifierCharacter ⇒ UnicodeInitialAlphabetic | $ | _
ContinuingIdentifierCharacter ⇒ UnicodeAlphanumeric | $ | _
UnicodeInitialAlphabetic ⇒ Any Unicode initial alphabetic character (includes ASCII A-Z and a-z)
UnicodeAlphanumeric ⇒ Any Unicode alphabetic or decimal digit character (includes ASCII 0-9, A-Z, and a-z)

Semantics

Name[Identifier]: String;
Name[Identifier ⇒ InitialIdentifierCharacter] = [InitialIdentifierCharacter];
Name[Identifier0 ⇒ Identifier1 ContinuingIdentifierCharacter] = Name[Identifier1⊕ [ContinuingIdentifierCharacter];

Waldemar Horwat
Last modified Thursday, February 7, 2002
previousupnext