From cff39602ec32d2b7fcaf1dcdea97bc290276d6d1 Mon Sep 17 00:00:00 2001 From: Johannes Luber Date: Wed, 26 Jan 2011 13:22:40 -0800 Subject: [PATCH] [C#] Additional changes to be able to compile files. [git-p4: depot-paths = "//depot/code/examples-v3/": change = 7531] --- csharp/ANTLR/ANTLRv3.g | 1 + csharp/ANTLR/ANTLRv3Tree.g | 1 + csharp/C/C.g | 1 + csharp/LL-star/SimpleC.g | 1 + csharp/cminus/CMinus.g | 1 + csharp/cminus/Main.cs | 2 +- csharp/composite-java/Java.g | 1 + csharp/composite-java/JavaAnnotations.g | 15 ++++++ csharp/composite-java/JavaDecl.g | 66 +++++++++++++++++++++++- csharp/composite-java/JavaExpr.g | 40 +++++++++++++- csharp/composite-java/JavaLexerRules.g | 12 +++++ csharp/composite-java/JavaStat.g | 16 ++++++ csharp/dynamic-scope/T.g | 1 + csharp/fuzzy/FuzzyJava.g | 1 + csharp/hoistedPredicates/T.g | 1 + csharp/import/Simple.g | 1 + csharp/island-grammar/Javadoc.g | 1 + csharp/island-grammar/Simple.g | 2 + csharp/java-from-v2/Java.g | 1 + csharp/java/Java.g | 1 + csharp/polydiff/Main.cs | 2 +- csharp/polydiff/Poly.g | 1 + csharp/polydiff/PolyDifferentiator.g | 1 + csharp/polydiff/PolyPrinter.g | 1 + csharp/polydiff/Simplifier.g | 1 + csharp/python/Python.g | 1 + csharp/ruby/Ruby.g | 1 + csharp/scopes/SymtabTest.g | 1 + csharp/simplecTreeParser/SimpleC.g | 1 + csharp/simplecTreeParser/SimpleCWalker.g | 1 + csharp/treeparser/Lang.g | 1 + csharp/treeparser/LangDumpDecl.g | 3 +- 32 files changed, 175 insertions(+), 6 deletions(-) diff --git a/csharp/ANTLR/ANTLRv3.g b/csharp/ANTLR/ANTLRv3.g index 2814828..ee97256 100644 --- a/csharp/ANTLR/ANTLRv3.g +++ b/csharp/ANTLR/ANTLRv3.g @@ -81,6 +81,7 @@ tokens { int gtype; } +public grammarDef : DOC_COMMENT? ( 'lexer' {gtype=LEXER_GRAMMAR;} // pure lexer diff --git a/csharp/ANTLR/ANTLRv3Tree.g b/csharp/ANTLR/ANTLRv3Tree.g index 2895dc1..d6f981c 100644 --- a/csharp/ANTLR/ANTLRv3Tree.g +++ b/csharp/ANTLR/ANTLRv3Tree.g @@ -36,6 +36,7 @@ options { ASTLabelType = CommonTree; } +public grammarDef : ^( grammarType ID DOC_COMMENT? optionsSpec? tokensSpec? attrScope* action* rule+ ) ; diff --git a/csharp/C/C.g b/csharp/C/C.g index 423e7c9..92090f0 100644 --- a/csharp/C/C.g +++ b/csharp/C/C.g @@ -73,6 +73,7 @@ bool isTypeName(string name) } } +public translation_unit scope Symbols; // entire file is a scope @init { diff --git a/csharp/LL-star/SimpleC.g b/csharp/LL-star/SimpleC.g index 471f4d9..cb1b070 100644 --- a/csharp/LL-star/SimpleC.g +++ b/csharp/LL-star/SimpleC.g @@ -5,6 +5,7 @@ options language=CSharp2; } +public program : declaration+ ; diff --git a/csharp/cminus/CMinus.g b/csharp/cminus/CMinus.g index 9009daf..4ad8530 100644 --- a/csharp/cminus/CMinus.g +++ b/csharp/cminus/CMinus.g @@ -20,6 +20,7 @@ scope slist { @header { } +public program scope { IList globals; diff --git a/csharp/cminus/Main.cs b/csharp/cminus/Main.cs index c3c6181..9c08bac 100644 --- a/csharp/cminus/Main.cs +++ b/csharp/cminus/Main.cs @@ -50,7 +50,7 @@ public static void Main(string[] args) CommonTokenStream tokens = new CommonTokenStream(lexer); CMinusParser parser = new CMinusParser(tokens); parser.TemplateLib = templates; - RuleReturnScope r = parser.program(); + CMinusParser.program_return r = parser.program(); Console.Out.WriteLine(r.Template.ToString()); } else diff --git a/csharp/composite-java/Java.g b/csharp/composite-java/Java.g index 9944eea..3f3a80d 100644 --- a/csharp/composite-java/Java.g +++ b/csharp/composite-java/Java.g @@ -18,6 +18,7 @@ import JavaDecl, JavaAnnotations, JavaExpr, JavaStat, JavaLexerRules; // starting point for parsing a java file /* The annotations are separated out to make parsing faster, but must be associated with a packageDeclaration or a typeDeclaration (and not an empty one). */ +public compilationUnit : annotations ( packageDeclaration importDeclaration* typeDeclaration* diff --git a/csharp/composite-java/JavaAnnotations.g b/csharp/composite-java/JavaAnnotations.g index b2ce453..f833af3 100644 --- a/csharp/composite-java/JavaAnnotations.g +++ b/csharp/composite-java/JavaAnnotations.g @@ -2,48 +2,59 @@ parser grammar JavaAnnotations; // ANNOTATIONS +public annotations : annotation+ ; +public annotation : '@' annotationName ( '(' ( elementValuePairs | elementValue )? ')' )? ; +public annotationName : Identifier ('.' Identifier)* ; +public elementValuePairs : elementValuePair (',' elementValuePair)* ; +public elementValuePair : Identifier '=' elementValue ; +public elementValue : conditionalExpression | annotation | elementValueArrayInitializer ; +public elementValueArrayInitializer : '{' (elementValue (',' elementValue)*)? (',')? '}' ; +public annotationTypeDeclaration : '@' 'interface' Identifier annotationTypeBody ; +public annotationTypeBody : '{' (annotationTypeElementDeclaration)* '}' ; +public annotationTypeElementDeclaration : modifiers annotationTypeElementRest ; +public annotationTypeElementRest : type annotationMethodOrConstantRest ';' | normalClassDeclaration ';'? @@ -52,19 +63,23 @@ annotationTypeElementRest | annotationTypeDeclaration ';'? ; +public annotationMethodOrConstantRest : annotationMethodRest | annotationConstantRest ; +public annotationMethodRest : Identifier '(' ')' defaultValue? ; +public annotationConstantRest : variableDeclarators ; +public defaultValue : 'default' elementValue ; diff --git a/csharp/composite-java/JavaDecl.g b/csharp/composite-java/JavaDecl.g index 77aec0c..039d278 100644 --- a/csharp/composite-java/JavaDecl.g +++ b/csharp/composite-java/JavaDecl.g @@ -1,26 +1,32 @@ parser grammar JavaDecl; +public packageDeclaration : 'package' qualifiedName ';' ; +public importDeclaration : 'import' 'static'? qualifiedName ('.' '*')? ';' ; +public typeDeclaration : classOrInterfaceDeclaration | ';' ; +public classOrInterfaceDeclaration : classOrInterfaceModifiers (classDeclaration | interfaceDeclaration) ; +public classOrInterfaceModifiers : classOrInterfaceModifier* ; +public classOrInterfaceModifier : annotation // class or interface | 'public' // class or interface @@ -32,15 +38,18 @@ classOrInterfaceModifier | 'strictfp' // class or interface ; +public modifiers : modifier* ; +public classDeclaration : normalClassDeclaration | enumDeclaration ; +public normalClassDeclaration : 'class' Identifier typeParameters? ('extends' type)? @@ -48,65 +57,80 @@ normalClassDeclaration classBody ; +public typeParameters : '<' typeParameter (',' typeParameter)* '>' ; +public typeParameter : Identifier ('extends' typeBound)? ; +public typeBound : type ('&' type)* ; +public enumDeclaration : ENUM Identifier ('implements' typeList)? enumBody ; +public enumBody : '{' enumConstants? ','? enumBodyDeclarations? '}' ; +public enumConstants : enumConstant (',' enumConstant)* ; +public enumConstant : annotations? Identifier arguments? classBody? ; +public enumBodyDeclarations : ';' (classBodyDeclaration)* ; +public interfaceDeclaration : normalInterfaceDeclaration | annotationTypeDeclaration ; +public normalInterfaceDeclaration : 'interface' Identifier typeParameters? ('extends' typeList)? interfaceBody ; +public typeList : type (',' type)* ; +public classBody : '{' classBodyDeclaration* '}' ; +public interfaceBody : '{' interfaceBodyDeclaration* '}' ; +public classBodyDeclaration : ';' | 'static'? block | modifiers memberDecl ; +public memberDecl : genericMethodOrConstructorDecl | memberDeclaration @@ -116,32 +140,39 @@ memberDecl | classDeclaration ; +public memberDeclaration : type (methodDeclaration | fieldDeclaration) ; +public genericMethodOrConstructorDecl : typeParameters genericMethodOrConstructorRest ; +public genericMethodOrConstructorRest : (type | 'void') Identifier methodDeclaratorRest | Identifier constructorDeclaratorRest ; +public methodDeclaration : Identifier methodDeclaratorRest ; +public fieldDeclaration : variableDeclarators ';' ; +public interfaceBodyDeclaration : modifiers interfaceMemberDecl | ';' ; +public interfaceMemberDecl : interfaceMethodOrFieldDecl | interfaceGenericMethodDecl @@ -150,15 +181,18 @@ interfaceMemberDecl | classDeclaration ; +public interfaceMethodOrFieldDecl : type Identifier interfaceMethodOrFieldRest ; +public interfaceMethodOrFieldRest : constantDeclaratorsRest ';' | interfaceMethodDeclaratorRest ; +public methodDeclaratorRest : formalParameters ('[' ']')* ('throws' qualifiedNameList)? @@ -167,6 +201,7 @@ methodDeclaratorRest ) ; +public voidMethodDeclaratorRest : formalParameters ('throws' qualifiedNameList)? ( methodBody @@ -174,56 +209,69 @@ voidMethodDeclaratorRest ) ; +public interfaceMethodDeclaratorRest : formalParameters ('[' ']')* ('throws' qualifiedNameList)? ';' ; +public interfaceGenericMethodDecl : typeParameters (type | 'void') Identifier interfaceMethodDeclaratorRest ; +public voidInterfaceMethodDeclaratorRest : formalParameters ('throws' qualifiedNameList)? ';' ; +public constructorDeclaratorRest : formalParameters ('throws' qualifiedNameList)? constructorBody ; +public constantDeclarator : Identifier constantDeclaratorRest ; +public variableDeclarators : variableDeclarator (',' variableDeclarator)* ; +public variableDeclarator : variableDeclaratorId ('=' variableInitializer)? ; +public constantDeclaratorsRest : constantDeclaratorRest (',' constantDeclarator)* ; +public constantDeclaratorRest : ('[' ']')* '=' variableInitializer ; +public variableDeclaratorId : Identifier ('[' ']')* ; +public variableInitializer : arrayInitializer | expression ; +public arrayInitializer : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}' ; +public modifier : annotation | 'public' @@ -239,27 +287,33 @@ modifier | 'strictfp' ; +public packageOrTypeName : qualifiedName ; +public enumConstantName : Identifier ; +public typeName : qualifiedName ; +public type : classOrInterfaceType ('[' ']')* | primitiveType ('[' ']')* ; +public classOrInterfaceType : Identifier typeArguments? ('.' Identifier typeArguments? )* ; +public primitiveType : 'boolean' | 'char' @@ -271,51 +325,61 @@ primitiveType | 'double' ; +public variableModifier : 'final' | annotation ; +public typeArguments : '<' typeArgument (',' typeArgument)* '>' ; +public typeArgument : type | '?' (('extends' | 'super') type)? ; +public qualifiedNameList : qualifiedName (',' qualifiedName)* ; +public formalParameters : '(' formalParameterDecls? ')' ; +public formalParameterDecls : variableModifiers type formalParameterDeclsRest ; +public formalParameterDeclsRest : variableDeclaratorId (',' formalParameterDecls)? | '...' variableDeclaratorId ; +public methodBody : block ; +public constructorBody : '{' explicitConstructorInvocation? blockStatement* '}' ; +public explicitConstructorInvocation : nonWildcardTypeArguments? ('this' | 'super') arguments ';' | primary '.' nonWildcardTypeArguments? 'super' arguments ';' ; - +public qualifiedName : Identifier ('.' Identifier)* ; diff --git a/csharp/composite-java/JavaExpr.g b/csharp/composite-java/JavaExpr.g index 27f40cc..d839f1a 100644 --- a/csharp/composite-java/JavaExpr.g +++ b/csharp/composite-java/JavaExpr.g @@ -1,25 +1,31 @@ parser grammar JavaExpr; +public parExpression : '(' expression ')' ; +public expressionList : expression (',' expression)* ; +public statementExpression : expression ; +public constantExpression : expression ; +public expression : conditionalExpression (assignmentOperator expression)? ; +public assignmentOperator : '=' | '+=' @@ -49,42 +55,52 @@ assignmentOperator $t2.CharPositionInLine + 1 == $t3.CharPositionInLine }? ; +public conditionalExpression : conditionalOrExpression ( '?' expression ':' expression )? ; +public conditionalOrExpression : conditionalAndExpression ( '||' conditionalAndExpression )* ; +public conditionalAndExpression : inclusiveOrExpression ( '&&' inclusiveOrExpression )* ; +public inclusiveOrExpression : exclusiveOrExpression ( '|' exclusiveOrExpression )* ; +public exclusiveOrExpression : andExpression ( '^' andExpression )* ; +public andExpression : equalityExpression ( '&' equalityExpression )* ; +public equalityExpression : instanceOfExpression ( ('==' | '!=') instanceOfExpression )* ; +public instanceOfExpression : relationalExpression ('instanceof' type)? ; +public relationalExpression : shiftExpression ( relationalOp shiftExpression )* ; +public relationalOp : ('<' '=')=> t1='<' t2='=' { $t1.Line == $t2.Line && @@ -96,10 +112,12 @@ relationalOp | '>' ; +public shiftExpression : additiveExpression ( shiftOp additiveExpression )* ; +public shiftOp : ('<' '<')=> t1='<' t2='<' { $t1.Line == $t2.Line && @@ -114,15 +132,17 @@ shiftOp $t1.CharPositionInLine + 1 == $t2.CharPositionInLine }? ; - +public additiveExpression : multiplicativeExpression ( ('+' | '-') multiplicativeExpression )* ; +public multiplicativeExpression : unaryExpression ( ( '*' | '/' | '%' ) unaryExpression )* ; +public unaryExpression : '+' unaryExpression | '-' unaryExpression @@ -131,6 +151,7 @@ unaryExpression | unaryExpressionNotPlusMinus ; +public unaryExpressionNotPlusMinus : '~' unaryExpression | '!' unaryExpression @@ -138,11 +159,13 @@ unaryExpressionNotPlusMinus | primary selector* ('++'|'--')? ; +public castExpression : '(' primitiveType ')' unaryExpression | '(' (type | expression) ')' unaryExpressionNotPlusMinus ; +public primary : parExpression | 'this' ('.' Identifier)* identifierSuffix? @@ -154,6 +177,7 @@ primary | 'void' '.' 'class' ; +public identifierSuffix : ('[' ']')+ '.' 'class' | ('[' expression ']')+ // can also be matched by selector, but do here @@ -165,20 +189,24 @@ identifierSuffix | '.' 'new' innerCreator ; +public creator : nonWildcardTypeArguments createdName classCreatorRest | createdName (arrayCreatorRest | classCreatorRest) ; +public createdName : classOrInterfaceType | primitiveType ; +public innerCreator : nonWildcardTypeArguments? Identifier classCreatorRest ; +public arrayCreatorRest : '[' ( ']' ('[' ']')* arrayInitializer @@ -186,18 +214,22 @@ arrayCreatorRest ) ; +public classCreatorRest : arguments classBody? ; +public explicitGenericInvocation : nonWildcardTypeArguments Identifier arguments ; +public nonWildcardTypeArguments : '<' typeList '>' ; +public selector : '.' Identifier arguments? | '.' 'this' @@ -206,15 +238,18 @@ selector | '[' expression ']' ; +public superSuffix : arguments | '.' Identifier arguments? ; +public arguments : '(' expressionList? ')' ; +public literal : integerLiteral | FloatingPointLiteral @@ -224,14 +259,15 @@ literal | 'null' ; +public integerLiteral : HexLiteral | OctalLiteral | DecimalLiteral ; +public booleanLiteral : 'true' | 'false' ; - diff --git a/csharp/composite-java/JavaLexerRules.g b/csharp/composite-java/JavaLexerRules.g index 409ee0d..096d510 100644 --- a/csharp/composite-java/JavaLexerRules.g +++ b/csharp/composite-java/JavaLexerRules.g @@ -8,10 +8,13 @@ protected bool assertIsKeyword = true; } +public HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ; +public DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ; +public OctalLiteral : '0' ('0'..'7')+ IntegerTypeSuffix? ; fragment @@ -20,6 +23,7 @@ HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ; fragment IntegerTypeSuffix : ('l'|'L') ; +public FloatingPointLiteral : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix? | '.' ('0'..'9')+ Exponent? FloatTypeSuffix? @@ -33,10 +37,12 @@ Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; fragment FloatTypeSuffix : ('f'|'F'|'d'|'D') ; +public CharacterLiteral : '\'' ( EscapeSequence | ~('\''|'\\') ) '\'' ; +public StringLiteral : '"' ( EscapeSequence | ~('\\'|'"') )* '"' ; @@ -60,13 +66,16 @@ UnicodeEscape : '\\' 'u' HexDigit HexDigit HexDigit HexDigit ; +public ENUM: 'enum' {if (!enumIsKeyword) $type=Identifier;} ; +public ASSERT : 'assert' {if (!assertIsKeyword) $type=Identifier;} ; +public Identifier : Letter (Letter|JavaIDDigit)* ; @@ -110,13 +119,16 @@ JavaIDDigit '\u1040'..'\u1049' ; +public WS : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=Hidden;} ; +public COMMENT : '/*' ( options {greedy=false;} : . )* '*/' {$channel=Hidden;} ; +public LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=Hidden;} ; diff --git a/csharp/composite-java/JavaStat.g b/csharp/composite-java/JavaStat.g index 364fffb..91fb3d7 100644 --- a/csharp/composite-java/JavaStat.g +++ b/csharp/composite-java/JavaStat.g @@ -1,27 +1,33 @@ parser grammar JavaStat; +public block : '{' blockStatement* '}' ; +public blockStatement : localVariableDeclarationStatement | classOrInterfaceDeclaration | statement ; +public localVariableDeclarationStatement : localVariableDeclaration ';' ; +public localVariableDeclaration : variableModifiers type variableDeclarators ; +public variableModifiers : variableModifier* ; +public statement : block | ASSERT expression (':' expression)? ';' @@ -45,18 +51,22 @@ statement | Identifier ':' statement ; +public catches : catchClause (catchClause)* ; +public catchClause : 'catch' '(' formalParameter ')' block ; +public formalParameter : variableModifiers type variableDeclaratorId ; +public switchBlockStatementGroups : (switchBlockStatementGroup)* ; @@ -65,31 +75,37 @@ switchBlockStatementGroups ambiguous; but with appropriately greedy parsing it yields the most appropriate AST, one in which each group, except possibly the last one, has labels and statements. */ +public switchBlockStatementGroup : switchLabel+ blockStatement* ; +public switchLabel : 'case' constantExpression ':' | 'case' enumConstantName ':' | 'default' ':' ; +public forControl options {k=3;} // be efficient for common case: for (ID ID : ID) ... : enhancedForControl | forInit? ';' expression? ';' forUpdate? ; +public forInit : localVariableDeclaration | expressionList ; +public enhancedForControl : variableModifiers type Identifier ':' expression ; +public forUpdate : expressionList ; diff --git a/csharp/dynamic-scope/T.g b/csharp/dynamic-scope/T.g index 3d6a63e..d0bea74 100644 --- a/csharp/dynamic-scope/T.g +++ b/csharp/dynamic-scope/T.g @@ -4,6 +4,7 @@ options { language=CSharp2; } +public program : method ; method diff --git a/csharp/fuzzy/FuzzyJava.g b/csharp/fuzzy/FuzzyJava.g index acf9456..6df7f83 100644 --- a/csharp/fuzzy/FuzzyJava.g +++ b/csharp/fuzzy/FuzzyJava.g @@ -4,6 +4,7 @@ options { language=CSharp2; } +public IMPORT : 'import' WS name=QIDStar WS? ';' ; diff --git a/csharp/hoistedPredicates/T.g b/csharp/hoistedPredicates/T.g index 5664849..f58c5fb 100644 --- a/csharp/hoistedPredicates/T.g +++ b/csharp/hoistedPredicates/T.g @@ -19,6 +19,7 @@ options { bool enableEnum = false; } +public stat: identifier {Console.Out.WriteLine("enum is an ID");} | enumAsKeyword {Console.Out.WriteLine("enum is a keyword");} ; diff --git a/csharp/import/Simple.g b/csharp/import/Simple.g index 8b4f316..83e9fb7 100644 --- a/csharp/import/Simple.g +++ b/csharp/import/Simple.g @@ -6,6 +6,7 @@ options { // pull in all rules even if not referenced so comments etc... work import CommonLexer; +public file : 'program' ID ';' {Console.Out.WriteLine("found program "+$ID.Text);} decl+ ; diff --git a/csharp/island-grammar/Javadoc.g b/csharp/island-grammar/Javadoc.g index 2b3d2eb..7cbe2fe 100644 --- a/csharp/island-grammar/Javadoc.g +++ b/csharp/island-grammar/Javadoc.g @@ -6,6 +6,7 @@ options { @namespace {Antlr.Examples.IslandGrammar} +public comment : ( author )* ; author : '@author' ID {Console.Out.WriteLine("author "+$ID.Text);} ; diff --git a/csharp/island-grammar/Simple.g b/csharp/island-grammar/Simple.g index 32a9603..7834189 100644 --- a/csharp/island-grammar/Simple.g +++ b/csharp/island-grammar/Simple.g @@ -45,6 +45,7 @@ public static int nesting = 0; * I go off to recognize javadoc comments, the lookahead for the Simple * parser is not messed up in any way. */ +public program : (variable)* (method)+ ; @@ -60,6 +61,7 @@ block : '{' '}' ; +public statement : ID '=' expr ';' {Console.Out.WriteLine("assignment to "+$ID.Text);} | 'return' expr ';' diff --git a/csharp/java-from-v2/Java.g b/csharp/java-from-v2/Java.g index 3e842ae..887926e 100644 --- a/csharp/java-from-v2/Java.g +++ b/csharp/java-from-v2/Java.g @@ -27,6 +27,7 @@ public static readonly CommonToken IGNORE_TOKEN = new CommonToken(null,0,99,0,0) // Compilation Unit: In Java, this is a single file. This is the start // rule for this parser +public compilationUnit : // A compilation unit starts with an optional package definition ( packageDefinition diff --git a/csharp/java/Java.g b/csharp/java/Java.g index 84f08b3..8357c01 100644 --- a/csharp/java/Java.g +++ b/csharp/java/Java.g @@ -194,6 +194,7 @@ protected bool assertIsKeyword = true; // starting point for parsing a java file /* The annotations are separated out to make parsing faster, but must be associated with a packageDeclaration or a typeDeclaration (and not an empty one). */ +public compilationUnit : annotations ( packageDeclaration importDeclaration* typeDeclaration* diff --git a/csharp/polydiff/Main.cs b/csharp/polydiff/Main.cs index 23ee1c3..f480411 100644 --- a/csharp/polydiff/Main.cs +++ b/csharp/polydiff/Main.cs @@ -42,6 +42,6 @@ public static void Main(string[] args) nodes.TokenStream = tokens; PolyPrinter printer = new PolyPrinter(nodes); PolyPrinter.poly_return r4 = printer.poly(); - Console.Out.WriteLine(r4.ST); + Console.Out.WriteLine(r4.Template); } } } diff --git a/csharp/polydiff/Poly.g b/csharp/polydiff/Poly.g index 21f5d42..e22c911 100644 --- a/csharp/polydiff/Poly.g +++ b/csharp/polydiff/Poly.g @@ -10,6 +10,7 @@ tokens { MULT; } // imaginary token #pragma warning disable 0219 } +public poly: term ('+'^ term)* ; diff --git a/csharp/polydiff/PolyDifferentiator.g b/csharp/polydiff/PolyDifferentiator.g index 1a6d620..d2f86c1 100644 --- a/csharp/polydiff/PolyDifferentiator.g +++ b/csharp/polydiff/PolyDifferentiator.g @@ -11,6 +11,7 @@ options { #pragma warning disable 0219 } +public poly: ^('+' poly poly) | ^(MULT INT ID) -> INT | ^(MULT c=INT ^('^' ID e=INT)) diff --git a/csharp/polydiff/PolyPrinter.g b/csharp/polydiff/PolyPrinter.g index d326731..80f391d 100644 --- a/csharp/polydiff/PolyPrinter.g +++ b/csharp/polydiff/PolyPrinter.g @@ -6,6 +6,7 @@ options { output=template; } +public poly: ^('+' a=poly b=poly) -> template(a={$a.st},b={$b.st}) "+" | ^(MULT a=poly b=poly) -> template(a={$a.st},b={$b.st}) "" | ^('^' a=poly b=poly) -> template(a={$a.st},b={$b.st}) "^" diff --git a/csharp/polydiff/Simplifier.g b/csharp/polydiff/Simplifier.g index 022fd82..cb29a1e 100644 --- a/csharp/polydiff/Simplifier.g +++ b/csharp/polydiff/Simplifier.g @@ -17,6 +17,7 @@ options { * perfect. We'd need to run the tree into this until nothing * changed to make it correct. */ +public poly: ^('+' a=INT b=INT) -> INT["" + ($a.int + $b.int)] | ^('+' ^('+' a=INT p=poly) b=INT) diff --git a/csharp/python/Python.g b/csharp/python/Python.g index 3f2ff7f..cf08dbd 100644 --- a/csharp/python/Python.g +++ b/csharp/python/Python.g @@ -85,6 +85,7 @@ single_input | compound_stmt NEWLINE ; +public file_input : (NEWLINE | stmt)* ; diff --git a/csharp/ruby/Ruby.g b/csharp/ruby/Ruby.g index ed91eda..7d672ff 100644 --- a/csharp/ruby/Ruby.g +++ b/csharp/ruby/Ruby.g @@ -12,6 +12,7 @@ options { backtrack=true; } +public program : compoundstmt | classdef diff --git a/csharp/scopes/SymtabTest.g b/csharp/scopes/SymtabTest.g index 308ceb0..fa068cb 100644 --- a/csharp/scopes/SymtabTest.g +++ b/csharp/scopes/SymtabTest.g @@ -26,6 +26,7 @@ private string ListToSTring(List list) { } } +public prog: globals (method)* ; diff --git a/csharp/simplecTreeParser/SimpleC.g b/csharp/simplecTreeParser/SimpleC.g index 8de3a19..27b29d7 100644 --- a/csharp/simplecTreeParser/SimpleC.g +++ b/csharp/simplecTreeParser/SimpleC.g @@ -14,6 +14,7 @@ tokens { BLOCK; } +public program : declaration+ ; diff --git a/csharp/simplecTreeParser/SimpleCWalker.g b/csharp/simplecTreeParser/SimpleCWalker.g index 87adae8..d09ced1 100644 --- a/csharp/simplecTreeParser/SimpleCWalker.g +++ b/csharp/simplecTreeParser/SimpleCWalker.g @@ -6,6 +6,7 @@ options { ASTLabelType=CommonTree; } +public program : declaration+ ; diff --git a/csharp/treeparser/Lang.g b/csharp/treeparser/Lang.g index 1c612e4..e2130e7 100644 --- a/csharp/treeparser/Lang.g +++ b/csharp/treeparser/Lang.g @@ -7,6 +7,7 @@ options { tokens {DECL;} // an imaginary node +public start : decl ; decl : type ID ';' -> ^(DECL type ID) diff --git a/csharp/treeparser/LangDumpDecl.g b/csharp/treeparser/LangDumpDecl.g index aac40b8..7dc0761 100644 --- a/csharp/treeparser/LangDumpDecl.g +++ b/csharp/treeparser/LangDumpDecl.g @@ -1,10 +1,11 @@ tree grammar LangDumpDecl; options { tokenVocab=Lang; - ASTLabelType = Tree; + ASTLabelType = ITree; language=CSharp2; } +public decl : ^(DECL type declarator) // label.start, label.start, label.text {Console.Out.WriteLine("int "+$declarator.text);}