RPA Toolkit
work on RJS. Fixed inlined rules compilation(ref shadowing).
authorMartin Stoilov <martin@rpasearch.com>
Wed, 27 Apr 2011 03:29:40 +0000 (20:29 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Wed, 27 Apr 2011 03:29:40 +0000 (20:29 -0700)
rjs/build/linux/rjs.mk
rjs/ecma262.rpa
rjs/ecma262org.rpa [new file with mode: 0644]
rjs/rjscompiler.c [new file with mode: 0644]
rjs/rjscompiler.h [new file with mode: 0644]
rpa2/rpacompiler.c
rpa2/rpacompiler.h
rpa2/rpadbex.c
rpa2/rpaparser.c
rpa2/rpaparser.h
rpa2/rpavm.c

index b04b0b4..240bcc0 100644 (file)
@@ -17,6 +17,7 @@ LIBS += -lrjs -lrpa2 -lrvm -lrlib -lpthread -lm --static
 RJS_OBJECTS =  \
        $(OUTDIR)/rjs.o \
        $(OUTDIR)/rjsparser.o \
+       $(OUTDIR)/rjscompiler.o \
        $(OUTDIR)/rjsrules.o \
        $(OUTDIR)/ecma262.o \
 
index 680dd15..5a70849 100644 (file)
@@ -4,7 +4,6 @@
 #!emit BitwiseXOROp
 #!emit BitwiseOROp
 #!emit AdditiveExpressionOp
-
 #!emit MultiplicativeExpressionOp
 #!emit ShiftExpressionOp
 #!emit EqualityExpressionOp
 #!emit LogicalOROperator
 #!emit LogicalNotOperator
 #!emit BitwiseNotOperator
-#!emit UnaryOperatorOpcode
-#!emit PrintOp
-
+#!emit UnaryOperator
 
+#!emit PrefixOperator
 #!emit PostfixOperator
 #!emit PostfixExpressionOp
 #!emit PrefixExpressionOp
 
-
 #!emit UnaryExpressionOp
 #!emit LogicalNotExpressionOp
 #!emit BitwiseNotExpressionOp
 #!emit Program
 #!emit Initialiser
 #!emit AssignmentExpressionOp
-
-#!emit VariableAllocate
-#!emit VariableAllocateAndInit
-
-#!emit ReturnOp
-
-#!emit SwiId
-#!emit SwiIdExist
-
-#!emit PostfixExpressionValOp
-#!emit LeftHandSideExpressionPush
-
+#!emit LeftHandSideExpression
+#!emit Expression
+#!emit MemberExpressionIndexOp
+#!emit MemberExpressionDotOp
+#!emit MemberExpressionBase
+#!emit IdentifierName
+#!emit Identifier
+#!emit CallExpression
 
 #!uid Program 1
 #!uid PostfixExpressionValOp 2
@@ -85,34 +78,34 @@ COMMA                                       ::= <S>? ',' <S>?
 EQ                                             ::= <S>? '=' <S>?
 
 # 7.4 Comments
-Comment                                        ::= <:MultiLineComment:> | <:SingleLineComment:>
-MultiLineComment               ::= '/*' <:MultiLineCommentChar:>* '*/'
+Comment                                        ::= <MultiLineComment> | <SingleLineComment>
+MultiLineComment               ::= '/*' <MultiLineCommentChar>* '*/'
 MultiLineCommentChar   ::= . - '*/'
-SingleLineComment              ::= '#' <:SingleLineCommentChar:>*
+SingleLineComment              ::= '#' <SingleLineCommentChar>*
 SingleLineCommentChar  ::= <SourceCharacter> - <LineTerminator>
 
 # 7.5 Tokens
-Token                                  ::= <:IdentifierName:> |
-                                               <:NumericLiteral:> |
-                                               <:StringLiteral:>
+Token                                  ::= <IdentifierName> |
+                                               <NumericLiteral> |
+                                               <StringLiteral>
 
 # 7.6 Identifier Names and Identifiers
 
-Identifier                             ::= <IdentifierName> - <ReservedWord> - <ReservedWord> <IdentifierPart>
+Identifier                             ::= <IdentifierName> - (<ReservedWord> - <ReservedWord> <IdentifierPart>)
 IdentifierName                 ::= <IdentifierStart> <IdentifierPart>*
-IdentifierStart                        ::= <UnicodeLetter> | '$' | '_' | '\' <:UnicodeLetter:>
+IdentifierStart                        ::= <UnicodeLetter> | '$' | '_' | '\' <UnicodeLetter>
 UnicodeLetter                  ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232] | [#0x0061-#0x007A] | [#0x00C0-#0x00DE]       # <Lu> | <Ll>
 
 Lu                                             ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232]   # TBD
 Ll                                             ::= [#0x0061-#0x007A] | [#0x00C0-#0x00DE]                                               # TBD
 IdentifierPart                 ::= <IdentifierStart> | 
-                                               <:UnicodeDigit:> 
+                                               <UnicodeDigit> 
 UnicodeDigit                   ::= [0-9] | [#0x0660-#0x0669]                                   # TBD
 
-ReservedWord                   ::= <:Keyword:>
-                                                       <:FutureReservedWord:> |
-                                                       <:NullLiteral:> |
-                                                       <:BooleanLiteral:>
+ReservedWord                   ::= <Keyword>
+                                                       <FutureReservedWord> |
+                                                       <NullLiteral> |
+                                                       <BooleanLiteral>
 
 Keyword                                        ::= 'instanceof' | 'typeof'     | 'break' |
                                                'do' | 'new' | 'var' |
@@ -128,342 +121,303 @@ FutureReservedWord                      ::= 'class' | 'enum' | 'extends' | 'import' | 'const' | 'ex
 
 NullLiteral                                    ::= 'null'
 BooleanLiteral                                 ::= 'true' | 'false'
-Literal                                        ::= <:NullLiteral:> |
-                                                       <:BooleanLiteral:> |
-                                                       <:NumericLiteral:> |
-                                                       <:StringLiteral:>
+Literal                                        ::= <NullLiteral> |
+                                                       <BooleanLiteral> |
+                                                       <NumericLiteral> |
+                                                       <StringLiteral>
                                                        
-LiteralOp                                      ::= <:Literal:>
+LiteralOp                                      ::= <Literal>
 
 # 7.8.3 Numeric Literals
 
-NumericLiteral                                 ::= <:HexIntegerLiteral:> | <:DecimalNonIntegerLiteral:> | <:DecimalIntegerLiteral:>
-DecimalNonIntegerLiteral               ::= ('0' | <:NonZeroDigit:> <DecimalDigits>?) '.' <DecimalDigits>? <:ExponentPart:>? |
-                                                               '.' <:DecimalDigits:> <:ExponentPart:>? 
-DecimalIntegerLiteral                  ::= '0' | <:NonZeroDigit:> <:DecimalDigits:>? <:ExponentPart:>?
-DecimalDigits                                  ::= <:DecimalDigit:>+
+NumericLiteral                                 ::= <HexIntegerLiteral> | <DecimalNonIntegerLiteral> | <DecimalIntegerLiteral>
+DecimalNonIntegerLiteral               ::= ('0' | <NonZeroDigit> <DecimalDigits>?) '.' <DecimalDigits>? <ExponentPart>? |
+                                                               '.' <DecimalDigits> <ExponentPart>? 
+DecimalIntegerLiteral                  ::= '0' | <NonZeroDigit> <DecimalDigits>? <ExponentPart>?
+DecimalDigits                                  ::= <DecimalDigit>+
 DecimalDigit                                   ::= [0-9]
 NonZeroDigit                                   ::= [1-9]
-ExponentPart                                   ::= <:ExponentIndicator:> <:SignedInteger:>
+ExponentPart                                   ::= <ExponentIndicator> <SignedInteger>
 ExponentIndicator                              ::= [eE]
-SignedInteger                                  ::= '-' <:DecimalDigits:> |
-                                                               '+' <:DecimalDigits:> |
-                                                               <:DecimalDigits:>
-HexIntegerLiteral                              ::= '0' [xX] <:HexDigit:>+
+SignedInteger                                  ::= '-' <DecimalDigits> |
+                                                               '+' <DecimalDigits> |
+                                                               <DecimalDigits>
+HexIntegerLiteral                              ::= '0' [xX] <HexDigit>+
 HexDigit                                               ::= [0-9a-fA-F]
 
 # 7.8.4 String Literals
-StringLiteral                                  ::= '"' <:DoubleStringCharacters:>? '"' |
-                                                               "'" <:SingleStringCharacters:>? "'"
+StringLiteral                                  ::= '"' <DoubleStringCharacters>? '"' |
+                                                               "'" <SingleStringCharacters>? "'"
 
 DoubleStringCharacters                 ::= <DoubleStringCharacter>+
 SingleStringCharacters                 ::= <SingleStringCharacter>+
 
-DoubleStringCharacter                  ::= <:SourceCharacter:> - ('"' | '\\' | <:LineTerminator:>)
+DoubleStringCharacter                  ::= <SourceCharacter> - ('"' | '\\' | <LineTerminator>)
 
-SingleStringCharacter                  ::= <:SourceCharacter:> - ("'" | '\\' | <:LineTerminator:>)
+SingleStringCharacter                  ::= <SourceCharacter> - ("'" | '\\' | <LineTerminator>)
+This                                                   ::= 'this'
 
-BracketExpressionOp                            ::= '(' <S>? <:Expression:> <S>? ')'
-ThisOp                                                 ::= 'this'
+PrimaryExpression                              ::= <This> | 
+                                                               '(' <S>? <Expression> <S>? ')' |
+                                                               <Literal> |
+                                                               <Identifier>
 
-PrimaryExpression                              ::= <:ThisOp:> | 
-                                                               '(' <S>? <:Expression:> <S>? ')' |
-                                                               <:LiteralOp:> |
-                                                               (<:SwiId:>) |
-                                                               <:IdentifierOp:>
 
-# The next line is mine
-IdentifierOp                                   ::= <:Identifier:> 
-SwiId                                                  ::= <:Identifier:> 
-SwiIdExist                                             ::= <SwiId> 
 
 
-ArrayLiteral                                   ::= '[' <S>? <:Elision:>? <S>? ']' |
-                                                               '[' <S>? <:ElementList:> <S>? ']' |
-                                                               '[' <S>? <:ElementList:> <S>? ',' <S>? <:Elision:> <S>? ']'
-ElementList                                            ::= <:Elision:>? <S>? <:AssignmentExpression:> (<S>? ',' <S>? <:Elision:>? <S>? <:AssignmentExpression:> )*
-Elision                                                        ::= ',' <S>? <:Elision:> | <S>? ','
+ArrayLiteral                                   ::= '[' <S>? <Elision>? <S>? ']' |
+                                                               '[' <S>? <ElementList> <S>? ']' |
+                                                               '[' <S>? <ElementList> <S>? ',' <S>? <Elision> <S>? ']'
+ElementList                                            ::= <Elision>? <S>? <AssignmentExpression> (<S>? ',' <S>? <Elision>? <S>? <AssignmentExpression> )*
+Elision                                                        ::= ',' <S>? <Elision> | <S>? ','
 
 
 # 11.2 Left-Hand-Side Expressions
-NewKeyword                                             ::= 'new' - 'new' <IdentifierPart>
 LSB                                                            ::= <S>? '[' <S>?
 RSB                                                            ::= <S>? ']' <S>?
-dot                                                            ::= '.'
-MemberIdentifierNameOp                 ::= <:Identifier:>
-MemberIdentifierNameLookupOp   ::= <:Identifier:>
-MemberExpressionBaseOp                 ::= <:MemberExpression:>
-MemberExpressionIndexOp                        ::= <:MemberExpressionBaseOp:>  <:LSB:> <:Expression:> <:RSB:>
-MemberExpressionNameOp                 ::= <:MemberExpressionBaseOp:> <:dot:> <:MemberIdentifierNameOp:>
-MemberExpressionNewOp                  ::= <:NewKeyword:> <S>? <:CallExpression:>
-
-MemberExpression                               ::= <:MemberExpressionIndexOp:>  |
-                                                                       <:MemberExpressionNameOp:> |
-                                                                       <:FunctionExpression:> |
-                                                                       <:PrimaryExpression:>
-
-NewExpressionCallName                  ::= <:MemberExpression:>
-NewExpressionCallOp                            ::= <:NewKeyword:> <S>? <:NewExpressionCallName:> <S>? <:ArgumentsOp:>?
-NewArrayExpressionOp                   ::= <S>? 'new' <S> ( 'Array' | 'Object') <S>? <ArgumentsOp>?
-
-NewExpression                                  ::= <:NewArrayExpressionOp:> |
-                                                                       <:NewExpressionCallOp:> |
-                                                                       <:MemberExpression:>
-
-FunctionCallName                               ::= <:CallExpression:> | <:MemberExpression:>
-CallExpressionOp                               ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
-CallExpressionBaseOp                   ::= <:CallExpression:>
-CallExpressionIndexOp                  ::= <:CallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
-CallExpressionNameOp                   ::= <:CallExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
-
-CallExpression                                 ::= <:CallExpressionIndexOp:> |
-                                                                       <:CallExpressionNameOp:> |
-                                                                       <:CallExpressionOp:>
-
-ArgumentsOp                                            ::= '(' <S>? ')' |
-                                                               '(' <S>? <:ArgumentList:> <S>? ')'
-ArgumentList                                   ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
-                                                                       <:AssignmentExpression:>
-
-ArgumentList                                   ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
-                                                                       <:FunctionCallParameter:>
-FunctionCallParameter                  ::= <:AssignmentExpression:>
+MemberExpressionBase                   ::= <MemberExpression>
+MemberExpressionIndexOp                        ::= <MemberExpressionBase> <LSB> <Expression> <RSB>
+MemberExpressionDotOp                  ::= <MemberExpressionBase> '.' <IdentifierName>
+
+MemberExpression                               ::= <MemberExpressionIndexOp>  |
+                                                                       <MemberExpressionDotOp> |
+                                                                       <FunctionExpression> |
+                                                                       <PrimaryExpression>
+                                                                       
                                                                        
-ValLeftHandSideExpression              ::= <:CallExpression:> | <:NewExpression:>
-AddressLeftHandSideExpression  ::= <:ValLeftHandSideExpression:>
-LeftHandSideExpression                 ::= <:AddressLeftHandSideExpression:>
+NewKeyword                                             ::= 'new' - 'new' <IdentifierPart>
+NewExpression                                  ::= <NewKeyword> <S>? <NewExpression> |
+                                                                       <MemberExpression>
+
+
+CallExpression                                 ::= <CallExpression> <Arguments> |
+                                                                       <CallExpression> <S>? '[' <S>? Expression <S>? ']' |
+                                                                       <CallExpression> '.' <IdentifierName> |
+                                                                       <MemberExpression> <S>? <Arguments>
+
+Arguments                                              ::= '(' <S>? ')' |
+                                                               '(' <S>? <ArgumentList> <S>? ')'
+ArgumentList                                   ::= <ArgumentList> <S>? ',' <S>? <AssignmentExpression> |
+                                                                       <AssignmentExpression>
+LeftHandSideExpression                 ::= <CallExpression> | <NewExpression>
 
 
 # 11.3 Postfix Expressions
 # RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
 PostfixOperator                                ::= '++' | '--'
-PostfixExpressionOp                    ::= <:LeftHandSideExpression:> <:PostfixOperator:>
-PostfixExpressionValOp                 ::= <:ValLeftHandSideExpression:>
-PostfixExpression                              ::= <:PostfixExpressionOp:> |
-                                                                       <:PostfixExpressionValOp:> 
+PostfixExpressionOp                    ::= <LeftHandSideExpression> <PostfixOperator>
+PostfixExpression                              ::= <PostfixExpressionOp> | <LeftHandSideExpression> 
 
-PrefixOperator                                         ::= <:PostfixOperator:>
-PrefixExpressionOp                             ::= <:PrefixOperator:> <:LeftHandSideExpression:>
-PrefixExpression                               ::= <:PrefixExpressionOp:>
+PrefixOperator                                         ::= '++' | '--'
+PrefixExpression                               ::= <PrefixOperator> <LeftHandSideExpression>
 
 # 11.4 Unary Operators
-UnaryOperatorOpcode                            ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
-UnaryOperator                          ::= <:UnaryOperatorOpcode:>
-UnaryExpressionOp                      ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
-UnaryExpression                                ::=     <:UnaryExpressionOp:> | <:PrefixExpression:> | <:PostfixExpression:>
+UnaryOperator                                  ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
+UnaryExpressionOp                      ::=     <S>? <UnaryOperator> <S>? <UnaryExpression>
+UnaryExpression                                ::=     <UnaryExpressionOp> | <PrefixExpression> | <PostfixExpression>
 
 
 # 11.5 Multiplicative Operators
 MultiplicativeOperator                         ::= '*' | '/' | '%'
-MultiplicativeExpressionOp             ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
-MultiplicativeExpression               ::= <:MultiplicativeExpressionOp:> | 
-                                                                       <:UnaryExpression:>
+MultiplicativeExpressionOp             ::= <MultiplicativeExpression> <S>? <MultiplicativeOperator> <S>? <UnaryExpression>
+MultiplicativeExpression               ::= <MultiplicativeExpressionOp> | 
+                                                                       <UnaryExpression>
 
 # 11.6 Additive Operators
 AdditiveOperator                               ::= '+' | '-'
-AdditiveExpressionOp                   ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
-AdditiveExpression                             ::= <:AdditiveExpressionOp:> | 
-                                                                       <:MultiplicativeExpression:>
+AdditiveExpressionOp                   ::= <AdditiveExpression> <S>? <AdditiveOperator> <S>? <MultiplicativeExpression>
+AdditiveExpression                             ::= <AdditiveExpressionOp> | 
+                                                                       <MultiplicativeExpression>
 
 
 11.7 Bitwise Shift Operators
 ShiftOperator                                  ::= '>>>' | '<<' | '>>'
-ShiftExpressionOp                              ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
-ShiftExpression                                        ::= <:ShiftExpressionOp:> |
-                                                               <:AdditiveExpression:> 
+ShiftExpressionOp                              ::= <ShiftExpression> <S>? <ShiftOperator> <S>? <AdditiveExpression>
+ShiftExpression                                        ::= <ShiftExpressionOp> |
+                                                               <AdditiveExpression> 
 
 
 # 11.8 Relational Operators
 RelationalOperator                             ::= '<=' | '>=' | '<' | '>' | 'instanceof'
-RelationalExpressionOp                 ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
-RelationalExpression                   ::= <:RelationalExpressionOp:> |
-                                                               <:ShiftExpression:>
+RelationalExpressionOp                 ::= <RelationalExpression> <S>? <RelationalOperator> <S>? <ShiftExpression>
+RelationalExpression                   ::= <RelationalExpressionOp> |
+                                                               <ShiftExpression>
 
 # 11.9 Equality Operators
 EqualityOperator                               ::= '===' | '==' | '!==' | '!='
-EqualityExpressionOp                   ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
-EqualityExpression                             ::= <:EqualityExpressionOp:> |
-                                                               <:RelationalExpression:>
+EqualityExpressionOp                   ::= <EqualityExpression> <S>? <EqualityOperator> <S>? <RelationalExpression> 
+EqualityExpression                             ::= <EqualityExpressionOp> |
+                                                               <RelationalExpression>
 
 BitwiseANDOperator                             ::= '&' - '&&'
-BitwiseANDOp                                   ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
-BitwiseANDExpression                   ::= <:BitwiseANDOp:> |
-                                                               <:EqualityExpression:>
+BitwiseANDOp                                   ::= <BitwiseANDExpression> <S>? <BitwiseANDOperator> <S>? <EqualityExpression>
+BitwiseANDExpression                   ::= <BitwiseANDOp> |
+                                                               <EqualityExpression>
 
 BitwiseXOROperator                             ::= '^'
-BitwiseXOROp                                   ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
-BitwiseXORExpression                   ::= <:BitwiseXOROp:> |
-                                                               <:BitwiseANDExpression:>
+BitwiseXOROp                                   ::= <BitwiseXORExpression> <S>? <BitwiseXOROperator> <S>? <BitwiseANDExpression>
+BitwiseXORExpression                   ::= <BitwiseXOROp> |
+                                                               <BitwiseANDExpression>
 
 BitwiseOROperator                              ::= '|' - '||'
-BitwiseOROp                                            ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
-BitwiseORExpression                    ::= <:BitwiseOROp:> |
-                                                               <:BitwiseXORExpression:>
+BitwiseOROp                                            ::= <BitwiseORExpression> <S>? <BitwiseOROperator> <S>? <BitwiseXORExpression>
+BitwiseORExpression                    ::= <BitwiseOROp> |
+                                                               <BitwiseXORExpression>
 
 # 11.11 Binary Logical Operators
 LogicalANDOperator                             ::= '&&'
-LogicalANDOp                                   ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
-LogicalANDExpression                   ::= <:LogicalANDOp:> |
-                                                               <:BitwiseORExpression:>
+LogicalANDOp                                   ::= <LogicalANDExpression> <S>? <LogicalANDOperator>  <S>? <BitwiseORExpression>
+LogicalANDExpression                   ::= <LogicalANDOp> |
+                                                               <BitwiseORExpression>
 
 LogicalOROperator                              ::= '||'
-LogicalOROp                                            ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
-LogicalORExpression                    ::= <:LogicalOROp:> |
-                                                               <:LogicalANDExpression:>
+LogicalOROp                                            ::= <LogicalORExpression> <S>? <LogicalOROperator> <S>? <LogicalANDExpression>
+LogicalORExpression                    ::= <LogicalOROp> |
+                                                               <LogicalANDExpression>
 
 
 # 11.12 Conditional Operator ( ? : )
-AssignmentExpressionIfTrueOp           ::= <:AssignmentExpression:>
-AssignmentExpressionIfFalseOp          ::= <:AssignmentExpression:>
-QuestionMarkOp                                         ::= '?'
-ConditionalExpression                          ::= <:LogicalORExpression:> (<S>? <:QuestionMarkOp:> <S>? <:AssignmentExpressionIfTrueOp:> <S>? ':' <S>? <:AssignmentExpressionIfFalseOp:>)?
+ConditionalExpression                  ::= <LogicalORExpression> ( <S>? '?' <S>? <AssignmentExpression> <S>? ':' <S>? <AssignmentExpression> )?
 
 # 11.13 Assignment Operators
-LeftHandSideExpressionPush             ::= <:LeftHandSideExpression:>
-IdentifierAddressPush                  ::= <:Identifier:>
-AssignmentExpressionOp                         ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
-AssignmentExpression                   ::= <:AssignmentExpressionOp:> | 
-                                                                       <:ConditionalExpression:>
-
-AssignmentExpressionNoIn               ::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:>
-AssignmentOperator                             ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
+AssignmentExpression                   ::= <LeftHandSideExpression> <S>? <AssignmentOperator> <S>? <AssignmentExpression> | <ConditionalExpression>
+AssignmentOperator                             ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
 
 
 # 11.14 Comma Operator         ( , )
-Expression                                     ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
-ExpressionNoIn                                 ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
+Expression                                     ::= <AssignmentExpression> ( <S>? ',' <S>? <AssignmentExpression> )*
 
 
 # 12 Statements
-Statement                                              ::= <:FunctionDefinitionStatement:> |
-                                                                       <:BreakStatement:> |
-                                                                       <:ContinueStatement:> |
-                                                                       <:Block:> |
-                                                               <:Comment:> |
-                                                               <:VariableStatement:> |
-                                                               <:EmptyStatement:> |
-                                                               <:ExpressionStatement:> |
-                                                               <:IfStatement:> |
-                                                               <:IterationStatement:> |
-                                                               <:ContinueStatement:> |
-                                                               <:BreakStatement:> |
-                                                               <:ReturnStatement:> |
-                                                               <:WithStatement:> |
-                                                               <:SwitchStatementOp:>
+Statement                                              ::= <FunctionDefinitionStatement> |
+                                                                       <BreakStatement> |
+                                                                       <ContinueStatement> |
+                                                                       <Block> |
+                                                               <Comment> |
+                                                               <VariableStatement> |
+                                                               <EmptyStatement> |
+                                                               <ExpressionStatement> |
+                                                               <IfStatement> |
+                                                               <IterationStatement> |
+                                                               <ContinueStatement> |
+                                                               <BreakStatement> |
+                                                               <ReturnStatement> |
+                                                               <WithStatement> |
+                                                               <SwitchStatementOp>
 
 # 12.1 Block
 BlockBegin                                                     ::= <S>? '{' <S>?
 BlockEnd                                                       ::= <S>? '}' <S>?
-Block                                                          ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
-StatementList                                          ::= (<S>? <:Statement:>)+
+Block                                                          ::= <BlockBegin> <StatementList>? <BlockEnd>
+StatementList                                          ::= (<S>? <Statement>)+
 
 # 12.2 Variable Statement
-VariableStatement                                      ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
-VariableDeclarationList                        ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
-VariableAllocate                                       ::= <:Identifier:>
-VariableAllocateAndInit                                ::= <:Identifier:>
-VariableDeclaration                                    ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
-Initialiser                                                    ::= <:EQ:> <:AssignmentExpression:>
+VariableStatement                                      ::= 'var' <S>? <VariableDeclarationList> <SC>
+VariableDeclarationList                        ::= <VariableDeclaration> (<COMMA> <VariableDeclaration> )*
+VariableAllocate                                       ::= <Identifier>
+VariableAllocateAndInit                                ::= <Identifier>
+VariableDeclaration                                    ::= <VariableAllocateAndInit> <Initialiser> | <VariableAllocate>
+Initialiser                                                    ::= <EQ> <AssignmentExpression>
 
 
 # 12.3 Empty Statement
-EmptyStatement                                         ::= <:SC:>
+EmptyStatement                                         ::= <SC>
 
 # 12.4 Expression Statement
-ExpressionStatement                            ::= (<:Expression:> - ('function' | '{')) <:SC:>
+ExpressionStatement                            ::= (<Expression> - ('function' | '{')) <SC>
 
 
 # 12.5 The if Statement
 
 ElseOp                                                         ::= 'else'
-IfConditionOp                                          ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
-IfOp                                                           ::= <:IfConditionOp:> <S>? <:Statement:>
-IfElseOp                                                       ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
+IfConditionOp                                          ::= 'if' <S>? '(' <S>? <Expression> <S>? ')'
+IfOp                                                           ::= <IfConditionOp> <S>? <Statement>
+IfElseOp                                                       ::= <IfConditionOp> <S>? <Statement> <S>? <ElseOp> <S>? <Statement>
 
-IfStatement                                                    ::= <:IfElseOp:> |
-                                                                               <:IfOp:>
+IfStatement                                                    ::= <IfElseOp> |
+                                                                               <IfOp>
 
 # 12.6 Iteration Statements
 # 12.6a Iteration do ... while() 
 WhileKeyword                                           ::= 'while'
-WhileExpression                                                ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
+WhileExpression                                                ::= <WhileKeyword> <S>? '(' <S>? <Expression> <S>? ')'
 DoKeyword                                                      ::= 'do'
-IterationDo                                                    ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
+IterationDo                                                    ::= <DoKeyword> <S>? <Statement> <S>? <WhileExpression> (<S>? ';')
 
 # 12.6b Iteration while()
-WhileConditionOp                                       ::= 'while' <S>? '(' <S>? <:Expression:> <S>? ')'
-IterationWhileOp                                       ::= <:WhileConditionOp:> <S>? <:Statement:>
+WhileConditionOp                                       ::= 'while' <S>? '(' <S>? <Expression> <S>? ')'
+IterationWhileOp                                       ::= <WhileConditionOp> <S>? <Statement>
 
 # 12.6c Iteration for ( ; ; )
 ForKeyword                                                     ::= 'for'
-ExpressionNoIn                                         ::= <:Expression:>
-ForExpressionInitOp                                    ::= ('var' <S>? <:VariableDeclarationList:>) | <:ExpressionNoIn:>
-ForExpressionCompareOp                         ::= <:Expression:>
-ForExpressionIncrementOp                       ::= <:Expression:>
+ExpressionNoIn                                         ::= <Expression>
+ForExpressionInitOp                                    ::= ('var' <S>? <VariableDeclarationList>) | <ExpressionNoIn>
+ForExpressionCompareOp                         ::= <Expression>
+ForExpressionIncrementOp                       ::= <Expression>
 
 # The following & expression is done in order to swap the places of the code generated for the comparison and increment.
 # This is done by selectively turning on/off callbacks in both statement so that the final result appears as if the
-# <:ForExpressionCompareOp:> <:ForExpressionIncrementOp:> appear in the opposite order.
-ForIterationStatementOp                                ::= <:ForKeyword:> <S>? '(' <S>? <:ForExpressionInitOp:>? <S>? ';' <S>? <ForExpressionCompareOp>? <S>? ';' <S>? <:ForExpressionIncrementOp:>? <S>? ')'
-IterationForOp                                         ::= <:ForIterationStatementOp:> <S>? <:Statement:>
+# <ForExpressionCompareOp> <ForExpressionIncrementOp> appear in the opposite order.
+ForIterationStatementOp                                ::= <ForKeyword> <S>? '(' <S>? <ForExpressionInitOp>? <S>? ';' <S>? <ForExpressionCompareOp>? <S>? ';' <S>? <ForExpressionIncrementOp>? <S>? ')'
+IterationForOp                                         ::= <ForIterationStatementOp> <S>? <Statement>
 
 
-IterationStatement                                     ::= <:IterationWhileOp:> |
-                                                                               <:IterationForOp:> |
-                                                                       <:IterationDo:>
+IterationStatement                                     ::= <IterationWhileOp> |
+                                                                               <IterationForOp> |
+                                                                       <IterationDo>
 
 # 12.9 The return Statement
-ReturnOp                                                       ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
-ReturnStatement                                                ::= <:ReturnOp:>
+ReturnOp                                                       ::= ('return' - 'return' <IdentifierPart>) <WhiteSpace>* <AssignmentExpression>? (<S>? ';')
+ReturnStatement                                                ::= <ReturnOp>
 
 # The Break Statement
-BreakOp                                                                ::= 'break' - 'break' <:IdentifierPart:>
-BreakStatement                                         ::= <S>? <:BreakOp:> <:SC:>
+BreakOp                                                                ::= 'break' - 'break' <IdentifierPart>
+BreakStatement                                         ::= <S>? <BreakOp> <SC>
 
 # The Continue Statement
-ContinueOp                                                     ::= 'continue' - 'continue' <:IdentifierPart:>
-ContinueStatement                                      ::= <S>? <:ContinueOp:> <:SC:>
+ContinueOp                                                     ::= 'continue' - 'continue' <IdentifierPart>
+ContinueStatement                                      ::= <S>? <ContinueOp> <SC>
 
 
 
 # 12.10 The with Statement
-WithStatement                                          ::= 'with' <S>? '(' <S>? <:Expression:> <S>? ')' <S>? <:Statement:>
+WithStatement                                          ::= 'with' <S>? '(' <S>? <Expression> <S>? ')' <S>? <Statement>
 
 
 # 12.11 The switch Statement
-SwitchExpressionOp                                     ::= ('switch' - 'switch' <IdentifierPart>) <S>? '(' <S>? <:Expression:> <S>? ')'
-SwitchStatementOp                                      ::= <:SwitchExpressionOp:> <S>? <:CaseBlock:>
+SwitchExpressionOp                                     ::= ('switch' - 'switch' <IdentifierPart>) <S>? '(' <S>? <Expression> <S>? ')'
+SwitchStatementOp                                      ::= <SwitchExpressionOp> <S>? <CaseBlock>
 
-CaseBlock                                                      ::= '{' <S>? <:CaseClauses:>? <S>? <:DefaultClauseOp:>? <S>? <:CaseClauses:>? <S>? '}' |
-                                                                       '{' <S>? <:CaseClauses:>? <S>? '}'
+CaseBlock                                                      ::= '{' <S>? <CaseClauses>? <S>? <DefaultClauseOp>? <S>? <CaseClauses>? <S>? '}' |
+                                                                       '{' <S>? <CaseClauses>? <S>? '}'
 
 
 
-CaseClauses                                            ::= (<S>? <:CaseClauseOp:>)+
-CaseExpressionOp                                       ::= ('case' - 'case' <IdentifierPart>) <S>? <:Expression:> <S>? ':'
-CaseClauseOp                                           ::= <:CaseExpressionOp:> <S>? <:StatementList:>?
+CaseClauses                                            ::= (<S>? <CaseClauseOp>)+
+CaseExpressionOp                                       ::= ('case' - 'case' <IdentifierPart>) <S>? <Expression> <S>? ':'
+CaseClauseOp                                           ::= <CaseExpressionOp> <S>? <StatementList>?
 DefaultKeywordOp                                       ::= 'default' - 'default' <IdentifierPart>
-DefaultClauseOp                                                ::= <:DefaultKeywordOp:> <S>? ':' <S>? <:StatementList:>?
+DefaultClauseOp                                                ::= <DefaultKeywordOp> <S>? ':' <S>? <StatementList>?
 
 
 # 13 Function Definition
-FunctionName                                           ::= <:Identifier:>
-FunctionNameLookupAlloc                                ::= <:Identifier:>
-FunctionDefinition                                     ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
-FunctionDeclaration                                    ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
-FunctionExpression                                     ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
-FunctionParameter                                      ::= <:Identifier:>
-FormalParameterList                            ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
-FunctionDefinitionStatement                    ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionNameLookupAlloc:><S>?'('<S>?<FormalParameterList>?<S>?')' <:SC:>
-FunctionBody                                           ::= <:SourceElements:>
+FunctionName                                           ::= <Identifier>
+FunctionNameLookupAlloc                                ::= <Identifier>
+FunctionDefinition                                     ::= ('function' - 'function' <IdentifierPart>)<S>?<FunctionName><S>?'('<S>?<FormalParameterList>?<S>?')'
+FunctionDeclaration                                    ::= <FunctionDefinition><S>?'{'<S>?<FunctionBody>?<S>?'}'
+FunctionExpression                                     ::= ('function' - 'function'<IdentifierPart>)<S>?<FunctionName>?<S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
+FunctionParameter                                      ::= <Identifier>
+FormalParameterList                            ::= <FunctionParameter> ( <S>? ',' <S>? <FunctionParameter> )*
+FunctionDefinitionStatement                    ::= ('function' - 'function' <IdentifierPart>)<S>?<FunctionNameLookupAlloc><S>?'('<S>?<FormalParameterList>?<S>?')' <SC>
+FunctionBody                                           ::= <SourceElements>
 
 
 # 14 Program
-SourceElements                                         ::= (<S>? <:SourceElement:>)+
-SourceElement                                          ::= <:FunctionDeclaration:> |
-                                                                       <:Statement:>
-Program                                                        ::= <:SourceElements:>
+SourceElements                                         ::= (<S>? <SourceElement>)+
+SourceElement                                          ::= <FunctionDeclaration> |
+                                                                       <Statement>
+Program                                                        ::= <SourceElements>
 # The root rule, it is anonymous
-<:Program:>
+<Expression>
        
 
diff --git a/rjs/ecma262org.rpa b/rjs/ecma262org.rpa
new file mode 100644 (file)
index 0000000..64cdaa5
--- /dev/null
@@ -0,0 +1,443 @@
+# 6 Source Text
+SourceCharacter                ::= .
+
+# 7.2 White space
+WhiteSpace             ::= [#0x0009] | [#0x000B] | [#0x000C] | [#0x0020] | [#0x00A0] | [#0xFEFF]
+
+# 7.3 Line Terminators
+LineTerminator         ::= [#0x000D] [#0x000A] | [#0x000A] | [#0x000D] | [#0x2028] | [#0x2029]
+LineTerminatorSequence ::= [#0x000D] [#0x000A] |
+                           [#0x000A] | 
+                           [#0x000D] | 
+                           [#0x2028] | 
+                           [#0x2029]
+
+S                      ::= ( <WhiteSpace> | <LineTerminator> )+
+
+# 7.4 Comments
+Comment                        ::= <MultiLineComment> | <SingleLineComment>
+MultiLineComment       ::= '/*' <MultiLineCommentChar>* '*/'
+MultiLineCommentChar   ::= . - '*/'
+SingleLineComment      ::= '//' <SingleLineCommentChar>*
+SingleLineCommentChar  ::= <SourceCharacter> - <LineTerminator>
+
+
+# 7.5 Tokens
+Token                  ::= <IdentifierName> |
+                           <Punctuator> |
+                           <NumericLiteral> |
+                           <StringLiteral>
+
+# 7.6 Identifier Names and Identifiers
+
+Identifier             ::= <IdentifierName> - <ReservedWord> - <ReservedWord> <IdentifierPart>
+IdentifierName         ::= <IdentifierStart> <IdentifierPart>*
+IdentifierStart                ::= <UnicodeLetter> | '$' | '_' | '\' <UnicodeEscapeSequence>
+UnicodeLetter          ::= <Lu> |
+                       <Ll> |
+                       <Lt> |
+                       <Lm> |
+                       <Lo> |
+                       <Nl>
+
+Lu                     ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232]   # TBD
+Ll                     ::= [#0x0061-#0x007A] | [#0x00C0-#0x00DE]                       # TBD
+IdentifierPart         ::= <IdentifierStart> | 
+                       <UnicodeCombiningMark> |
+                       <UnicodeDigit> | 
+                       <UnicodeConnectorPunctuation>                                   # TBD
+
+UnicodeDigit           ::= [0-9] | [#0x0660-#0x0669]                                   # TBD
+ReservedWord           ::= <Keyword>
+                       <Keyword> | 
+                       <FutureReservedWord> |
+                       <NullLiteral> |
+                       <BooleanLiteral>
+
+Keyword                        ::= 'instanceof' | 'typeof'     | 'break' | 
+                           'do' | 'new' | 'var' |
+                           'case' | 'else' | 'return' | 'void' | 
+                           'catch' | 'finally' | 'continue' | 'for' | 
+                           'switch' | 'while' | 'this' | 'with' | 
+                           'debugger' | 'function' | 'throw' | 'default' |  
+                           'if' | 'try' | 'delete' | 'in'
+
+FutureReservedWord     ::= 'class' | 'enum' | 'extends' | 'import' | 'const' | 'export' |
+                           'implements' | 'let' | 'private' | 'public' |
+                            'static' | 'interface' | 'package' | 'protected'
+
+NullLiteral            ::= 'null'
+BooleanLiteral                 ::= 'true' | 'false'
+Literal                ::= <NullLiteral> |
+                           <BooleanLiteral> |
+                           <NumericLiteral> |
+                           <StringLiteral> |
+                           <RegularExpressionLiteral>
+
+
+
+# 7.7 Punctuators
+Punctuator             ::= '{' | '}' | '(' | ')' | '[' | ']' |
+                            '===' | '!==' | '>=' | '<=' | '==' | '!=' |
+                           '<<' | '>>>' | '>>' | '&' | '^=' | '^' |
+                           '!' | '~' | '&&' | '||' | '?' | ':' |
+                           '>>=' | '>>>=' | '&=' | '|=' |
+                           '=' | '+='| '-=' | '*=' | '%=' | '<<=' |
+                           '.' | ';' | ',' | '<' | '>' | '|' |
+                           '+' | '-' | '*' | '%' | '++' | '--'
+DivPunctuator          ::= '/' | '/='
+
+
+
+# 7.8.3 Numeric Literals
+NumericLiteral         ::= <HexIntegerLiteral> | <DecimalLiteral>
+DecimalLiteral         ::= <DecimalIntegerLiteral> '.' <DecimalDigits>? <ExponentPart>? |
+                           '.' <DecimalDigits> <ExponentPart>? |
+                           <DecimalIntegerLiteral> <ExponentPart>?
+
+DecimalIntegerLiteral  ::= '0' |
+                           <NonZeroDigit> <DecimalDigits>?
+
+DecimalDigits          ::= <DecimalDigit>+
+DecimalDigit           ::= [0-9]
+NonZeroDigit           ::= [1-9]
+ExponentPart           ::= <ExponentIndicator> <SignedInteger>
+ExponentIndicator      ::= [eE]
+SignedInteger          ::= <DecimalDigits> |
+                           '+' <DecimalDigits> |
+                           '-' <DecimalDigits>
+HexIntegerLiteral      ::= '0' [xX] <HexDigit>+
+HexDigit               ::= [0-9a-fA-F]
+
+
+# 7.8.4 String Literals
+
+StringLiteral          ::= '"' <DoubleStringCharacters>? '"' |
+                           "'" <SingleStringCharacters>? "'"
+
+DoubleStringCharacters ::= <DoubleStringCharacter>+
+SingleStringCharacters ::= <SingleStringCharacter>+
+
+
+DoubleStringCharacter  ::= '\' <EscapeSequence> |
+                           <LineContinuation> |
+                           <SourceCharacter> - ('"' | '\' | <LineTerminator>)
+
+SingleStringCharacter  ::= '\' <EscapeSequence> |
+                           <LineContinuation> |
+                           <SourceCharacter> - ("'" | '\' | <LineTerminator>)
+
+LineContinuation       ::= '\' <LineTerminatorSequence>
+
+
+EscapeSequence                 ::= <CharacterEscapeSequence> |
+                                   '0' ^<DecimalDigit> |
+                           <HexEscapeSequence> |
+                           <UnicodeEscapeSequence>
+
+CharacterEscapeSequence ::= <SingleEscapeCharacter> |
+                           <NonEscapeCharacter>
+
+SingleEscapeCharacter  ::= "'" | '"' | '\' | [bfnrtv]
+NonEscapeCharacter     ::= <SourceCharacter> - (<EscapeCharacter> | <LineTerminator>)
+EscapeCharacter        ::= <SingleEscapeCharacter> |
+                           <DecimalDigit> |
+                           'x' |
+                           'u'
+
+HexEscapeSequence      ::= 'x' <HexDigit> <HexDigit>
+UnicodeEscapeSequence  ::= 'u' <HexDigit> <HexDigit> <HexDigit> <HexDigit>
+
+
+# 7.8.5 Regular Expression Literals
+RegularExpressionLiteral::= '/' <RegularExpressionBody> '/' <RegularExpressionFlags>
+RegularExpressionBody  ::= <RegularExpressionFirstChar> <RegularExpressionChars>?
+RegularExpressionChars ::= <RegularExpressionChar>+
+RegularExpressionFirstChar ::= <RegularExpressionNonTerminator> - ( '*' | '\' | '/' | '[' ) |
+                              <RegularExpressionBackslashSequence> |
+                              <RegularExpressionClass>
+
+RegularExpressionChar  ::= <RegularExpressionNonTerminator> - ( '\' | '/' | '[') |
+                           <RegularExpressionBackslashSequence> |
+                           <RegularExpressionClass>
+
+
+RegularExpressionBackslashSequence ::= '\' <RegularExpressionNonTerminator>
+RegularExpressionNonTerminator    ::= <SourceCharacter> - <LineTerminator>
+RegularExpressionClass                    ::= '[' <RegularExpressionClassChars> ']'
+RegularExpressionClassChars       ::= <RegularExpressionClassChar>+
+RegularExpressionClassChar        ::= <RegularExpressionNonTerminator> - ( ']' | '\' ) |
+                                      <RegularExpressionBackslashSequence>
+
+RegularExpressionFlags            ::= <IdentifierPart> <RegularExpressionFlags> | <IdentifierPart>
+
+# 11.1 Primary Expressions
+
+PrimaryExpression      ::= <Identifier> |
+                           <Literal> |
+                           <ArrayLiteral> |
+                           <ObjectLiteral> |
+                           '(' <S>? <Expression> <S>? ')' |
+                           'this'
+
+ArrayLiteral           ::= '[' <S>? <Elision>? <S>? ']' |
+                           '[' <S>? <ElementList> <S>? ']' |
+                           '[' <S>? <ElementList> <S>? ',' <S>? <Elision> <S>? ']'
+
+
+ElementList            ::= <Elision>? <S>? <AssignmentExpression> (<S>? ',' <S>? <Elision>? <S>? <AssignmentExpression> )*
+Elision                        ::= ',' <S>? <Elision> | <S>? ','
+ObjectLiteral          ::= '{' <S>? '}' |
+                           '{' <S>? <PropertyNameAndValueList>  <S>? '}' |
+                           '{' <S>? <PropertyNameAndValueList>  <S>? ','  <S>? '}'
+
+PropertyNameAndValueList::= <PropertyAssignment> ( <S>? ','  <S>? <PropertyAssignment>)*
+
+PropertyAssignment     ::= <PropertyName>  <S>? ':'  <S>? <AssignmentExpression> |
+                           'get'  <S>? <PropertyName>  <S>? '(' <S>? ')'  <S>? '{' <S>? <FunctionBody>?  <S>? '}' |
+                           'set'  <S>? <PropertyName>  <S>? '(' <S>? <PropertySetParameterList>  <S>? ')' <S>? '{' <S>? <FunctionBody>?  <S>? '}'
+
+
+PropertyName           ::= <IdentifierName> |
+                                               <StringLiteral> |
+                                               <NumericLiteral>
+
+PropertySetParameterList::= <Identifier>
+
+
+# 11.2 Left-Hand-Side Expressions
+MemberExpression                               ::= <MemberExpression> <S>? '[' <S>? <Expression> <S>? ']' |
+                                                                       <MemberExpression> '.' <IdentifierName> |
+                                                                       'new' <S> <MemberExpression> <S>? <Arguments> |
+                                                                       <FunctionExpression> |
+                                                                       <PrimaryExpression>
+
+NewExpression                                  ::= <NewKeyword> <S>? <NewExpression> |
+                                                                       <MemberExpression>
+
+
+CallExpression                                 ::= <CallExpression> <Arguments> |
+                                                                       <CallExpression> <S>? '[' <S>? Expression <S>? ']' |
+                                                                       <CallExpression> '.' <IdentifierName> |
+                                                                       <MemberExpression> <S>? <Arguments>
+
+Arguments                                              ::= '(' <S>? ')' |
+                                                               '(' <S>? <ArgumentList> <S>? ')'
+ArgumentList                                   ::= <ArgumentList> <S>? ',' <S>? <AssignmentExpression> |
+                                                                       <AssignmentExpression>
+LeftHandSideExpression                 ::= <CallExpression> | <NewExpression>
+       
+# 11.3 Postfix Expressions
+PostfixOperator        ::= '++' | '--'
+PostfixExpression      ::= <LeftHandSideExpression> <PostfixOperator>?
+
+# 11.4 Unary Operators
+UnaryOperator              ::= 'delete' | 'void' | 'typeof' | '++' | '--' | '+' | '-' | '~' | '!'
+UnaryExpression                    ::= <S>? <UnaryOperator> <S>? <UnaryExpression> | <PostfixExpression>
+
+
+# 11.5 Multiplicative Operators
+MultiplicativeOperator         ::= '*' | '/' | '%'
+MultiplicativeExpression::= <MultiplicativeExpression> <S>? <MultiplicativeOperator> <S>? <UnaryExpression> |
+                           <UnaryExpression>
+
+
+# 11.6 Additive Operators
+AdditiveOperator       ::= '+' | '-'
+AdditiveExpression     ::= <AdditiveExpression> <S>? <AdditiveOperator> <S>? <MultiplicativeExpression> |
+                           <MultiplicativeExpression>
+
+11.7 Bitwise Shift Operators
+ShiftOperator          ::= '>>>' | '<<' | '>>'
+ShiftExpression                ::= <ShiftExpression> <S>? <ShiftOperator> <S>? <AdditiveExpression> |
+                           <AdditiveExpression>
+
+# 11.8 Relational Operators
+RelationalOperatorNoIn         ::= '<=' | '>=' | '<' | '>' | 'instanceof'
+RelationalOperator     ::= <RelationalOperatorNoIn> | 'in'
+RelationalExpression   ::= <RelationalExpression> <S>? <RelationalOperator> <S>? <ShiftExpression> |
+                           <ShiftExpression>
+RelationalExpressionNoIn::= <RelationalExpressionNoIn> <S>? <RelationalOperatorNoIn> <S>? <ShiftExpression> |
+                           <ShiftExpression>
+
+
+# 11.9 Equality Operators
+EqualityOperator       ::= '===' | '==' | '!==' | '!='
+EqualityExpression     ::= <EqualityExpression> <S>? <EqualityOperator> <S>? <RelationalExpression> |
+                           <RelationalExpression>
+EqualityExpressionNoIn         ::= <EqualityExpression> <S>? <EqualityOperator> <S>? <RelationalExpressionNoIn> |
+                           <RelationalExpressionNoIn>
+
+# 11.10 Binary Bitwise Operators
+BitwiseANDExpression   ::= <BitwiseANDExpression> <S>? <BitwiseANDOperator> <S>? <EqualityExpression> |
+                           <EqualityExpression>
+BitwiseANDExpressionNoIn::= <BitwiseANDExpressionNoIn> <S>? <BitwiseANDOperator> <S>? <EqualityExpressionNoIn> |
+                           <EqualityExpressionNoIn>
+BitwiseANDOperator     ::= '&'
+
+
+BitwiseXORExpression   ::= <BitwiseXORExpression> <S>? <BitwiseXOROperator> <S>? <BitwiseANDExpression> |
+                           <BitwiseANDExpression>
+BitwiseXORExpressionNoIn::= <BitwiseXORExpressionNoIn> <S>? <BitwiseXOROperator> <S>? <BitwiseANDExpressionNoIn> |
+                           <BitwiseANDExpressionNoIn>
+BitwiseXOROperator     ::= '^'
+
+BitwiseORExpression    ::= <BitwiseORExpression> <S>? <BitwiseOROperator> <S>? <BitwiseXORExpression> |
+                           <BitwiseXORExpression>
+BitwiseORExpressionNoIn::= <BitwiseORExpressionNoIn> <S>? <BitwiseOROperator> <S>? <BitwiseXORExpressionNoIn> |
+                          <BitwiseXORExpressionNoIn>
+BitwiseOROperator      ::= '|'
+
+
+
+# 11.11 Binary Logical Operators
+LogicalANDExpression   ::= <LogicalANDExpression> <S>? <LogicalANDOperator>  <S>? <BitwiseORExpression> |
+                           <BitwiseORExpression>
+LogicalANDExpressionNoIn::= <LogicalANDExpressionNoIn> <S>? <LogicalANDOperator>  <S>? <BitwiseORExpressionNoIn> |
+                           <BitwiseORExpressionNoIn>
+LogicalANDOperator     ::= '&&'
+
+LogicalORExpression    ::= <LogicalORExpression> <S>? <LogicalOROperator> <S>? <LogicalANDExpression> |
+                           <LogicalANDExpression>
+LogicalORExpressionNoIn ::= <LogicalORExpressionNoIn> <S>? <LogicalOROperator> <S>? <LogicalANDExpressionNoIn> |
+                           <LogicalANDExpressionNoIn> 
+LogicalOROperator      ::= '||'
+
+# 11.12 Conditional Operator ( ? : )
+ConditionalExpression  ::= <LogicalORExpression> ( <S>? '?' <S>? <AssignmentExpression> <S>? ':' <S>? <AssignmentExpression> )?
+ConditionalExpressionNoIn::=<LogicalORExpressionNoIn> ( <S>? '?' <S>? <AssignmentExpression> <S>? ':' <S>? <AssignmentExpressionNoIn> )?
+
+# 11.13 Assignment Operators
+AssignmentExpression   ::= <LeftHandSideExpression> <S>? <AssignmentOperator> <S>? <AssignmentExpression> | <ConditionalExpression>
+AssignmentExpressionNoIn::= <LeftHandSideExpression> <S>? <AssignmentOperator> <S>? <AssignmentExpressionNoIn> | <ConditionalExpressionNoIn>
+AssignmentOperator     ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
+
+
+# 11.14 Comma Operator         ( , )
+Expression             ::= <AssignmentExpression> ( <S>? ',' <S>? <AssignmentExpression> )*
+ExpressionNoIn         ::= <AssignmentExpressionNoIn> ( <S>? ',' <S>? <AssignmentExpressionNoIn> )*
+
+
+# 12 Statements
+
+Statement              ::= <Block> |
+                           <Comment> |
+                           <VariableStatement> |
+                           <EmptyStatement> |
+                           <ExpressionStatement> |
+                           <IfStatement> |
+                           <IterationStatement> |
+                           <ContinueStatement> |
+                           <BreakStatement> |
+                           <ReturnStatement> |
+                           <ImportStatement> |
+                           <WithStatement> |
+                           <LabelledStatement> |
+                           <SwitchStatement> |
+                           <ThrowStatement> |
+                           <TryStatement> |
+                           <DebuggerStatement>
+
+# 12.1 Block
+Block                  ::= '{' <S>? <StatementList>? <S>? '}'
+StatementList          ::= (<S>? <Statement>)+
+
+# 12.2 Variable Statement
+VariableStatement      ::= 'var' <S>? <VariableDeclarationList> (<S>? ';')
+VariableDeclarationList ::= <VariableDeclaration> (<S>? ',' <S>? <VariableDeclaration> )*
+VariableDeclarationListNoIn::= <VariableDeclarationNoIn> (<S>? ',' <S>? <VariableDeclarationNoIn> )*
+VariableDeclaration    ::= <Identifier> <Initialiser>?
+VariableDeclarationNoIn ::= <Identifier> <InitialiserNoIn>?
+Initialiser            ::= <S>? '=' <S>? <AssignmentExpression>
+InitialiserNoIn        ::= <S>? '=' <S>? <AssignmentExpressionNoIn>
+
+# 12.3 Empty Statement
+EmptyStatement         ::= <S>? ';'
+
+
+# 12.4 Expression Statement
+ExpressionStatement    ::= (<Expression> - ('function' | '{')) (<S>? ';')
+
+12.5 The if Statement
+IfStatement            ::= 'if' <S>? '(' <S>? <Expression> <S>? ')'<S>? <Statement> <S>? 'else' <S>? <Statement> |
+                           'if' <S>? '(' <S>? <Expression> <S>? ')'<S>? <Statement> 
+
+
+
+
+# 12.6 Iteration Statements
+IterationStatement     ::= 'do' <S>? <Statement> <S>? 'while' <S>? '(' <S>? <Expression> <S>? ')' (<S>? ';') |
+           'while' <S>? '(' <S>? <Expression> <S>? ')' <S>? <Statement> |
+           'for' <S>? '(' <S>?'var' <S>? <VariableDeclarationListNoIn> <S>? ';' <S>? <Expression>? <S>? ';'<S>? <Expression>? <S>? ')' <S>? <Statement> |
+           'for' <S>? '(' <S>?'var' <S>? <VariableDeclarationNoIn> <S>? 'in' <S>? <Expression> <S>? ')' <S>?  <Statement> |
+           'for' <S>? '(' <S>? <LeftHandSideExpression> <S>? 'in' <S>? <Expression> <S>? ')' <S>?  <Statement> |
+           'for' <S>? '(' <S>? <ExpressionNoIn>? <S>? ';' <S>? <Expression>? <S>? ';' <S>? <Expression>? <S>? ')' <S>? <Statement>
+
+
+# 12.7 The continue Statement
+ContinueStatement      ::= ('continue' - 'continue' <IdentifierPart>) <WhiteSpace>* <Identifier>? (<S>? ';')
+
+
+# 12.8 The break Statement
+BreakStatement         ::= ('break' - 'break' <IdentifierPart>)<WhiteSpace>* <Identifier>? (<S>? ';')
+
+
+# 12.9 The return Statement
+ReturnStatement                ::= ('return' - 'return' <IdentifierPart>) <WhiteSpace>* <Expression>? (<S>? ';')
+
+
+# 12.10 The with Statement
+WithStatement          ::= 'with' <S>? '(' <S>? <Expression> <S>? ')' <S>? <Statement>
+
+
+# 12.11 The switch Statement
+SwitchStatement                ::= 'switch' <S>? '(' <S>? <Expression> <S>? ')' <S>? <CaseBlock>
+
+CaseBlock              ::= '{' <S>? <CaseClauses>? <S>? <DefaultClause> <S>? <CaseClauses>? <S>? '}' |
+                           '{' <S>? <CaseClauses>? <S>? '}'
+
+
+
+CaseClauses            ::= (<S>? <CaseClause>)+
+
+CaseClause             ::= 'case' <S>? <Expression> <S>? ':' <S>? <StatementList>?
+DefaultClause          ::= 'default' <S>? ':' <S>? <StatementList>
+
+# 12.12 Labelled Statements
+LabelledStatement      ::= <Identifier> <S>? ':' <S>? <Statement>
+
+# 12.13 The throw Statement
+ThrowStatement         ::= ('throw' - 'throw' <IdentifierPart>) <WhiteSpace>* <Expression> (<S>? ';')
+
+12.14 The try Statement
+TryStatement           ::= 'try' <S>? <Block> <S>? <Catch> <S>? <Finally> |
+                           'try' <S>? <Block> <S>? <Catch> |
+                           'try' <S>? <Block> <S>? <Finally>
+
+
+Catch                  ::= 'catch' <S>? '(' <Identifier> ')' <S>? <Block>
+Finally                ::= 'finally' <S>? <Block>
+
+# 12.15 The debugger statement
+DebuggerStatement      ::= 'debugger' <S>? ';'
+
+
+# 13 Function Definition
+FunctionDeclaration    ::= ('function'-'function'<IdentifierPart>)<S>?<Identifier><S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
+FunctionExpression     ::= ('function'-'function'<IdentifierPart>)<S>?<Identifier>?<S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
+FormalParameterList    ::= <Identifier> ( <S>? ',' <S>? <Identifier> )*
+FunctionBody           ::= <SourceElements>
+
+
+# Other
+ImportStatement        ::= 'import' <Name> ( '.' '*' )? (<S>? ';')
+Name                   ::= <IdentifierName> ( '.' <IdentifierName> )*
+
+
+# 14 Program
+SourceElements                 ::= (<S>? <SourceElement>)+
+SourceElement          ::= <FunctionDeclaration> |
+                           <Statement>
+Program                        ::= <SourceElements>?
+
+<Program>
diff --git a/rjs/rjscompiler.c b/rjs/rjscompiler.c
new file mode 100644 (file)
index 0000000..7442b5c
--- /dev/null
@@ -0,0 +1,20 @@
+#include "rmem.h"
+#include "rjscompiler.h"
+
+
+rjs_compiler_t *rjs_compiler_create()
+{
+       rjs_compiler_t *co = (rjs_compiler_t *) r_zmalloc(sizeof(*co));
+
+       co->cg = rvm_codegen_create();
+       return co;
+}
+
+
+void rjs_compiler_destroy(rjs_compiler_t *co)
+{
+       if (co) {
+               rvm_codegen_destroy(co->cg);
+               r_free(co);
+       }
+}
diff --git a/rjs/rjscompiler.h b/rjs/rjscompiler.h
new file mode 100644 (file)
index 0000000..d806337
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef _RJSCOMPILER_H_
+#define _RJSCOMPILER_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "rtypes.h"
+#include "rarray.h"
+#include "rvmcodegen.h"
+
+
+typedef struct rjs_compiler_s {
+       rvm_codegen_t *cg;
+} rjs_compiler_t;
+
+
+rjs_compiler_t *rjs_compiler_create();
+void rjs_compiler_destroy(rjs_compiler_t *parser);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 71833c7..2172a3f 100644 (file)
@@ -2,7 +2,6 @@
 #include "rpacompiler.h"
 #include "rstring.h"
 
-#define OPTIMIZE_MNODE_NAN 1
 
 static rlong rpa_codegen_add_numlabel_s(rvm_codegen_t *cg, const rchar *alphaname, rlong numname)
 {
@@ -440,7 +439,7 @@ rint rpa_compiler_inlinerule_begin(rpa_compiler_t *co, const rchar *name, ruint
        r_memset(&exp, 0, sizeof(exp));
        exp.branch = rvm_codegen_addins(co->cg, rvm_asm(RVM_B, DA, XX, XX, 0));
        exp.start = rvm_codegen_getcodesize(co->cg);
-       exp.startidx = rvm_codegen_addlabel(co->cg, name, namesize);
+       exp.startidx = rpa_codegen_add_numlabel_s(co->cg, "__inlined", exp.start);
        exp.endidx = rpa_codegen_invalid_add_numlabel_s(co->cg, "__end", exp.start);
        exp.dataidx = rpa_compiler_addblob(co, exp.start, ruleuid, ruleflags, name, namesize);
 
index b024ef4..fce0813 100644 (file)
@@ -44,7 +44,6 @@ typedef struct rpa_compiler_s {
        rvm_codegen_t *cg;
        rharray_t *ruleprefs;
        rarray_t *expressions;
-       rboolean optimized;
        rvm_scope_t *scope;
        rulong fpoff;
        rpair_t currange;
index 67a864f..20e05df 100644 (file)
@@ -95,6 +95,51 @@ static rlong rpa_dbex_getmatchspecialchr(rulong matchtype)
 }
 
 
+static rint rpa_record2long(rparecord_t *prec, ruint32 *num)
+{
+       rchar *endptr = NULL;
+       rchar buffer[64];
+
+       if (prec->inputsiz == 0 || prec->inputsiz >= sizeof(buffer))
+               return -1;
+       r_memset(buffer, 0, sizeof(buffer));
+       r_memcpy(buffer, prec->input, prec->inputsiz);
+       if (prec->ruleuid == RPA_PRODUCTION_HEX) {
+               *num = (ruint32)r_strtoul(prec->input, &endptr, 16);
+       } else if (prec->ruleuid == RPA_PRODUCTION_DEC) {
+               *num = (ruint32)r_strtoul(prec->input, &endptr, 10);
+       } else {
+               return -1;
+       }
+       return 0;
+}
+
+
+static rint rpa_dbex_rh_uid(rpadbex_t *dbex, rlong rec)
+{
+       const rchar *name = NULL;
+       rsize_t namesize;
+       ruint32 uid = 0;
+       rparecord_t *pnumrec;
+       rparecord_t *prec = (rparecord_t *) r_array_slot(dbex->records, rec);
+
+       if (prec->type & RPA_RECORD_START) {
+               if (rpa_dbex_rulename(dbex, rec, &name, &namesize) < 0) {
+                       return -1;
+               }
+               pnumrec = rpa_dbex_record(dbex, rpa_recordtree_lastchild(dbex->records, rec, RPA_RECORD_END));
+               if (!pnumrec)
+                       return -1;
+               if (rpa_record2long(pnumrec, &uid) < 0)
+                       return -1;
+               rpa_compiler_rulepref_set_ruleuid(dbex->co, name, namesize, uid);
+       } else if (prec->type & RPA_RECORD_END) {
+
+       }
+       return 0;
+}
+
+
 static rint rpa_dbex_rh_emit(rpadbex_t *dbex, rlong rec)
 {
        const rchar *name = NULL;
@@ -188,7 +233,6 @@ static rint rpa_dbex_rh_namedrule(rpadbex_t *dbex, rlong rec)
 
                        return -1;
                }
-
                if (!r_array_empty(dbex->inlinestack)) {
                        rpa_compiler_inlinerule_begin(dbex->co, name, namesize, 0);
                } else {
@@ -395,26 +439,6 @@ static rint rpa_dbex_rh_range(rpadbex_t *dbex, rlong rec)
 }
 
 
-static rint rpa_record2long(rparecord_t *prec, ruint32 *num)
-{
-       rchar *endptr = NULL;
-       rchar buffer[64];
-
-       if (prec->inputsiz == 0 || prec->inputsiz >= sizeof(buffer))
-               return -1;
-       r_memset(buffer, 0, sizeof(buffer));
-       r_memcpy(buffer, prec->input, prec->inputsiz);
-       if (prec->ruleuid == RPA_PRODUCTION_HEX) {
-               *num = (ruint32)r_strtoul(prec->input, &endptr, 16);
-       } else if (prec->ruleuid == RPA_PRODUCTION_DEC) {
-               *num = (ruint32)r_strtoul(prec->input, &endptr, 10);
-       } else {
-               return -1;
-       }
-       return 0;
-}
-
-
 static rint rpa_dbex_rh_numrange(rpadbex_t *dbex, rlong rec)
 {
        rparecord_t *prec = (rparecord_t *) rpa_dbex_record(dbex, rec);
@@ -541,6 +565,8 @@ static void rpa_dbex_rh_loopref(rpadbex_t *dbex, rparecord_t *prec)
        rvm_codegen_addins(dbex->co->cg, rvm_asm(RVM_MOVS, R0, R_LOO, XX, 0));
        rvm_codegen_index_addrelocins(dbex->co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(dbex->co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
        rpa_compiler_exp_end(dbex->co);
+//     rvm_codegen_index_addrelocins(dbex->co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(dbex->co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+
 }
 
 
@@ -559,6 +585,11 @@ static rint rpa_dbex_rh_aref(rpadbex_t *dbex, rlong rec)
 
                if ((prec->usertype & RPA_LOOP_PATH) && rpa_parseinfo_loopdetect(dbex, rec, rpa_dbex_firstinlined(dbex))) {
                        info = (rpa_ruleinfo_t *) r_harray_get(dbex->rules, rpa_dbex_lookup(dbex, name, namesize));
+                       if (!info) {
+                               RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_UNRESOLVED_SYMBOL);
+                               RPA_DBEX_SETERRINFO_NAME(dbex, name, namesize);
+                               return -1;
+                       }
                        if (rpa_dbex_findinlined(dbex, info->startrec)) {
                                rpa_dbex_rh_loopref(dbex, prec);
                        } else {
@@ -630,6 +661,7 @@ rpadbex_t *rpa_dbex_create(void)
        dbex->handlers[RPA_PRODUCTION_DIRECTIVENOEMIT] = rpa_dbex_rh_noemit;
        dbex->handlers[RPA_PRODUCTION_DIRECTIVEEMITALL] = rpa_dbex_rh_emitall;
        dbex->handlers[RPA_PRODUCTION_DIRECTIVEEMITNONE] = rpa_dbex_rh_emitnone;
+       dbex->handlers[RPA_PRODUCTION_DIRECTIVEUID] = rpa_dbex_rh_uid;
 
        return dbex;
 }
@@ -815,7 +847,7 @@ static void rpa_dbex_buildruleinfo(rpadbex_t *dbex)
                        if ((rec = rpa_dbex_record(dbex, rpa_recordtree_get(dbex->records, i, RPA_RECORD_END))))
                                r_harray_add(dbex->rules, rec->input, rec->inputsiz, &info);
                        i += info.sizerecs - 1;
-               } else if ((rec->type & RPA_RECORD_START) && (rec->ruleuid >= RPA_PRODUCTION_DIRECTIVEEMIT) && (rec->ruleuid <= RPA_PRODUCTION_DIRECTIVEEMITALL)) {
+               } else if ((rec->type & RPA_RECORD_START) && (rec->ruleuid >= RPA_PRODUCTION_DIRECTIVEEMIT) && (rec->ruleuid <= RPA_PRODUCTION_DIRECTIVEUID)) {
                        r_memset(&info, 0, sizeof(info));
                        info.type = RPA_RULEINFO_DIRECTIVE;
                        info.startrec = i;
index 88463f9..24438e8 100644 (file)
@@ -84,7 +84,25 @@ static void rpa_production_directives(rpa_parser_t *pa)
        rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
        rpa_compiler_branch_end(co);
 
+       rpa_compiler_branch_begin(co, RPA_MATCH_NONE);
+       rpa_compiler_reference_nan_s(co, "uid");
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_branch_end(co);
        rpa_compiler_altexp_end(co);
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+
+       /*
+        * Skip any junk we might have up to the end of the line
+        */
+       rpa_compiler_notexp_begin(co, RPA_MATCH_MULTIOPT);
+       rpa_compiler_class_begin(co, RPA_MATCH_NONE);
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, '\r'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BGRE, DA, XX, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, '\n'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BGRE, DA, XX, XX, 0));
+       rpa_compiler_class_end(co);
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_notexp_end(co);
 
        rpa_compiler_rule_end(co);
 }
@@ -143,6 +161,38 @@ static void rpa_production_bnf(rpa_parser_t *pa)
 }
 
 
+static void rpa_production_directive_uid(rpa_parser_t *pa)
+{
+       rpa_compiler_t *co = pa->co;
+
+       rpa_compiler_rulepref_set_ruleuid_flags_s(co, "uid", RPA_PRODUCTION_DIRECTIVEUID, RPA_RFLAG_EMITRECORD);
+       rpa_compiler_rule_begin_s(co, "uid");
+
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, '#'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_opt_s(co, "space");
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, '!'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_opt_s(co, "space");
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, 'u'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, 'i'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RPA_MATCHCHR_NAN, DA, XX, XX, 'd'));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_nan_s(co, "space");
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_nan_s(co, "rulename");
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_nan_s(co, "space");
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+       rpa_compiler_reference_nan_s(co, "dec");
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, RPA_COMPILER_CURRENTEXP(co)->endidx, rvm_asm(RVM_BLES, DA, XX, XX, 0));
+
+       rpa_compiler_rule_end(co);
+}
+
+
 static void rpa_production_directive_emit(rpa_parser_t *pa)
 {
        rpa_compiler_t *co = pa->co;
@@ -1325,6 +1375,7 @@ static rint rpa_parser_init(rpa_parser_t *pa)
        rpa_production_directive_emitnone(pa);
        rpa_production_directive_emit(pa);
        rpa_production_directive_noemit(pa);
+       rpa_production_directive_uid(pa);
        rpa_production_directives(pa);
        rpa_production_char(pa);
        rpa_production_clsnum(pa);
index 0e00a71..925f59a 100644 (file)
@@ -46,6 +46,7 @@ enum {
        RPA_PRODUCTION_DIRECTIVENOEMIT,
        RPA_PRODUCTION_DIRECTIVEEMITNONE,
        RPA_PRODUCTION_DIRECTIVEEMITALL,
+       RPA_PRODUCTION_DIRECTIVEUID,
 
 
 /*
index 7d4ff96..0d1f175 100644 (file)
@@ -247,9 +247,10 @@ static void rpavm_swi_emitstart(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rword tp = RVM_CPUREG_GETU(cpu, ins->op2);
        rstr_t name = {(rchar*)ruledata + ruledata->name, ruledata->namesize};
 
+       if (stat->debug)
+               r_printf("%ld: %s, %s, tp = %ld\n", RVM_CPUREG_GETU(cpu, FP), "START", name.str, tp);
        if (!(ruledata->flags & RPA_RFLAG_EMITRECORD))
                return;
-//     r_printf("%ld: %s, %s, tp = %ld\n", RVM_CPUREG_GETU(cpu, FP), "START", name.str, tp);
        R_ASSERT(RVM_CPUREG_GETL(cpu, R_REC) >= 0);
 //     index = r_array_replace(stat->records, index + 1, NULL);
        index = r_array_add(stat->records, NULL);
@@ -282,9 +283,11 @@ static void rpavm_swi_emitend(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rword tplen = RVM_CPUREG_GETU(cpu, ins->op3);
        rstr_t name = {(rchar*)ruledata + ruledata->name, ruledata->namesize};
 
+       if (stat->debug)
+               r_printf("%ld: %s, %s, tp = %ld, tplen = %ld\n", RVM_CPUREG_GETU(cpu, FP), "END ", name.str, tp, tplen);
        if (!(ruledata->flags & RPA_RFLAG_EMITRECORD))
                return;
-//     r_printf("%ld: %s, %s, tp = %ld, tplen = %ld\n", RVM_CPUREG_GETU(cpu, FP), "END ", name.str, tp, tplen);
+
        R_ASSERT(RVM_CPUREG_GETL(cpu, R_REC) >= 0);
 //     index = r_array_replace(stat->records, index + 1, NULL);
        index = r_array_add(stat->records, NULL);
@@ -313,11 +316,16 @@ static void rpavm_swi_emitend(rvmcpu_t *cpu, rvm_asmins_t *ins)
 
 static void rpavm_swi_prninfo(rvmcpu_t *cpu, rvm_asmins_t *ins)
 {
+       rpastat_t *stat = (rpastat_t *)cpu->userdata1;
        rpa_ruledata_t *ruledata = RVM_CPUREG_GETP(cpu, ins->op1);
-       rstr_t name = {(rchar*)ruledata + ruledata->name, ruledata->namesize};
-
-       if (!(ruledata->flags & RPA_RFLAG_EMITRECORD))
+       rstr_t name = {"unknown", 7};
+       if (!stat->debug)
                return;
+       if (ruledata) {
+               name.str = (rchar*)ruledata + ruledata->name;
+               name.size = ruledata->namesize;
+       }
+
        r_printf("%s: ", name.str);
        rvm_cpu_dumpregs(cpu, ins);
 }