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 9268527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:50:18+00:00 2026-06-18T14:50:18+00:00

I am using ANTLRWorks 1.5 for C (ANTLR 3.5). I created a lexer and

  • 0

I am using ANTLRWorks 1.5 for C (ANTLR 3.5).
I created a lexer and parser file.
When trying to generate code, it returns as error <[18:52:50] error(100): Script.g:57:2: syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing EOF>',<-1>,57:1] at options {)>.

Here is the code, please tell what am I missing.

/* ############################## L E X E R ############################ */

grammar Lexer;

options { 

    language = C;
    output = AST; //generating an AST
    ASTLabelType = pANTLT3_BASE_TREE; //specifying a tree walker

    k=1;    // Only 1 lookahead character required

}

// Define string values - either simple unquoted or complex quoted
STRING : ('a'..'z'|'A'..'Z'|'0'..'9'|'_' | '+')+ 
        | ('"' (~'"')* '"');


// Ignore all whitespace
WS :(' ' 
    | '\t' 
    | '\r' '\n' { newline(); } 
    | '\n'      { newline(); }
    ) 
    { $setType(Token.SKIP); } ;

// TODO:Single-line comment
LINE_COMMENT : '/*' (~('\n'|'\r'))* ('\n'|'\r'('\n')?)? 
    { $setType(Token.SKIP); newline(); } ;

// Punctuation     
LBRACE : '<';
RBRACE : '>';
SLASH : '/';
EQUALS : '=';
SEMI : ';';

TRIGGER : ('Trigger');
TRIGGERTYPE : ('Fall') SLASH ('Rise')|('Rise') SLASH ('Fall')|('Fall')|('Rise'); 
DEFAULT : ('Default TimeSet');
TIMESETVAL : ('TSET_')('0..9')*;

 

/* ############################## P A R S E R ############################ */

grammar Script;

options { 
        language=C;
    output=AST;         // Automatically build the AST while parsing
    ASTLabelType=pANTLR3_BASE_TREE;
    //k=2;              // Need lookahead of two for props without keys (to check for the =)
}

/*tokens {
    SCRIPT;             // Imaginary token inserted at the root of the script
    BLOCK;              // Imaginary token inserted at the root of a block
    COMMAND;            // Imaginary token inserted at the root of a command
    PROPERTY;           // Imaginary token inserted at the root of a property
}*/

/** Rule to parse Trigger line
*/

trigger : TRIGGER EQUALS TRIGGERTYPE SEMI;

/** Rule to parse TimeSet line
*/

timeset : DEFAULT TIMESETVAL;
  • 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-18T14:50:19+00:00Added an answer on June 18, 2026 at 2:50 pm

    Your “combined” grammar Lexer only has lexer rules, while when you only define grammar, ANTLR expects at least 1 parser rule.

    There are 3 different types of grammars

    • combined grammar: grammar Foo, generates:
      • class FooParser extends Parser and
      • class FooLexer extends Lexer
    • parser grammar: parser grammar Bar, generates:
      • class Bar extends Parser
    • lexer grammar: lexer grammar Baz, generates:
      • class Baz extends Lexer

    So, in your case, change grammar Lexer; into lexer grammar ScriptLexer; (don’t name your lexer grammar Lexer since it is the base lexer class in ANTLR!) and import this lexer in your parser grammar:

    parser grammar ScriptParser;
    
    import ScriptLexer;    
    
    options { 
      language=C;
      output=AST;
      ASTLabelType=pANTLR3_BASE_TREE;
    }
    
    // ...
    

    Related:

    • ANTLR3 Wiki: Composite Grammars
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ANTLRWorks 1.4.3 together with ANTLR 3.4 to generate a Java-based parser
Using this is very helpful when trying to generate html code in c#. var
I am using ANTLR 3.1.3 to generate the parser. After importing the generated testParser,
I'm able to successfully generate C# code (CSharp2) for my grammar written using ANTLRWorks.
I'm trying to update a file in an existing jar (in this example antlr)
Using this code, the following execution yields strange results: C 100 R W The
I examine heterogeneous trees in ANTLR (using ANTLRWorks 1.4.2). Here is the example of
Recently I tried to write ANTLR grammar file (.g) using the ANTLR Editor for
I am trying build an AST for the below grammer using ANTLR condition_in :
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.

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.