Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7726995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:20:58+00:00 2026-06-01T05:20:58+00:00

I am trying to develop a c# code generator using ANTLR and the StringTemplate

  • 0

I am trying to develop a c# code generator using ANTLR and the StringTemplate library. AntlrWorks can generate the c# parser and lexer files without reporting any errors. However, the c# parser code is not valid and cannot be compiled in visual studio.

Can anyone see what is wrong with the following grammar?

grammar StrucadShape;

options {
    language=CSharp3 ;
   output=template;  

}

@header {using System;}
@lexer::header {using System;} 
@lexer::members {const int HIDDEN = Hidden;}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/  

 public shapedef: parameters_def  
                  -> class_temp( parameters={$parameters_def.st} )
                  ;

 parameters_def : (PARAMETERS LPAREN (p+=param) (COMMA (p+=param))* RPAREN )
                  -> parameter_list(params={$p})
                  ;

param   : IDENTIFIER ->Parameter_decl(p={$IDENTIFIER.text});  

/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/    

fragment EOL:'\r'|'\n'|'\r\n'  ;  


 WS : (' ' 
| '\t' 
| EOL) 
{ $channel = HIDDEN; } ;    

 PARAMETERS: 'PARAMETERS';
   COMMA : ',' ;
   LPAREN : '(' ; 
   RPAREN : ')' ;  

fragment LETTER :('A'..'Z' | 'a'..'z');
IDENTIFIER: LETTER (LETTER|DIGIT)*;
INTEGER : (DIGIT)+ ;
FLOAT   : (DIGIT)+'.'(DIGIT)+;
fragment DIGIT  : '0'..'9' ;

This results in the following lines of code in generated parameters_def() method

List<object> list_p = null;

...snipped some code

if (list_p==null) list_p=new List<StringTemplate>(); 

This is failing on the assignment of the List <StringTemplate> to type List<Object>.
The grammar works before I add the string template rules. The error is introduced when I add the (p+=param) syntax required for list processing in the StringTemplate library.

I’ll add my StringTemplate file for completeness, but I don’t think this could be causing an error as it is not loaded until runtime.

group StrucadShape;

Parameter_decl(p)::= "public double <p> { get; set; }"

parameter_list(params) ::=
<<
start expressions
<params; separator="\n">
end
>>

class_temp(  parameters)::=
<<
public class name
{
    <parameters; separator="\n>  
}
>>

A sample input string PARAMETERS( D,B,T)

Antlr Versions

  • Antlr3.Runtime 3.4.1.9004
  • AntlrWorks 1.4.3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:20:59+00:00Added an answer on June 1, 2026 at 5:20 am

    I found a related issue on the Antlr mailing list here.

    The solution was to add an ASTLabeltype to the grammar options

    options {
        language=CSharp3;   
        output=template;  
        ASTLabelType = StringTemplate;
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a simple kernel using TASM, using this code: ; beroset.asm
I'm trying to develop simple Python (3.2) code to read XML files, do some
I'm trying to develop an application using Google's maps and I can't get this
I'm desperate for a solution to this. I'm trying to develop Assembly code allowing
I have been trying to develop a Core Data piece of code and have
This is the code I'm trying to develop: Public Structure Statistic(Of t) Dim maxStat
I am trying to develop a Wicket-based web application using Hibernate at the model
i'm trying to develop a simple Hello World web service using Axis2 v1.5, Tomcat6
i'm trying to develop a client-server chat application using java servlets and mysql(innoDB engine)
I'm trying to develop code for mpeg/h.264/RTP streaming. I'm quite new to all this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.