JavaScript 2.0
正式な記述
字句セマンティクス
previousupnext

2003-06-30 (Mon)

字句解析器が Unicode 文字の入力ストリームをトークンの並びに変換するのに使うアクションは字句セマンティクスにより記述される。ここでは利便性のために字句文法を再掲する。セマンティクスの表記法も見よ。

この文書には Word RTF 版 [英語] もある。

字句解析の開始記号は次のいずれかである。つまり、直前の入力要素が数値であれば NextInputElementnum 、直前の入力要素が数値でなく / であり、それを正規式として解釈していれば NextInputElementre 、また直前の入力要素が数値でなく / であり、それを除算演算子か除算代入演算子として解釈していれば NextInputElementdiv である。

上記に加え、文字列から数値への変換の構文セマンティクスに使う StringNumericLiteralparseFloat 関数の実装の構文セマンティクスに使う StringDecimalLiteral という開始記号がある。

セマンティクス

tag lineBreak;
tag endOfInput;
tuple Keyword
nameString
end tuple;
tuple Punctuator
nameString
end tuple;
tuple Identifier
nameString
end tuple;
tuple NumberToken
end tuple;
tag negatedMinLong;
tuple StringToken
valueString
end tuple;
tuple RegularExpression
bodyString,
flagsString
end tuple;
TokenKeyword  Punctuator  Identifier  NumberToken  {negatedMinLong StringToken  RegularExpression;
InputElement = {lineBreakendOfInput Token;
tag syntaxError;
tag rangeError;
SemanticException = {syntaxErrorrangeError};

Unicode 文字クラス

構文

UnicodeCharacter  あらゆる Unicode 文字
UnicodeInitialAlphabetic  Unicode 文字データベースでの分類が Lu (uppercase letter)、Ll (lowercase letter)、Lt (titlecase letter)、Lm (modifier letter)、Lo (other letter)、Nl (letter number) のいずれかであるあらゆる文字
UnicodeAlphanumeric  Unicode 文字データベースでの分類が Lu (uppercase letter)、Ll (lowercase letter)、Lt (titlecase letter)、Lm (modifier letter)、Lo (other letter)、Nd (decimal number)、Nl (letter number)、Mn (non-spacing mark)、Mc (combining spacing mark)、Pc (connector punctuation) のいずれかであるあらゆる文字
WhiteSpaceCharacter 
   «TAB» | «VT» | «FF» | «SP» | «u00A0»
|  «u2000» | «u2001» | «u2002» | «u2003» | «u2004» | «u2005» | «u2006» | «u2007»
|  «u2008» | «u2009» | «u200A» | «u200B»
|  «u3000»
LineTerminator  «LF» | «CR» | «u0085» | «u2028» | «u2029»
ASCIIDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

セマンティクス

DecimalValue[ASCIIDigit]: Integer = digitValue(ASCIIDigit);

コメント

構文

LineComment  / / LineCommentCharacters
LineCommentCharacters 
   «empty»
|  LineCommentCharacters NonTerminator
NonTerminator  UnicodeCharacter except LineTerminator
SingleLineBlockComment  / * BlockCommentCharacters * /
BlockCommentCharacters 
   «empty»
|  BlockCommentCharacters NonTerminatorOrSlash
|  PreSlashCharacters /
PreSlashCharacters 
   «empty»
|  BlockCommentCharacters NonTerminatorOrAsteriskOrSlash
|  PreSlashCharacters /
NonTerminatorOrSlash  NonTerminator except /
NonTerminatorOrAsteriskOrSlash  NonTerminator except * | /
MultiLineBlockComment  / * MultiLineBlockCommentCharacters BlockCommentCharacters * /
MultiLineBlockCommentCharacters 
   BlockCommentCharacters LineTerminator
|  MultiLineBlockCommentCharacters BlockCommentCharacters LineTerminator

空白類文字

構文

WhiteSpace 
   «empty»
|  WhiteSpace WhiteSpaceCharacter
|  WhiteSpace SingleLineBlockComment

改行

構文

LineBreak 
   LineTerminator
|  LineComment LineTerminator
|  MultiLineBlockComment
LineBreaks 
   LineBreak
|  LineBreaks WhiteSpace LineBreak

入力要素

構文

  {redivnum}
NextInputElementre  WhiteSpace InputElementre
NextInputElementdiv  WhiteSpace InputElementdiv
NextInputElementnum  [lookahead{ContinuingIdentifierCharacter\}] WhiteSpace InputElementdiv

セマンティクス

Lex[NextInputElement]: InputElement;
Lex[NextInputElementre  WhiteSpace InputElementre] = Lex[InputElementre];
Lex[NextInputElementdiv  WhiteSpace InputElementdiv] = Lex[InputElementdiv];
Lex[NextInputElementnum  [lookahead{ContinuingIdentifierCharacter\}] WhiteSpace InputElementdiv] = Lex[InputElementdiv];

構文

InputElementre 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  NumericLiteral
|  StringLiteral
|  RegExpLiteral
|  EndOfInput
InputElementdiv 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  DivisionPunctuator
|  NumericLiteral
|  StringLiteral
|  EndOfInput
EndOfInput 
   End
|  LineComment End

セマンティクス

Lex[InputElement]: InputElement;
Lex[InputElement  LineBreaks] = lineBreak;
Lex[InputElement  IdentifierOrKeyword] = Lex[IdentifierOrKeyword];
Lex[InputElement  Punctuator] = Lex[Punctuator];
Lex[InputElementdiv  DivisionPunctuator] = Lex[DivisionPunctuator];
Lex[InputElement  NumericLiteral] = Lex[NumericLiteral];
Lex[InputElement  StringLiteral] = Lex[StringLiteral];
Lex[InputElementre  RegExpLiteral] = Lex[RegExpLiteral];
Lex[InputElement  EndOfInput] = endOfInput;

キーワード及び識別子

構文

IdentifierOrKeyword  IdentifierName

セマンティクス

Lex[IdentifierOrKeyword  IdentifierName]: InputElement
begin
idString  Lex[IdentifierName];
if id  {“abstract”, “as”, “break”, “case”, “catch”, “class”, “const”, “continue”, “debugger”, “default”, “delete”, “do”, “else”, “enum”, “export”, “extends”, “false”, “finally”, “for”, “function”, “get”, “goto”, “if”, “implements”, “import”, “in”, “instanceof”, “interface”, “is”, “namespace”, “native”, “new”, “null”, “package”, “private”, “protected”, “public”, “return”, “set”, “super”, “switch”, “synchronized”, “this”, “throw”, “throws”, “transient”, “true”, “try”, “typeof”, “use”, “var”, “volatile”, “while”, “with”} and not ContainsEscapes[IdentifierNamethen
return Keywordnameid
else return Identifiernameid
end if
end;

構文

IdentifierName 
   InitialIdentifierCharacterOrEscape
|  NullEscapes InitialIdentifierCharacterOrEscape
|  IdentifierName ContinuingIdentifierCharacterOrEscape
|  IdentifierName NullEscape
NullEscapes 
   NullEscape
|  NullEscapes NullEscape
NullEscape  \ _
InitialIdentifierCharacterOrEscape 
   InitialIdentifierCharacter
|  \ HexEscape
InitialIdentifierCharacter  UnicodeInitialAlphabetic | $ | _
ContinuingIdentifierCharacterOrEscape 
   ContinuingIdentifierCharacter
|  \ HexEscape
ContinuingIdentifierCharacter  UnicodeAlphanumeric | $ | _

セマンティクス

Lex[IdentifierName]: String;
Lex[IdentifierName0  IdentifierName1 ContinuingIdentifierCharacterOrEscape] = Lex[IdentifierName1 [Lex[ContinuingIdentifierCharacterOrEscape]];
Lex[IdentifierName0  IdentifierName1 NullEscape] = Lex[IdentifierName1];
ContainsEscapes[IdentifierName]: Boolean;
ContainsEscapes[IdentifierName  InitialIdentifierCharacterOrEscape] = ContainsEscapes[InitialIdentifierCharacterOrEscape];
ContainsEscapes[IdentifierName  NullEscapes InitialIdentifierCharacterOrEscape] = true;
ContainsEscapes[IdentifierName0  IdentifierName1 ContinuingIdentifierCharacterOrEscape] = ContainsEscapes[IdentifierName1or ContainsEscapes[ContinuingIdentifierCharacterOrEscape];
ContainsEscapes[IdentifierName  IdentifierName NullEscape] = true;
Lex[InitialIdentifierCharacterOrEscape]: Char16;
Lex[InitialIdentifierCharacterOrEscape  \ HexEscape]
begin
chChar16  Lex[HexEscape];
if the nonterminal InitialIdentifierCharacter can expand into [ch] then
return ch
else throw syntaxError
end if
end;
ContainsEscapes[InitialIdentifierCharacterOrEscape]: Boolean;
ContainsEscapes[InitialIdentifierCharacterOrEscape  InitialIdentifierCharacter] = false;
ContainsEscapes[InitialIdentifierCharacterOrEscape  \ HexEscape] = true;
Lex[ContinuingIdentifierCharacterOrEscape]: Char16;
Lex[ContinuingIdentifierCharacterOrEscape  \ HexEscape]
begin
chChar16  Lex[HexEscape];
if the nonterminal ContinuingIdentifierCharacter can expand into [ch] then
return ch
else throw syntaxError
end if
end;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape]: Boolean;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape  ContinuingIdentifierCharacter] = false;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape  \ HexEscape] = true;

区切り文字

構文

Punctuator 
   !
|  ! =
|  ! = =
|  %
|  % =
|  &
|  & &
|  & & =
|  & =
|  (
|  )
|  *
|  * =
|  +
|  + +
|  + =
|  ,
|  -
|  - -
|  - =
|  .
|  . . .
|  :
|  : :
|  ;
|  <
|  < <
|  < < =
|  < =
|  =
|  = =
|  = = =
|  >
|  > =
|  > >
|  > > =
|  > > >
|  > > > =
|  ?
|  [
|  ]
|  ^
|  ^ =
|  ^ ^
|  ^ ^ =
|  {
|  |
|  | =
|  | |
|  | | =
|  }
|  ~
DivisionPunctuator 
   / [lookahead{/*}]
|  / =

セマンティクス

Lex[Punctuator]: Token;
Lex[Punctuator  !] = Punctuatorname: “!;
Lex[Punctuator  ! =] = Punctuatorname: “!=;
Lex[Punctuator  ! = =] = Punctuatorname: “!==;
Lex[Punctuator  %] = Punctuatorname: “%;
Lex[Punctuator  % =] = Punctuatorname: “%=;
Lex[Punctuator  &] = Punctuatorname: “&;
Lex[Punctuator  & &] = Punctuatorname: “&&;
Lex[Punctuator  & & =] = Punctuatorname: “&&=;
Lex[Punctuator  & =] = Punctuatorname: “&=;
Lex[Punctuator  (] = Punctuatorname: “(;
Lex[Punctuator  )] = Punctuatorname: “);
Lex[Punctuator  *] = Punctuatorname: “*;
Lex[Punctuator  * =] = Punctuatorname: “*=;
Lex[Punctuator  +] = Punctuatorname: “+;
Lex[Punctuator  + +] = Punctuatorname: “++;
Lex[Punctuator  + =] = Punctuatorname: “+=;
Lex[Punctuator  ,] = Punctuatorname: “,;
Lex[Punctuator  -] = Punctuatorname: “-;
Lex[Punctuator  - -] = Punctuatorname: “--;
Lex[Punctuator  - =] = Punctuatorname: “-=;
Lex[Punctuator  .] = Punctuatorname: “.;
Lex[Punctuator  . . .] = Punctuatorname: “...;
Lex[Punctuator  :] = Punctuatorname: “:;
Lex[Punctuator  : :] = Punctuatorname: “::;
Lex[Punctuator  ;] = Punctuatorname: “;;
Lex[Punctuator  <] = Punctuatorname: “<;
Lex[Punctuator  < <] = Punctuatorname: “<<;
Lex[Punctuator  < < =] = Punctuatorname: “<<=;
Lex[Punctuator  < =] = Punctuatorname: “<=;
Lex[Punctuator  =] = Punctuatorname: “=;
Lex[Punctuator  = =] = Punctuatorname: “==;
Lex[Punctuator  = = =] = Punctuatorname: “===;
Lex[Punctuator  >] = Punctuatorname: “>;
Lex[Punctuator  > =] = Punctuatorname: “>=;
Lex[Punctuator  > >] = Punctuatorname: “>>;
Lex[Punctuator  > > =] = Punctuatorname: “>>=;
Lex[Punctuator  > > >] = Punctuatorname: “>>>;
Lex[Punctuator  > > > =] = Punctuatorname: “>>>=;
Lex[Punctuator  ?] = Punctuatorname: “?;
Lex[Punctuator  [] = Punctuatorname: “[;
Lex[Punctuator  ]] = Punctuatorname: “];
Lex[Punctuator  ^] = Punctuatorname: “^;
Lex[Punctuator  ^ =] = Punctuatorname: “^=;
Lex[Punctuator  ^ ^] = Punctuatorname: “^^;
Lex[Punctuator  ^ ^ =] = Punctuatorname: “^^=;
Lex[Punctuator  {] = Punctuatorname: “{;
Lex[Punctuator  |] = Punctuatorname: “|;
Lex[Punctuator  | =] = Punctuatorname: “|=;
Lex[Punctuator  | |] = Punctuatorname: “||;
Lex[Punctuator  | | =] = Punctuatorname: “||=;
Lex[Punctuator  }] = Punctuatorname: “};
Lex[Punctuator  ~] = Punctuatorname: “~;
Lex[DivisionPunctuator]: Token;
Lex[DivisionPunctuator  / [lookahead{/*}]] = Punctuatorname: “/;
Lex[DivisionPunctuator  / =] = Punctuatorname: “/=;

数値リテラル

構文

NumericLiteral 
   DecimalLiteralnoLeadingZeros
|  HexIntegerLiteral
|  DecimalLiteralnoLeadingZeros LetterF
|  IntegerLiteral LetterL
|  IntegerLiteral LetterU LetterL
IntegerLiteral 
   DecimalIntegerLiteralnoLeadingZeros
|  HexIntegerLiteral
LetterF  F | f
LetterL  L | l
LetterU  U | u

セマンティクス

Lex[NumericLiteral]: Token;
Lex[NumericLiteral  DecimalLiteralnoLeadingZeros] = NumberTokenvalue: (Lex[DecimalLiteralnoLeadingZeros])f64;
Lex[NumericLiteral  HexIntegerLiteral] = NumberTokenvalue: (Lex[HexIntegerLiteral])f64;
Lex[NumericLiteral  DecimalLiteralnoLeadingZeros LetterF] = NumberTokenvalue: (Lex[DecimalLiteralnoLeadingZeros])f32;
Lex[NumericLiteral  IntegerLiteral LetterL]
begin
iInteger  Lex[IntegerLiteral];
if i  263 – 1 then return NumberTokenvalueilong
elsif i = 263 then return negatedMinLong
else throw rangeError
end if
end;
Lex[NumericLiteral  IntegerLiteral LetterU LetterL]
begin
iInteger  Lex[IntegerLiteral];
if i  264 – 1 then return NumberTokenvalueiulong
else throw rangeError
end if
end;
Lex[IntegerLiteral]: Integer;
Lex[IntegerLiteral  DecimalIntegerLiteralnoLeadingZeros] = Lex[DecimalIntegerLiteralnoLeadingZeros];
Lex[IntegerLiteral  HexIntegerLiteral] = Lex[HexIntegerLiteral];

構文

  {noLeadingZerosallowLeadingZeros}
DecimalLiteral 
   Mantissa
|  Mantissa LetterE SignedInteger
LetterE  E | e
Mantissa 
   DecimalIntegerLiteral
|  DecimalIntegerLiteral .
|  DecimalIntegerLiteral . Fraction
|  . Fraction
DecimalIntegerLiteralnoLeadingZeros 
   0
|  NonZeroDecimalDigits
DecimalIntegerLiteralallowLeadingZeros  DecimalDigits
NonZeroDecimalDigits 
   NonZeroDigit
|  NonZeroDecimalDigits ASCIIDigit
NonZeroDigit  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Fraction  DecimalDigits

セマンティクス

Lex[DecimalLiteral]: Rational;
Lex[DecimalLiteral  Mantissa] = Lex[Mantissa];
Lex[DecimalLiteral  Mantissa LetterE SignedInteger] = Lex[Mantissa]10Lex[SignedInteger];
Lex[Mantissa]: Rational;
Lex[Mantissa  DecimalIntegerLiteral] = Lex[DecimalIntegerLiteral];
Lex[Mantissa  DecimalIntegerLiteral .] = Lex[DecimalIntegerLiteral];
Lex[Mantissa  DecimalIntegerLiteral . Fraction] = Lex[DecimalIntegerLiteral] + Lex[Fraction];
Lex[Mantissa  . Fraction] = Lex[Fraction];
Lex[DecimalIntegerLiteral]: Integer;
Lex[DecimalIntegerLiteralnoLeadingZeros  0] = 0;
Lex[DecimalIntegerLiteralnoLeadingZeros  NonZeroDecimalDigits] = Lex[NonZeroDecimalDigits];
Lex[DecimalIntegerLiteralallowLeadingZeros  DecimalDigits] = Lex[DecimalDigits];
Lex[NonZeroDecimalDigits]: Integer;
Lex[NonZeroDecimalDigits  NonZeroDigit] = DecimalValue[NonZeroDigit];
Lex[NonZeroDecimalDigits0  NonZeroDecimalDigits1 ASCIIDigit] = 10Lex[NonZeroDecimalDigits1] + DecimalValue[ASCIIDigit];
DecimalValue[NonZeroDigit]: Integer = digitValue(NonZeroDigit);
Lex[Fraction  DecimalDigits]: Rational = Lex[DecimalDigits]/10NDigits[DecimalDigits];

構文

SignedInteger  OptionalSign DecimalDigits
OptionalSign 
   «empty»
|  +
|  -

セマンティクス

Lex[SignedInteger  OptionalSign DecimalDigits]: IntegerLex[OptionalSign]Lex[DecimalDigits];
Lex[OptionalSign]: {–1, 1};
Lex[OptionalSign  «empty»] = 1;
Lex[OptionalSign  +] = 1;
Lex[OptionalSign  -] = –1;

構文

DecimalDigits 
   ASCIIDigit
|  DecimalDigits ASCIIDigit

セマンティクス

Lex[DecimalDigits]: Integer;
Lex[DecimalDigits  ASCIIDigit] = DecimalValue[ASCIIDigit];
Lex[DecimalDigits0  DecimalDigits1 ASCIIDigit] = 10Lex[DecimalDigits1] + DecimalValue[ASCIIDigit];
NDigits[DecimalDigits]: Integer;
NDigits[DecimalDigits  ASCIIDigit] = 1;
NDigits[DecimalDigits0  DecimalDigits1 ASCIIDigit] = NDigits[DecimalDigits1] + 1;

構文

HexIntegerLiteral 
   0 LetterX HexDigit
|  HexIntegerLiteral HexDigit
LetterX  X | x
HexDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | a | b | c | d | e | f

セマンティクス

Lex[HexIntegerLiteral]: Integer;
Lex[HexIntegerLiteral  0 LetterX HexDigit] = HexValue[HexDigit];
Lex[HexIntegerLiteral0  HexIntegerLiteral1 HexDigit] = 16Lex[HexIntegerLiteral1] + HexValue[HexDigit];
HexValue[HexDigit]: Integer = digitValue(HexDigit);

文字列リテラル

構文

  {singledouble}
StringLiteral 
   ' StringCharssingle '
|  " StringCharsdouble "

セマンティクス

Lex[StringLiteral]: Token;
Lex[StringLiteral  ' StringCharssingle '] = StringTokenvalueLex[StringCharssingle];
Lex[StringLiteral  " StringCharsdouble "] = StringTokenvalueLex[StringCharsdouble];

構文

StringChars 
   «empty»
|  StringChars StringChar
|  StringChars NullEscape
StringChar 
   LiteralStringChar
|  \ StringEscape
LiteralStringCharsingle  UnicodeCharacter except ' | \ | LineTerminator
LiteralStringChardouble  UnicodeCharacter except " | \ | LineTerminator

セマンティクス

Lex[StringChars]: String;
Lex[StringChars  «empty»] = “”;
Lex[StringChars0  StringChars1 StringChar] = Lex[StringChars1 [Lex[StringChar]];
Lex[StringChars0  StringChars1 NullEscape] = Lex[StringChars1];
Lex[StringChar]: Char16;
Lex[StringChar  LiteralStringChar] = LiteralStringChar;
Lex[StringChar  \ StringEscape] = Lex[StringEscape];

構文

StringEscape 
   ControlEscape
|  ZeroEscape
|  HexEscape
|  IdentityEscape
IdentityEscape  NonTerminator except _ | UnicodeAlphanumeric

セマンティクス

Lex[StringEscape]: Char16;
Lex[StringEscape  ControlEscape] = Lex[ControlEscape];
Lex[StringEscape  ZeroEscape] = Lex[ZeroEscape];
Lex[StringEscape  HexEscape] = Lex[HexEscape];
Lex[StringEscape  IdentityEscape] = IdentityEscape;

構文

ControlEscape 
   b
|  f
|  n
|  r
|  t
|  v

セマンティクス

Lex[ControlEscape]: Char16;
Lex[ControlEscape  b] = ‘«BS»’;
Lex[ControlEscape  f] = ‘«FF»’;
Lex[ControlEscape  n] = ‘«LF»’;
Lex[ControlEscape  r] = ‘«CR»’;
Lex[ControlEscape  t] = ‘«TAB»’;
Lex[ControlEscape  v] = ‘«VT»’;

構文

ZeroEscape  0 [lookahead{ASCIIDigit}]

セマンティクス

Lex[ZeroEscape  0 [lookahead{ASCIIDigit}]]: Char16 = ‘«NUL»’;

構文

HexEscape 
   x HexDigit HexDigit
|  u HexDigit HexDigit HexDigit HexDigit
|  U HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit

セマンティクス

Lex[HexEscape]: Char16;
Lex[HexEscape  x HexDigit1 HexDigit2] = integerToChar16(16HexValue[HexDigit1] + HexValue[HexDigit2]);
Lex[HexEscape  u HexDigit1 HexDigit2 HexDigit3 HexDigit4] = integerToChar16(4096HexValue[HexDigit1] + 256HexValue[HexDigit2] + 16HexValue[HexDigit3] + HexValue[HexDigit4]);
Lex[HexEscape  U HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit] = ????;

[訳注: 最後の部分の “????” は編集上のミスではない。現時点でセマンティクスの実装は終了しておらず、未確定という意味である]

正規表現リテラル

構文

RegExpLiteral  RegExpBody RegExpFlags
RegExpFlags 
   «empty»
|  RegExpFlags ContinuingIdentifierCharacterOrEscape
|  RegExpFlags NullEscape
RegExpBody  / [lookahead{*}] RegExpChars /
RegExpChars 
   RegExpChar
|  RegExpChars RegExpChar
RegExpChar 
   OrdinaryRegExpChar
|  \ NonTerminator
OrdinaryRegExpChar  NonTerminator except \ | /

セマンティクス

Lex[RegExpLiteral  RegExpBody RegExpFlags]: TokenRegularExpressionbodyLex[RegExpBody], flagsLex[RegExpFlags];
Lex[RegExpFlags]: String;
Lex[RegExpFlags  «empty»] = “”;
Lex[RegExpFlags0  RegExpFlags1 ContinuingIdentifierCharacterOrEscape] = Lex[RegExpFlags1 [Lex[ContinuingIdentifierCharacterOrEscape]];
Lex[RegExpFlags0  RegExpFlags1 NullEscape] = Lex[RegExpFlags1];
Lex[RegExpBody  / [lookahead{*}] RegExpChars /]: String = Lex[RegExpChars];
Lex[RegExpChars]: String;
Lex[RegExpChars  RegExpChar] = Lex[RegExpChar];
Lex[RegExpChars0  RegExpChars1 RegExpChar] = Lex[RegExpChars1 Lex[RegExpChar];
Lex[RegExpChar]: String;
Lex[RegExpChar  OrdinaryRegExpChar] = [OrdinaryRegExpChar];
Lex[RegExpChar  \ NonTerminator] = [\’, NonTerminator];

文字列から数値への変換

構文

StringNumericLiteral 
   StringWhiteSpace
|  StringWhiteSpace SignedDecimalLiteral StringWhiteSpace
|  StringWhiteSpace OptionalSign HexIntegerLiteral StringWhiteSpace
SignedDecimalLiteral 
   OptionalSign DecimalLiteralallowLeadingZeros
|  OptionalSign I n f i n i t y
|  N a N
StringWhiteSpace 
   «empty»
|  StringWhiteSpace WhiteSpaceOrLineTerminatorChar
WhiteSpaceOrLineTerminatorChar  WhiteSpaceCharacter | LineTerminator

セマンティクス

tag +zero;
tag –zero;
tag +;
tag ;
tag NaN;
ExtendedRational = Rational  {+zero–zero+NaN};
Lex[StringNumericLiteral]: ExtendedRational;
Lex[StringNumericLiteral  StringWhiteSpace] = +zero;
Lex[SignedDecimalLiteral]: ExtendedRational;
Lex[SignedDecimalLiteral  OptionalSign DecimalLiteralallowLeadingZeros] = combineWithSign(Lex[OptionalSign], Lex[DecimalLiteralallowLeadingZeros]);
Lex[SignedDecimalLiteral  OptionalSign I n f i n i t y] = Lex[OptionalSign] > 0 ? + : ;
Lex[SignedDecimalLiteral  N a N] = NaN;
proc combineWithSign(sign: {–1, 1}, qRational): ExtendedRational
if q  0 then return signq
elsif sign > 0 then return +zero
else return –zero
end if
end proc;

parseFloat 変換

構文

StringDecimalLiteral  StringWhiteSpace SignedDecimalLiteral

セマンティクス

Lex[StringDecimalLiteral  StringWhiteSpace SignedDecimalLiteral]: ExtendedRationalLex[SignedDecimalLiteral];

Waldemar Horwat
最終更新: 2003年6月30日 (月)
previousupnext