mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
lots of treeifying and removed ambiguities
This commit is contained in:
parent
b48d69e443
commit
d0a695315a
@ -14,6 +14,6 @@ java -Xmx512m -jar ../../../jar/antlr-3.3.jar -Xconversiontimeout 5000 -make -ve
|
|||||||
# echo JavaPrettyPrint.g
|
# echo JavaPrettyPrint.g
|
||||||
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -Xconversiontimeout 10000 -make -verbose JavaPrettyPrint.g
|
java -Xmx512m -jar ../../../jar/antlr-3.3.jar -Xconversiontimeout 10000 -make -verbose JavaPrettyPrint.g
|
||||||
cd ../../../
|
cd ../../../
|
||||||
#xbuild
|
xbuild
|
||||||
echo 'All Done'
|
echo 'All Done'
|
||||||
|
|
||||||
|
@ -50,9 +50,14 @@ namespace RusticiSoftware.Translator.AntlrUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void DumpNodesFlat(CommonTreeNodeStream nodes)
|
public static void DumpNodesFlat(CommonTreeNodeStream nodes)
|
||||||
|
{
|
||||||
|
DumpNodesFlat(nodes, "Nodes");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DumpNodesFlat(CommonTreeNodeStream nodes, string title)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||||
Console.WriteLine("Nodes");
|
Console.WriteLine(title);
|
||||||
//object o_prev = string.Empty;
|
//object o_prev = string.Empty;
|
||||||
object o = nodes.NextElement();
|
object o = nodes.NextElement();
|
||||||
while (!nodes.IsEndOfFile(o))
|
while (!nodes.IsEndOfFile(o))
|
||||||
@ -89,7 +94,7 @@ namespace RusticiSoftware.Translator.AntlrUtils
|
|||||||
}
|
}
|
||||||
// if (o_prev.ToString() != "UP" && o_prev.ToString() != "DOWN")
|
// if (o_prev.ToString() != "UP" && o_prev.ToString() != "DOWN")
|
||||||
// Console.Write(" {0}", o_prev.ToString());
|
// Console.Write(" {0}", o_prev.ToString());
|
||||||
// Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +272,12 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
long startTime = DateTime.Now.Ticks;
|
long startTime = DateTime.Now.Ticks;
|
||||||
if (cfg.DebugLevel > 3) Console.Out.WriteLine("Translating file {0}", fullName);
|
if (cfg.DebugLevel > 3) Console.Out.WriteLine("Translating file {0}", fullName);
|
||||||
if (cfg.DebugLevel > 5) Console.Out.WriteLine("Parsing file {0}", fullName);
|
if (cfg.DebugLevel > 5) Console.Out.WriteLine("Parsing file {0}", fullName);
|
||||||
ITreeNodeStream csTree = parseFile(fullName);
|
CommonTreeNodeStream csTree = parseFile(fullName);
|
||||||
if (cfg.DumpCSharp && csTree != null) AntlrUtils.AntlrUtils.DumpNodes((CommonTreeNodeStream)csTree);
|
if (cfg.DumpCSharp && csTree != null)
|
||||||
|
{
|
||||||
|
AntlrUtils.AntlrUtils.DumpNodesFlat(csTree, "C Sharp Parse Tree");
|
||||||
|
csTree.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
if (csTree != null)
|
if (csTree != null)
|
||||||
{
|
{
|
||||||
@ -327,7 +331,11 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
|
|
||||||
// Translate calls to .Net to calls to Java libraries
|
// Translate calls to .Net to calls to Java libraries
|
||||||
CommonTreeNodeStream javaSyntaxNodes = new CommonTreeNodeStream(typeAST);
|
CommonTreeNodeStream javaSyntaxNodes = new CommonTreeNodeStream(typeAST);
|
||||||
if (cfg.DumpJavaSyntax && javaSyntaxNodes != null) AntlrUtils.AntlrUtils.DumpNodesFlat(javaSyntaxNodes);
|
if (cfg.DumpJavaSyntax && javaSyntaxNodes != null)
|
||||||
|
{
|
||||||
|
AntlrUtils.AntlrUtils.DumpNodesFlat(javaSyntaxNodes, "Java Syntax Parse Tree for " + claName);
|
||||||
|
javaSyntaxNodes.Reset();
|
||||||
|
}
|
||||||
javaSyntaxNodes.TokenStream = csTree.TokenStream;
|
javaSyntaxNodes.TokenStream = csTree.TokenStream;
|
||||||
|
|
||||||
NetMaker netMaker = new NetMaker(javaSyntaxNodes);
|
NetMaker netMaker = new NetMaker(javaSyntaxNodes);
|
||||||
@ -342,6 +350,11 @@ namespace RusticiSoftware.Translator.CSharp
|
|||||||
CommonTreeNodeStream javaCompilationUnitNodes = new CommonTreeNodeStream(javaCompilationUnit.Tree);
|
CommonTreeNodeStream javaCompilationUnitNodes = new CommonTreeNodeStream(javaCompilationUnit.Tree);
|
||||||
javaCompilationUnitNodes.TokenStream = csTree.TokenStream;
|
javaCompilationUnitNodes.TokenStream = csTree.TokenStream;
|
||||||
|
|
||||||
|
if (cfg.DumpJava && javaCompilationUnitNodes != null)
|
||||||
|
{
|
||||||
|
AntlrUtils.AntlrUtils.DumpNodesFlat(javaCompilationUnitNodes, "Final Java Parse Tree for " + claName);
|
||||||
|
javaCompilationUnitNodes.Reset();
|
||||||
|
}
|
||||||
// Pretty print java parse tree as text
|
// Pretty print java parse tree as text
|
||||||
JavaPrettyPrint outputMaker = new JavaPrettyPrint(javaCompilationUnitNodes);
|
JavaPrettyPrint outputMaker = new JavaPrettyPrint(javaCompilationUnitNodes);
|
||||||
outputMaker.Filename = fullName;
|
outputMaker.Filename = fullName;
|
||||||
|
@ -164,41 +164,42 @@ modifier:
|
|||||||
| 'readonly' -> FINAL["final"] | 'volatile' | 'extern' | 'virtual' | 'override';
|
| 'readonly' -> FINAL["final"] | 'volatile' | 'extern' | 'virtual' | 'override';
|
||||||
|
|
||||||
class_member_declaration:
|
class_member_declaration:
|
||||||
attributes?
|
a=attributes?
|
||||||
m=modifiers?
|
m=modifiers?
|
||||||
( 'const' type constant_declarators ';'
|
( c='const' ct=type constant_declarators ';' -> ^(CONST[$c.token, "CONST"] $a? $m? $ct constant_declarators)
|
||||||
| event_declaration // 'event'
|
| ed=event_declaration -> ^(EVENT[$ed.start.Token, "EVENT"] $a? $m? $ed)
|
||||||
| p='partial' { Warning($p.line, "[UNSUPPORTED] 'partial' definition"); } (method_declaration
|
| p='partial' { Warning($p.line, "[UNSUPPORTED] 'partial' definition"); } (v1='void' m3=method_declaration -> ^(METHOD[$v1.token, "METHOD"] $a? $m? ^(TYPE $v1) $m3)
|
||||||
| interface_declaration
|
| i1=interface_declaration -> ^(INTERFACE[$i1.start.Token, "INTERFACE"] $a? $m? $i1)
|
||||||
| class_declaration
|
| c1=class_declaration -> ^(CLASS[$c1.start.Token, "CLASS"] $a? $m? $c1)
|
||||||
| struct_declaration)
|
| s1=struct_declaration) -> ^(CLASS[$s1.start.Token, "CLASS"] $a? $m? $s1)
|
||||||
| interface_declaration // 'interface'
|
| i2=interface_declaration -> ^(INTERFACE[$i2.start.Token, "INTERFACE"] $a? $m? $i2) // 'interface'
|
||||||
| 'void' method_declaration
|
| v='void' m1=method_declaration -> ^(METHOD[$v.token, "METHOD"] $a? $m? ^(TYPE[$v.token, "TYPE"] $v) $m1)
|
||||||
| type ( (member_name '(') => method_declaration
|
| t=type ( (member_name '(') => m2=method_declaration -> ^(METHOD[$t.start.Token, "METHOD"] $a? $m? $t $m2)
|
||||||
| (member_name '{') => property_declaration
|
| (member_name '{') => property_declaration -> ^(PROPERTY[$t.start.Token, "PROPERTY"] $a? $m? $t property_declaration)
|
||||||
| (member_name '.' 'this') => type_name '.' indexer_declaration
|
| (member_name '.' 'this') => type_name '.' ix1=indexer_declaration -> ^(INDEXER[$t.start.Token, "INDEXER"] $a? $m? $t type_name $ix1)
|
||||||
| indexer_declaration //this
|
| ix2=indexer_declaration -> ^(INDEXER[$t.start.Token,"INDEXER"] $a? $m? $t $ix2) //this
|
||||||
| field_declaration // qid
|
| field_declaration -> ^(FIELD[$t.start.Token, "FIELD"] $a? $m? $t field_declaration) // qid
|
||||||
| operator_declaration
|
| operator_declaration -> ^(OPERATOR[$t.start.Token, "OPERATOR"] $a? $m? $t operator_declaration)
|
||||||
)
|
)
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
|
||||||
| class_declaration // 'class'
|
| c3=class_declaration -> ^(CLASS[$c3.start.Token, "CLASS"] $a? $m? $c3) // 'class'
|
||||||
| struct_declaration // 'struct'
|
| s3=struct_declaration -> ^(CLASS[$s3.start.Token, "CLASS"] $a? $m? $s3)
|
||||||
| enum_declaration // 'enum'
|
| e3=enum_declaration -> ^(ENUM[$e3.start.Token, "ENUM"] $a? $m? $e3)
|
||||||
| delegate_declaration // 'delegate'
|
| d3=delegate_declaration -> ^(DELEGATE[$d3.start.Token, "DELEGATE"] $a? $m? $d3)
|
||||||
| conversion_operator_declaration
|
| co3=conversion_operator_declaration -> ^(CONVERSION_OPERATOR[$co3.start.Token, "CONVERSION"] $a? $m? $co3)
|
||||||
| constructor_declaration // | static_constructor_declaration
|
| con3=constructor_declaration -> ^(CONSTRUCTOR[$con3.start.Token, "CONSTRUCTOR"] $a? $m? $con3)
|
||||||
| destructor_declaration
|
| de3=destructor_declaration -> ^(DESTRUCTOR[$de3.start.Token, "DESTRUCTOR"] $a? $m? $de3)
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
primary_expression:
|
primary_expression:
|
||||||
('this' brackets) => 'this' brackets primary_expression_part*
|
('this' brackets[null]) => (t='this' -> $t) (b1=brackets[$primary_expression.tree] -> $b1) (pp1=primary_expression_part[$primary_expression.tree] -> $pp1) *
|
||||||
| ('base' brackets) => 'this' brackets primary_expression_part*
|
| ('base' brackets[null]) => (b='this' -> $b) (b2=brackets[$primary_expression.tree] -> $b2) (pp2=primary_expression_part[$primary_expression.tree] -> $pp2) *
|
||||||
| primary_expression_start primary_expression_part*
|
| (primary_expression_start -> primary_expression_start) (pp3=primary_expression_part[$primary_expression.tree] -> $pp3 )*
|
||||||
|
// keving:TODO fixup
|
||||||
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
||||||
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
object_creation_expression primary_expression_part[null]+ // new Foo(arg, arg).Member
|
||||||
// try the simple one first, this has no argS and no expressions
|
// try the simple one first, this has no argS and no expressions
|
||||||
// symantically could be object creation
|
// symantically could be object creation
|
||||||
| (delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
|
| (delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
|
||||||
@ -222,23 +223,25 @@ primary_expression_start:
|
|||||||
| literal
|
| literal
|
||||||
;
|
;
|
||||||
|
|
||||||
primary_expression_part:
|
primary_expression_part [CommonTree lhs]:
|
||||||
access_identifier
|
access_identifier[$lhs]
|
||||||
| brackets_or_arguments
|
| brackets_or_arguments[$lhs]
|
||||||
| '++'
|
| p='++' -> ^(POSTINC[$p.token, "POST++"] { (CommonTree)adaptor.DupTree($lhs) } )
|
||||||
| '--' ;
|
| m='--' -> ^(POSTDEC[$m.token, "POST--"] { (CommonTree)adaptor.DupTree($lhs) } )
|
||||||
access_identifier:
|
;
|
||||||
access_operator type_or_generic ;
|
access_identifier [CommonTree lhs]:
|
||||||
|
access_operator type_or_generic -> ^(access_operator { (CommonTree)adaptor.DupTree($lhs) } type_or_generic);
|
||||||
access_operator:
|
access_operator:
|
||||||
'.' | '->' ;
|
'.' | '->' ;
|
||||||
brackets_or_arguments:
|
brackets_or_arguments [CommonTree lhs]:
|
||||||
brackets | arguments ;
|
brackets[$lhs] | arguments[$lhs] ;
|
||||||
brackets:
|
brackets [CommonTree lhs]:
|
||||||
'[' expression_list? ']' ;
|
'[' expression_list? ']' -> ^(INDEX { (CommonTree)adaptor.DupTree($lhs) } expression_list?);
|
||||||
|
// keving: TODO: drop this.
|
||||||
paren_expression:
|
paren_expression:
|
||||||
'(' expression ')' ;
|
'(' expression ')' -> ^(TEMPPARENS expression);
|
||||||
arguments:
|
arguments [CommonTree lhs]:
|
||||||
'(' argument_list? ')' ;
|
'(' argument_list? ')' -> ^(APPLY { (CommonTree)adaptor.DupTree($lhs) } argument_list?);
|
||||||
argument_list:
|
argument_list:
|
||||||
argument (',' argument)*;
|
argument (',' argument)*;
|
||||||
// 4.0
|
// 4.0
|
||||||
@ -291,12 +294,12 @@ primary_or_array_creation_expression:
|
|||||||
;
|
;
|
||||||
// new Type[2] { }
|
// new Type[2] { }
|
||||||
array_creation_expression:
|
array_creation_expression:
|
||||||
'new'
|
'new'^
|
||||||
(type ('[' expression_list ']'
|
(type ('[' expression_list ']'
|
||||||
( rank_specifiers? array_initializer? // new int[4]
|
( rank_specifiers? array_initializer? // new int[4]
|
||||||
// | invocation_part*
|
// | invocation_part*
|
||||||
| ( ((arguments ('['|'.'|'->')) => arguments invocation_part)// new object[2].GetEnumerator()
|
| ( ((arguments[null] ('['|'.'|'->')) => arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] invocation_part)// new object[2].GetEnumerator()
|
||||||
| invocation_part)* arguments
|
| invocation_part)* arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ]
|
||||||
) // new int[4]()
|
) // new int[4]()
|
||||||
| array_initializer
|
| array_initializer
|
||||||
)
|
)
|
||||||
@ -311,15 +314,15 @@ variable_initializer_list:
|
|||||||
variable_initializer:
|
variable_initializer:
|
||||||
expression | array_initializer ;
|
expression | array_initializer ;
|
||||||
sizeof_expression:
|
sizeof_expression:
|
||||||
'sizeof' '(' unmanaged_type ')';
|
'sizeof'^ '('! unmanaged_type ')'!;
|
||||||
checked_expression:
|
checked_expression:
|
||||||
'checked' '(' expression ')' ;
|
'checked'^ '('! expression ')'! ;
|
||||||
unchecked_expression:
|
unchecked_expression:
|
||||||
'unchecked' '(' expression ')' ;
|
'unchecked'^ '('! expression ')'! ;
|
||||||
default_value_expression:
|
default_value_expression:
|
||||||
'default' '(' type ')' ;
|
'default'^ '('! type ')'! ;
|
||||||
anonymous_method_expression:
|
anonymous_method_expression:
|
||||||
'delegate' explicit_anonymous_function_signature? block;
|
'delegate'^ explicit_anonymous_function_signature? block;
|
||||||
explicit_anonymous_function_signature:
|
explicit_anonymous_function_signature:
|
||||||
'(' explicit_anonymous_function_parameter_list? ')' ;
|
'(' explicit_anonymous_function_parameter_list? ')' ;
|
||||||
explicit_anonymous_function_parameter_list:
|
explicit_anonymous_function_parameter_list:
|
||||||
@ -366,9 +369,9 @@ initializer_value:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
typeof_expression:
|
typeof_expression:
|
||||||
'typeof' '(' ((unbound_type_name) => unbound_type_name
|
'typeof'^ '('! ((unbound_type_name) => unbound_type_name
|
||||||
| type
|
| type
|
||||||
| 'void') ')' ;
|
| 'void') ')'! ;
|
||||||
// unbound type examples
|
// unbound type examples
|
||||||
//foo<bar<X<>>>
|
//foo<bar<X<>>>
|
||||||
//bar::foo<>
|
//bar::foo<>
|
||||||
@ -423,7 +426,7 @@ qid_start returns [string name, List<String> tyargs]:
|
|||||||
|
|
||||||
|
|
||||||
qid_part:
|
qid_part:
|
||||||
access_identifier ;
|
access_identifier[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] ;
|
||||||
|
|
||||||
generic_argument_list returns [List<string> tyargs]
|
generic_argument_list returns [List<string> tyargs]
|
||||||
@after {
|
@after {
|
||||||
@ -442,12 +445,12 @@ type returns [string thetext]:
|
|||||||
((predefined_type | type_name) rank_specifiers) => (p1=predefined_type { $thetext = $p1.thetext; } | tn1=type_name { $thetext = $tn1.thetext; }) rs=rank_specifiers { $thetext += $rs.text; } (s1+='*' { $thetext += "*"; })* -> ^(TYPE $p1? $tn1? $rs $s1*)
|
((predefined_type | type_name) rank_specifiers) => (p1=predefined_type { $thetext = $p1.thetext; } | tn1=type_name { $thetext = $tn1.thetext; }) rs=rank_specifiers { $thetext += $rs.text; } (s1+='*' { $thetext += "*"; })* -> ^(TYPE $p1? $tn1? $rs $s1*)
|
||||||
| ((predefined_type | type_name) ('*'+ | '?')) => (p2=predefined_type { $thetext = $p2.thetext; } | tn2=type_name { $thetext = $tn2.thetext; }) ((s2+='*' { $thetext += "*"; })+ | o2='?' { $thetext += "?"; }) -> ^(TYPE $p2? $tn2? $s2* $o2?)
|
| ((predefined_type | type_name) ('*'+ | '?')) => (p2=predefined_type { $thetext = $p2.thetext; } | tn2=type_name { $thetext = $tn2.thetext; }) ((s2+='*' { $thetext += "*"; })+ | o2='?' { $thetext += "?"; }) -> ^(TYPE $p2? $tn2? $s2* $o2?)
|
||||||
| (p3=predefined_type { $thetext = $p3.thetext; } | tn3=type_name { $thetext = $tn3.thetext; }) -> ^(TYPE $p3? $tn3?)
|
| (p3=predefined_type { $thetext = $p3.thetext; } | tn3=type_name { $thetext = $tn3.thetext; }) -> ^(TYPE $p3? $tn3?)
|
||||||
| v='void' { $thetext = "System.Void"; } (s+='*' { $thetext += "*"; })+ -> ^(TYPE $v $s+)
|
| v='void' { $thetext = "System.Void"; } (s+='*' { $thetext += "*"; })+ -> ^(TYPE[$v.token, "TYPE"] $v $s+)
|
||||||
;
|
;
|
||||||
non_nullable_type:
|
non_nullable_type:
|
||||||
type
|
(p=predefined_type | t=type_name) rs=rank_specifiers? (s+='*')* -> ^(TYPE["TYPE"] $p? $t? $rs? $s*)
|
||||||
|
| v='void' (s+='*')+ -> ^(TYPE[$v.token,"TYPE"] $v $s+)
|
||||||
;
|
;
|
||||||
|
|
||||||
non_array_type:
|
non_array_type:
|
||||||
type;
|
type;
|
||||||
array_type:
|
array_type:
|
||||||
@ -482,30 +485,30 @@ assignment:
|
|||||||
unary_expression assignment_operator expression ;
|
unary_expression assignment_operator expression ;
|
||||||
unary_expression:
|
unary_expression:
|
||||||
//('(' arguments ')' ('[' | '.' | '(')) => primary_or_array_creation_expression
|
//('(' arguments ')' ('[' | '.' | '(')) => primary_or_array_creation_expression
|
||||||
(cast_expression) => cast_expression
|
(cast_expression) => cast_expression
|
||||||
| primary_or_array_creation_expression
|
| primary_or_array_creation_expression -> primary_or_array_creation_expression
|
||||||
| '+' unary_expression
|
| p='+' unary_expression -> ^(MONOPLUS[$p.token,"MONOPLUS"] unary_expression)
|
||||||
| '-' unary_expression
|
| m='-' unary_expression -> ^(MONOMINUS[$m.token, "MONOMINUS"] unary_expression)
|
||||||
| '!' unary_expression
|
| n='!' unary_expression -> ^(MONONOT[$n.token, "MONONOT"] unary_expression)
|
||||||
| '~' unary_expression
|
| t='~' unary_expression -> ^(MONOTWIDDLE[$t.token, "TWIDDLE"] unary_expression)
|
||||||
| pre_increment_expression
|
| pre_increment_expression -> pre_increment_expression
|
||||||
| pre_decrement_expression
|
| pre_decrement_expression -> pre_decrement_expression
|
||||||
| pointer_indirection_expression
|
| pointer_indirection_expression -> pointer_indirection_expression
|
||||||
| addressof_expression
|
| addressof_expression -> addressof_expression
|
||||||
;
|
;
|
||||||
cast_expression:
|
cast_expression:
|
||||||
//'(' type ')' unary_expression ;
|
// //'(' type ')' unary_expression ;
|
||||||
'(' type ')' unary_expression -> ^(CAST_EXPR type unary_expression);
|
l='(' type ')' unary_expression -> ^(CAST_EXPR[$l.token, "CAST"] type unary_expression);
|
||||||
assignment_operator:
|
assignment_operator:
|
||||||
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
||||||
pre_increment_expression:
|
pre_increment_expression:
|
||||||
'++' unary_expression ;
|
s='++' unary_expression -> ^(PREINC[$s.token, "PRE++"] unary_expression) ;
|
||||||
pre_decrement_expression:
|
pre_decrement_expression:
|
||||||
'--' unary_expression ;
|
s='--' unary_expression -> ^(PREDEC[$s.token, "PRE--"] unary_expression);
|
||||||
pointer_indirection_expression:
|
pointer_indirection_expression:
|
||||||
'*' unary_expression ;
|
s='*' unary_expression -> ^(MONOSTAR[$s.token, "STAR"] unary_expression);
|
||||||
addressof_expression:
|
addressof_expression:
|
||||||
'&' unary_expression ;
|
a='&' unary_expression -> ^(ADDRESSOF[$a.token, "ADDRESSOF"] unary_expression);
|
||||||
|
|
||||||
non_assignment_expression:
|
non_assignment_expression:
|
||||||
//'non ASSIGNment'
|
//'non ASSIGNment'
|
||||||
@ -553,8 +556,9 @@ conditional_or_expression:
|
|||||||
null_coalescing_expression:
|
null_coalescing_expression:
|
||||||
conditional_or_expression ('??'^ conditional_or_expression)* ;
|
conditional_or_expression ('??'^ conditional_or_expression)* ;
|
||||||
conditional_expression:
|
conditional_expression:
|
||||||
(null_coalescing_expression '?' expression ':') => e1=null_coalescing_expression q='?' e2=expression ':' e3=expression -> ^(COND_EXPR[$q.Token, "?:"] $e1 $e2 $e3)
|
(ne=null_coalescing_expression -> $ne) (q='?' te=expression ':' ee=expression -> ^(COND_EXPR[$q.token, "?:"] $conditional_expression $te $ee))? ;
|
||||||
| null_coalescing_expression ;
|
// (null_coalescing_expression '?' expression ':') => e1=null_coalescing_expression q='?' e2=expression ':' e3=expression -> ^(COND_EXPR[$q.token, "?:"] $e1 $e2 $e3)
|
||||||
|
// | null_coalescing_expression ;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// lambda Section
|
// lambda Section
|
||||||
@ -854,7 +858,7 @@ constructor_constraint:
|
|||||||
'new' '(' ')' ;
|
'new' '(' ')' ;
|
||||||
return_type:
|
return_type:
|
||||||
type
|
type
|
||||||
| v='void' -> ^(TYPE $v);
|
| v='void' -> ^(TYPE[$v.token, "TYPE"] $v);
|
||||||
formal_parameter_list:
|
formal_parameter_list:
|
||||||
formal_parameter (',' formal_parameter)* ;
|
formal_parameter (',' formal_parameter)* ;
|
||||||
formal_parameter:
|
formal_parameter:
|
||||||
@ -1021,8 +1025,8 @@ destructor_body:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
invocation_expression:
|
invocation_expression:
|
||||||
invocation_start (((arguments ('['|'.'|'->')) => arguments invocation_part)
|
invocation_start (((arguments[null] ('['|'.'|'->')) => arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] invocation_part)
|
||||||
| invocation_part)* arguments ;
|
| invocation_part)* arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] ;
|
||||||
invocation_start:
|
invocation_start:
|
||||||
predefined_type
|
predefined_type
|
||||||
| (identifier generic_argument_list) => identifier generic_argument_list
|
| (identifier generic_argument_list) => identifier generic_argument_list
|
||||||
@ -1032,8 +1036,8 @@ invocation_start:
|
|||||||
| typeof_expression // typeof(Foo).Name
|
| typeof_expression // typeof(Foo).Name
|
||||||
;
|
;
|
||||||
invocation_part:
|
invocation_part:
|
||||||
access_identifier
|
access_identifier[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ]
|
||||||
| brackets ;
|
| brackets[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] ;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -91,39 +91,61 @@ modifier
|
|||||||
-> string(payload={$m.text});
|
-> string(payload={$m.text});
|
||||||
|
|
||||||
class_member_declaration:
|
class_member_declaration:
|
||||||
attributes?
|
^(CONST attributes? modifiers? type constant_declarators)
|
||||||
m=modifiers?
|
| ^(EVENT attributes? modifiers? event_declaration)
|
||||||
( 'const' t1=type constant_declarators ';'
|
| ^(METHOD attributes? modifiers? type method_declaration)
|
||||||
| event_declaration // 'event'
|
| ^(INTERFACE attributes? modifiers? interface_declaration[$modifiers.st])
|
||||||
| 'partial' (method_declaration
|
| ^(CLASS attributes? modifiers? class_declaration[$modifiers.st])
|
||||||
| interface_declaration[$m.st]
|
| ^(PROPERTY attributes? modifiers? type property_declaration)
|
||||||
| class_declaration[$m.st]
|
| ^(INDEXER attributes? modifiers? type type_name? indexer_declaration)
|
||||||
| struct_declaration)
|
| ^(FIELD attributes? modifiers? type field_declaration) -> field(modifiers={$modifiers.st}, type={$type.st}, field={$field_declaration.st})
|
||||||
| interface_declaration[$m.st] // 'interface'
|
| ^(OPERATOR attributes? modifiers? type operator_declaration)
|
||||||
| 'void' method_declaration
|
| ^(ENUM attributes? modifiers? enum_declaration[$modifiers.st])
|
||||||
| t2=type ( (member_name '(') => method_declaration
|
| ^(DELEGATE attributes? modifiers? delegate_declaration)
|
||||||
| (member_name '{') => property_declaration
|
| ^(CONSTRUCTOR attributes? modifiers? constructor_declaration)
|
||||||
| (member_name '.' 'this') => type_name '.' indexer_declaration
|
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
||||||
| indexer_declaration //this
|
;
|
||||||
| field_declaration -> field(modifiers={$m.st}, type={$t2.st}, field={$field_declaration.st}) // qid
|
|
||||||
| operator_declaration
|
|
||||||
)
|
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
|
||||||
|
|
||||||
| c2=class_declaration[$m.st] -> { $c2.st } // 'class'
|
|
||||||
| s2=struct_declaration -> { $s2.st }// 'struct'
|
|
||||||
| e2=enum_declaration[$m.st] -> { $e2.st } // 'enum'
|
|
||||||
| delegate_declaration // 'delegate'
|
|
||||||
| conversion_operator_declaration
|
|
||||||
| constructor_declaration // | static_constructor_declaration
|
|
||||||
| destructor_declaration
|
|
||||||
)
|
|
||||||
;
|
|
||||||
|
|
||||||
|
// class_member_declaration:
|
||||||
|
// attributes?
|
||||||
|
// m=modifiers?
|
||||||
|
// ( 'const' t1=type constant_declarators ';'
|
||||||
|
// | event_declaration // 'event'
|
||||||
|
// | 'partial' (method_declaration
|
||||||
|
// | interface_declaration[$m.st]
|
||||||
|
// | class_declaration[$m.st]
|
||||||
|
// | struct_declaration)
|
||||||
|
// | interface_declaration[$m.st] // 'interface'
|
||||||
|
// // | 'void' method_declaration
|
||||||
|
// | t2=type ( (member_name '(') => method_declaration
|
||||||
|
// | (member_name '{') => property_declaration
|
||||||
|
// | (member_name '.' 'this') => type_name '.' indexer_declaration
|
||||||
|
// | indexer_declaration //this
|
||||||
|
// | field_declaration -> field(modifiers={$m.st}, type={$t2.st}, field={$field_declaration.st}) // qid
|
||||||
|
// | operator_declaration
|
||||||
|
// )
|
||||||
|
// // common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
//
|
||||||
|
// | c2=class_declaration[$m.st] -> { $c2.st } // 'class'
|
||||||
|
// | s2=struct_declaration -> { $s2.st }// 'struct'
|
||||||
|
// | e2=enum_declaration[$m.st] -> { $e2.st } // 'enum'
|
||||||
|
// | delegate_declaration // 'delegate'
|
||||||
|
// | conversion_operator_declaration
|
||||||
|
// | constructor_declaration // | static_constructor_declaration
|
||||||
|
// | destructor_declaration
|
||||||
|
// )
|
||||||
|
// ;
|
||||||
|
//
|
||||||
primary_expression:
|
primary_expression:
|
||||||
('this' brackets) => 'this' brackets primary_expression_part*
|
^(INDEX expression expression_list?)
|
||||||
| ('base' brackets) => 'this' brackets primary_expression_part*
|
| ^(APPLY expression argument_list?)
|
||||||
| primary_expression_start pp+=primary_expression_part* -> primary_expression_start_parts(start={ $primary_expression_start.st }, follows={ $pp })
|
| ^(POSTINC expression)
|
||||||
|
| ^(POSTDEC expression)
|
||||||
|
| primary_expression_start -> { $primary_expression_start.st }
|
||||||
|
| ^(access_operator expression type_or_generic)
|
||||||
|
// ('this' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | ('base' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | primary_expression_start primary_expression_part*
|
||||||
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
||||||
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
||||||
// try the simple one first, this has no argS and no expressions
|
// try the simple one first, this has no argS and no expressions
|
||||||
@ -137,6 +159,23 @@ primary_expression:
|
|||||||
| default_value_expression // default
|
| default_value_expression // default
|
||||||
| anonymous_method_expression // delegate (int foo) {}
|
| anonymous_method_expression // delegate (int foo) {}
|
||||||
;
|
;
|
||||||
|
// primary_expression:
|
||||||
|
// ('this' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | ('base' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | primary_expression_start pp+=primary_expression_part* -> primary_expression_start_parts(start={ $primary_expression_start.st }, follows={ $pp })
|
||||||
|
// | 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
||||||
|
// object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
||||||
|
// // try the simple one first, this has no argS and no expressions
|
||||||
|
// // symantically could be object creation
|
||||||
|
// | (delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
|
||||||
|
// | object_creation_expression
|
||||||
|
// | anonymous_object_creation_expression) // new {int X, string Y}
|
||||||
|
// | sizeof_expression // sizeof (struct)
|
||||||
|
// | checked_expression // checked (...
|
||||||
|
// | unchecked_expression // unchecked {...}
|
||||||
|
// | default_value_expression // default
|
||||||
|
// | anonymous_method_expression // delegate (int foo) {}
|
||||||
|
// ;
|
||||||
|
|
||||||
primary_expression_start:
|
primary_expression_start:
|
||||||
predefined_type
|
predefined_type
|
||||||
@ -144,7 +183,7 @@ primary_expression_start:
|
|||||||
| identifier ('::' identifier)?
|
| identifier ('::' identifier)?
|
||||||
| 'this'
|
| 'this'
|
||||||
| 'base'
|
| 'base'
|
||||||
| paren_expression
|
| ^(TEMPPARENS expression) -> template(e={$expression.st}) "(<e>)"
|
||||||
| typeof_expression // typeof(Foo).Name
|
| typeof_expression // typeof(Foo).Name
|
||||||
| literal -> { $literal.st }
|
| literal -> { $literal.st }
|
||||||
;
|
;
|
||||||
@ -212,7 +251,7 @@ primary_or_array_creation_expression:
|
|||||||
;
|
;
|
||||||
// new Type[2] { }
|
// new Type[2] { }
|
||||||
array_creation_expression:
|
array_creation_expression:
|
||||||
'new'
|
^('new'
|
||||||
(type ('[' expression_list ']'
|
(type ('[' expression_list ']'
|
||||||
( rank_specifiers? array_initializer? // new int[4]
|
( rank_specifiers? array_initializer? // new int[4]
|
||||||
// | invocation_part*
|
// | invocation_part*
|
||||||
@ -224,7 +263,7 @@ array_creation_expression:
|
|||||||
| rank_specifier // [,]
|
| rank_specifier // [,]
|
||||||
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
|
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
|
||||||
)
|
)
|
||||||
) ;
|
)) ;
|
||||||
array_initializer:
|
array_initializer:
|
||||||
'{' variable_initializer_list? ','? '}' ;
|
'{' variable_initializer_list? ','? '}' ;
|
||||||
variable_initializer_list:
|
variable_initializer_list:
|
||||||
@ -232,15 +271,15 @@ variable_initializer_list:
|
|||||||
variable_initializer:
|
variable_initializer:
|
||||||
expression -> { $expression.st } | array_initializer -> { $array_initializer.st };
|
expression -> { $expression.st } | array_initializer -> { $array_initializer.st };
|
||||||
sizeof_expression:
|
sizeof_expression:
|
||||||
'sizeof' '(' unmanaged_type ')';
|
^('sizeof' unmanaged_type );
|
||||||
checked_expression:
|
checked_expression:
|
||||||
'checked' '(' expression ')' ;
|
^('checked' expression ) ;
|
||||||
unchecked_expression:
|
unchecked_expression:
|
||||||
'unchecked' '(' expression ')' ;
|
^('unchecked' expression ) ;
|
||||||
default_value_expression:
|
default_value_expression:
|
||||||
'default' '(' type ')' ;
|
^('default' type ) ;
|
||||||
anonymous_method_expression:
|
anonymous_method_expression:
|
||||||
'delegate' explicit_anonymous_function_signature? block;
|
^('delegate' explicit_anonymous_function_signature? block);
|
||||||
explicit_anonymous_function_signature:
|
explicit_anonymous_function_signature:
|
||||||
'(' explicit_anonymous_function_parameter_list? ')' ;
|
'(' explicit_anonymous_function_parameter_list? ')' ;
|
||||||
explicit_anonymous_function_parameter_list:
|
explicit_anonymous_function_parameter_list:
|
||||||
@ -287,9 +326,7 @@ initializer_value:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
typeof_expression:
|
typeof_expression:
|
||||||
'typeof' '(' ((unbound_type_name) => unbound_type_name
|
^('typeof' (unbound_type_name | type | 'void') ) ;
|
||||||
| type
|
|
||||||
| 'void') ')' ;
|
|
||||||
// unbound type examples
|
// unbound type examples
|
||||||
//foo<bar<X<>>>
|
//foo<bar<X<>>>
|
||||||
//bar::foo<>
|
//bar::foo<>
|
||||||
@ -351,7 +388,7 @@ type
|
|||||||
List<string> stars = new List<string>();
|
List<string> stars = new List<string>();
|
||||||
string opt = null;
|
string opt = null;
|
||||||
}:
|
}:
|
||||||
^(TYPE (tp=predefined_type {nm=$tp.st;} | tn=type_name {nm=$tn.st;}) rank_specifiers? ('*' { stars.Add("*");})* ('?' { opt = "?";} )?) -> type(name={ nm }, stars={ stars }, rs={ $rank_specifiers.st }, opt={ opt })
|
^(TYPE (tp=predefined_type {nm=$tp.st;} | tn=type_name {nm=$tn.st;} | tv='void' {nm=new StringTemplate("void");}) rank_specifiers? ('*' { stars.Add("*");})* ('?' { opt = "?";} )?) -> type(name={ nm }, stars={ stars }, rs={ $rank_specifiers.st }, opt={ opt })
|
||||||
;
|
;
|
||||||
non_nullable_type:
|
non_nullable_type:
|
||||||
type -> { $type.st } ;
|
type -> { $type.st } ;
|
||||||
@ -391,29 +428,41 @@ assignment:
|
|||||||
unary_expression:
|
unary_expression:
|
||||||
//('(' arguments ')' ('[' | '.' | '(')) => primary_or_array_creation_expression
|
//('(' arguments ')' ('[' | '.' | '(')) => primary_or_array_creation_expression
|
||||||
// ^(CAST_EXPR type expression)
|
// ^(CAST_EXPR type expression)
|
||||||
(cast_expression) => cast_expression
|
^(CAST_EXPR type u0=unary_expression) -> cast_expr(type= { $type.st}, exp = { $u0.st})
|
||||||
| primary_or_array_creation_expression -> { $primary_or_array_creation_expression.st }
|
| primary_or_array_creation_expression -> { $primary_or_array_creation_expression.st }
|
||||||
| '+' u1=unary_expression -> template(e={$u1.st}) "+<e>"
|
| ^(MONOPLUS u1=unary_expression) -> template(e={$u1.st}) "+<e>"
|
||||||
| '-' u2=unary_expression -> template(e={$u2.st}) "-<e>"
|
| ^(MONOMINUS u2=unary_expression) -> template(e={$u2.st}) "-<e>"
|
||||||
| '!' u3=unary_expression -> template(e={$u3.st}) "!<e>"
|
| ^(MONONOT u3=unary_expression) -> template(e={$u3.st}) "!<e>"
|
||||||
| '~' u4=unary_expression -> template(e={$u4.st}) "~<e>"
|
| ^(MONOTWIDDLE u4=unary_expression) -> template(e={$u4.st}) "~<e>"
|
||||||
| pre_increment_expression
|
| ^(PREINC u5=unary_expression) -> template(e={$u5.st}) "++<e>"
|
||||||
| pre_decrement_expression
|
| ^(PREDEC u6=unary_expression) -> template(e={$u6.st}) "--<e>"
|
||||||
| pointer_indirection_expression
|
| ^(MONOSTAR unary_expression)
|
||||||
| addressof_expression
|
| ^(ADDRESSOF unary_expression)
|
||||||
;
|
;
|
||||||
cast_expression:
|
|
||||||
^(CAST_EXPR type unary_expression ) -> cast_expr(type= { $type.st}, exp = { $unary_expression.st});
|
// (cast_expression) => cast_expression
|
||||||
assignment_operator:
|
// | primary_or_array_creation_expression -> { $primary_or_array_creation_expression.st }
|
||||||
|
// | '+' u1=unary_expression -> template(e={$u1.st}) "+<e>"
|
||||||
|
// | '-' u2=unary_expression -> template(e={$u2.st}) "-<e>"
|
||||||
|
// | '!' u3=unary_expression -> template(e={$u3.st}) "!<e>"
|
||||||
|
// | '~' u4=unary_expression -> template(e={$u4.st}) "~<e>"
|
||||||
|
// | pre_increment_expression
|
||||||
|
// | pre_decrement_expression
|
||||||
|
// | pointer_indirection_expression
|
||||||
|
// | addressof_expression
|
||||||
|
// ;
|
||||||
|
// cast_expression:
|
||||||
|
// ^(CAST_EXPR type unary_expression ) -> cast_expr(type= { $type.st}, exp = { $unary_expression.st});
|
||||||
|
assignment_operator:
|
||||||
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
||||||
pre_increment_expression:
|
// pre_increment_expression:
|
||||||
'++' unary_expression ;
|
// '++' unary_expression ;
|
||||||
pre_decrement_expression:
|
// pre_decrement_expression:
|
||||||
'--' unary_expression ;
|
// '--' unary_expression ;
|
||||||
pointer_indirection_expression:
|
// pointer_indirection_expression:
|
||||||
'*' unary_expression ;
|
// '*' unary_expression ;
|
||||||
addressof_expression:
|
// addressof_expression:
|
||||||
'&' unary_expression ;
|
// '&' unary_expression ;
|
||||||
|
|
||||||
non_assignment_expression:
|
non_assignment_expression:
|
||||||
//'non ASSIGNment'
|
//'non ASSIGNment'
|
||||||
@ -887,9 +936,14 @@ invocation_part:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// keving: split statement into two parts, there seems to be a problem with the state
|
||||||
|
// machine if we combine statement and statement_plus.
|
||||||
statement:
|
statement:
|
||||||
(declaration_statement) => declaration_statement
|
(declaration_statement) => declaration_statement
|
||||||
| (identifier ':') => labeled_statement
|
| statement_plus
|
||||||
|
;
|
||||||
|
statement_plus:
|
||||||
|
(identifier ':') => labeled_statement
|
||||||
| embedded_statement
|
| embedded_statement
|
||||||
;
|
;
|
||||||
embedded_statement:
|
embedded_statement:
|
||||||
|
@ -36,39 +36,60 @@ modifier:
|
|||||||
| 'readonly' | 'volatile' | 'extern' | 'virtual' | 'override' | FINAL ;
|
| 'readonly' | 'volatile' | 'extern' | 'virtual' | 'override' | FINAL ;
|
||||||
|
|
||||||
class_member_declaration:
|
class_member_declaration:
|
||||||
attributes?
|
^(CONST attributes? modifiers? type constant_declarators)
|
||||||
m=modifiers?
|
| ^(EVENT attributes? modifiers? event_declaration)
|
||||||
( 'const' type constant_declarators ';'
|
| ^(METHOD attributes? modifiers? type method_declaration)
|
||||||
| event_declaration // 'event'
|
| ^(INTERFACE attributes? modifiers? interface_declaration)
|
||||||
| 'partial' (method_declaration
|
| ^(CLASS attributes? modifiers? class_declaration)
|
||||||
| interface_declaration
|
| ^(PROPERTY attributes? modifiers? type property_declaration)
|
||||||
| class_declaration
|
| ^(INDEXER attributes? modifiers? type type_name? indexer_declaration)
|
||||||
| struct_declaration)
|
| ^(FIELD attributes? modifiers? type field_declaration)
|
||||||
| interface_declaration // 'interface'
|
| ^(OPERATOR attributes? modifiers? type operator_declaration)
|
||||||
| 'void' method_declaration
|
| ^(ENUM attributes? modifiers? enum_declaration)
|
||||||
| type ( (member_name '(') => method_declaration
|
| ^(DELEGATE attributes? modifiers? delegate_declaration)
|
||||||
| (member_name '{') => property_declaration
|
| ^(CONSTRUCTOR attributes? modifiers? constructor_declaration)
|
||||||
| (member_name '.' 'this') => type_name '.' indexer_declaration
|
| ^(DESTRUCTOR attributes? modifiers? destructor_declaration)
|
||||||
| indexer_declaration //this
|
;
|
||||||
| field_declaration // qid
|
// class_member_declaration:
|
||||||
| operator_declaration
|
// attributes?
|
||||||
)
|
// m=modifiers?
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// ( 'const' type constant_declarators ';'
|
||||||
|
// | event_declaration // 'event'
|
||||||
| class_declaration // 'class'
|
// | 'partial' (method_declaration
|
||||||
| struct_declaration // 'struct'
|
// | interface_declaration
|
||||||
| enum_declaration // 'enum'
|
// | class_declaration
|
||||||
| delegate_declaration // 'delegate'
|
// | struct_declaration)
|
||||||
| conversion_operator_declaration
|
// | interface_declaration // 'interface'
|
||||||
| constructor_declaration // | static_constructor_declaration
|
// // | 'void' method_declaration
|
||||||
| destructor_declaration
|
// | type ( (member_name '(') => method_declaration
|
||||||
)
|
// | (member_name '{') => property_declaration
|
||||||
;
|
// | (member_name '.' 'this') => type_name '.' indexer_declaration
|
||||||
|
// | indexer_declaration //this
|
||||||
|
// | field_declaration // qid
|
||||||
|
// | operator_declaration
|
||||||
|
// )
|
||||||
|
// // common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
//
|
||||||
|
// | class_declaration // 'class'
|
||||||
|
// | struct_declaration // 'struct'
|
||||||
|
// | enum_declaration // 'enum'
|
||||||
|
// | delegate_declaration // 'delegate'
|
||||||
|
// | conversion_operator_declaration
|
||||||
|
// | constructor_declaration // | static_constructor_declaration
|
||||||
|
// | destructor_declaration
|
||||||
|
// )
|
||||||
|
// ;
|
||||||
|
//
|
||||||
primary_expression:
|
primary_expression:
|
||||||
('this' brackets) => 'this' brackets primary_expression_part*
|
^(INDEX expression expression_list?)
|
||||||
| ('base' brackets) => 'this' brackets primary_expression_part*
|
| ^(APPLY expression argument_list?)
|
||||||
| primary_expression_start primary_expression_part*
|
| ^(POSTINC expression)
|
||||||
|
| ^(POSTDEC expression)
|
||||||
|
| primary_expression_start
|
||||||
|
| ^(access_operator expression type_or_generic)
|
||||||
|
// ('this' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | ('base' brackets) => 'this' brackets primary_expression_part*
|
||||||
|
// | primary_expression_start primary_expression_part*
|
||||||
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
|
||||||
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
|
||||||
// try the simple one first, this has no argS and no expressions
|
// try the simple one first, this has no argS and no expressions
|
||||||
@ -89,7 +110,7 @@ primary_expression_start:
|
|||||||
| identifier ('::' identifier)?
|
| identifier ('::' identifier)?
|
||||||
| 'this'
|
| 'this'
|
||||||
| 'base'
|
| 'base'
|
||||||
| paren_expression
|
| ^(TEMPPARENS expression)
|
||||||
| typeof_expression // typeof(Foo).Name
|
| typeof_expression // typeof(Foo).Name
|
||||||
| literal
|
| literal
|
||||||
;
|
;
|
||||||
@ -157,7 +178,7 @@ primary_or_array_creation_expression:
|
|||||||
;
|
;
|
||||||
// new Type[2] { }
|
// new Type[2] { }
|
||||||
array_creation_expression:
|
array_creation_expression:
|
||||||
'new'
|
^('new'
|
||||||
(type ('[' expression_list ']'
|
(type ('[' expression_list ']'
|
||||||
( rank_specifiers? array_initializer? // new int[4]
|
( rank_specifiers? array_initializer? // new int[4]
|
||||||
// | invocation_part*
|
// | invocation_part*
|
||||||
@ -169,7 +190,7 @@ array_creation_expression:
|
|||||||
| rank_specifier // [,]
|
| rank_specifier // [,]
|
||||||
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
|
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
|
||||||
)
|
)
|
||||||
) ;
|
)) ;
|
||||||
array_initializer:
|
array_initializer:
|
||||||
'{' variable_initializer_list? ','? '}' ;
|
'{' variable_initializer_list? ','? '}' ;
|
||||||
variable_initializer_list:
|
variable_initializer_list:
|
||||||
@ -177,15 +198,15 @@ variable_initializer_list:
|
|||||||
variable_initializer:
|
variable_initializer:
|
||||||
expression | array_initializer ;
|
expression | array_initializer ;
|
||||||
sizeof_expression:
|
sizeof_expression:
|
||||||
'sizeof' '(' unmanaged_type ')';
|
^('sizeof' unmanaged_type );
|
||||||
checked_expression:
|
checked_expression:
|
||||||
'checked' '(' expression ')' ;
|
^('checked' expression ) ;
|
||||||
unchecked_expression:
|
unchecked_expression:
|
||||||
'unchecked' '(' expression ')' ;
|
^('unchecked' expression ) ;
|
||||||
default_value_expression:
|
default_value_expression:
|
||||||
'default' '(' type ')' ;
|
^('default' type ) ;
|
||||||
anonymous_method_expression:
|
anonymous_method_expression:
|
||||||
'delegate' explicit_anonymous_function_signature? block;
|
^('delegate' explicit_anonymous_function_signature? block);
|
||||||
explicit_anonymous_function_signature:
|
explicit_anonymous_function_signature:
|
||||||
'(' explicit_anonymous_function_parameter_list? ')' ;
|
'(' explicit_anonymous_function_parameter_list? ')' ;
|
||||||
explicit_anonymous_function_parameter_list:
|
explicit_anonymous_function_parameter_list:
|
||||||
@ -232,9 +253,7 @@ initializer_value:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
typeof_expression:
|
typeof_expression:
|
||||||
'typeof' '(' ((unbound_type_name) => unbound_type_name
|
^('typeof' (unbound_type_name | type | 'void') ) ;
|
||||||
| type
|
|
||||||
| 'void') ')' ;
|
|
||||||
// unbound type examples
|
// unbound type examples
|
||||||
//foo<bar<X<>>>
|
//foo<bar<X<>>>
|
||||||
//bar::foo<>
|
//bar::foo<>
|
||||||
@ -290,7 +309,7 @@ type_arguments:
|
|||||||
type (',' type)* ;
|
type (',' type)* ;
|
||||||
|
|
||||||
type:
|
type:
|
||||||
^(TYPE (predefined_type | type_name) rank_specifiers? '*'* '?'?);
|
^(TYPE (predefined_type | type_name | 'void') rank_specifiers? '*'* '?'?);
|
||||||
non_nullable_type:
|
non_nullable_type:
|
||||||
type;
|
type;
|
||||||
non_array_type:
|
non_array_type:
|
||||||
@ -331,27 +350,27 @@ unary_expression:
|
|||||||
//(cast_expression) => cast_expression
|
//(cast_expression) => cast_expression
|
||||||
^(CAST_EXPR type unary_expression)
|
^(CAST_EXPR type unary_expression)
|
||||||
| primary_or_array_creation_expression
|
| primary_or_array_creation_expression
|
||||||
| '+' unary_expression
|
| ^(MONOPLUS unary_expression)
|
||||||
| '-' unary_expression
|
| ^(MONOMINUS unary_expression)
|
||||||
| '!' unary_expression
|
| ^(MONONOT unary_expression)
|
||||||
| '~' unary_expression
|
| ^(MONOTWIDDLE unary_expression)
|
||||||
| pre_increment_expression
|
| ^(PREINC unary_expression)
|
||||||
| pre_decrement_expression
|
| ^(PREDEC unary_expression)
|
||||||
| pointer_indirection_expression
|
| ^(MONOSTAR unary_expression)
|
||||||
| addressof_expression
|
| ^(ADDRESSOF unary_expression)
|
||||||
;
|
;
|
||||||
cast_expression:
|
//cast_expression:
|
||||||
'(' type ')' non_assignment_expression ;
|
// '(' type ')' non_assignment_expression ;
|
||||||
assignment_operator:
|
assignment_operator:
|
||||||
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
'=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>' '>=' ;
|
||||||
pre_increment_expression:
|
//pre_increment_expression:
|
||||||
'++' unary_expression ;
|
// '++' unary_expression ;
|
||||||
pre_decrement_expression:
|
//pre_decrement_expression:
|
||||||
'--' unary_expression ;
|
// '--' unary_expression ;
|
||||||
pointer_indirection_expression:
|
//pointer_indirection_expression:
|
||||||
'*' unary_expression ;
|
// '*' unary_expression ;
|
||||||
addressof_expression:
|
//addressof_expression:
|
||||||
'&' unary_expression ;
|
// '&' unary_expression ;
|
||||||
|
|
||||||
non_assignment_expression:
|
non_assignment_expression:
|
||||||
//'non ASSIGNment'
|
//'non ASSIGNment'
|
||||||
@ -834,13 +853,17 @@ invocation_part:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// keving: split statement into two parts, there seems to be a problem with the state
|
||||||
|
// machine if we combine statement and statement_plus. (It fails to recognise dataHelper.Add();)
|
||||||
statement:
|
statement:
|
||||||
(declaration_statement) => declaration_statement
|
(declaration_statement) => declaration_statement
|
||||||
| (identifier ':') => labeled_statement
|
| statement_plus;
|
||||||
| embedded_statement
|
statement_plus:
|
||||||
|
(identifier ':') => labeled_statement
|
||||||
|
| embedded_statement
|
||||||
;
|
;
|
||||||
embedded_statement:
|
embedded_statement:
|
||||||
block
|
block
|
||||||
| selection_statement // if, switch
|
| selection_statement // if, switch
|
||||||
| iteration_statement // while, do, for, foreach
|
| iteration_statement // while, do, for, foreach
|
||||||
| jump_statement // break, continue, goto, return, throw
|
| jump_statement // break, continue, goto, return, throw
|
||||||
|
@ -15,6 +15,32 @@ tokens {
|
|||||||
FINAL; /* final modifier */
|
FINAL; /* final modifier */
|
||||||
IN;
|
IN;
|
||||||
OUT;
|
OUT;
|
||||||
|
CONST;
|
||||||
|
EVENT;
|
||||||
|
METHOD;
|
||||||
|
PROPERTY;
|
||||||
|
INDEXER;
|
||||||
|
FIELD;
|
||||||
|
OPERATOR;
|
||||||
|
ENUM;
|
||||||
|
DELEGATE;
|
||||||
|
CONVERSION_OPERATOR;
|
||||||
|
CONSTRUCTOR;
|
||||||
|
DESTRUCTOR;
|
||||||
|
|
||||||
|
MONOPLUS;
|
||||||
|
MONOMINUS;
|
||||||
|
MONONOT;
|
||||||
|
MONOTWIDDLE;
|
||||||
|
MONOSTAR;
|
||||||
|
ADDRESSOF;
|
||||||
|
PREINC;
|
||||||
|
PREDEC;
|
||||||
|
POSTINC;
|
||||||
|
POSTDEC;
|
||||||
|
TEMPPARENS;
|
||||||
|
INDEX;
|
||||||
|
APPLY;
|
||||||
|
|
||||||
OPEN_BRACKET='[';
|
OPEN_BRACKET='[';
|
||||||
CLOSE_BRACKET=']';
|
CLOSE_BRACKET=']';
|
||||||
@ -35,6 +61,7 @@ tokens {
|
|||||||
PAYLOAD; // carries arbitrary text for the output file
|
PAYLOAD; // carries arbitrary text for the output file
|
||||||
PAYLOAD_LIST;
|
PAYLOAD_LIST;
|
||||||
SEP;
|
SEP;
|
||||||
|
KGHOLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@namespace { RusticiSoftware.Translator.CSharp }
|
@namespace { RusticiSoftware.Translator.CSharp }
|
||||||
@ -115,7 +142,7 @@ class_member_declaration:
|
|||||||
m=modifiers?
|
m=modifiers?
|
||||||
( 'const' type constant_declarators ';'
|
( 'const' type constant_declarators ';'
|
||||||
| event_declaration // 'event'
|
| event_declaration // 'event'
|
||||||
| 'partial' (method_declaration
|
| 'partial' ('void' method_declaration
|
||||||
| interface_declaration
|
| interface_declaration
|
||||||
| class_declaration
|
| class_declaration
|
||||||
| struct_declaration)
|
| struct_declaration)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user