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

  • SEARCH
  • Home
  • 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 790361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:40:11+00:00 2026-05-14T21:40:11+00:00

I need a little guidance in writing a grammar to parse the log file

  • 0

I need a little guidance in writing a grammar to parse the log file of the game Aion. I’ve decided upon using Antlr3 (because it seems to be a tool that can do the job and I figured it’s good for me to learn to use it). However, I’ve run into problems because the log file is not exactly structured.

The log file I need to parse looks like the one below:

2010.04.27 22:32:22 : You changed the connection status to Online. 
2010.04.27 22:32:22 : You changed the group to the Solo state. 
2010.04.27 22:32:22 : You changed the group to the Solo state. 
2010.04.27 22:32:28 : Legion Message: www.xxxxxxxx.com (forum)



ventrillo: 19x.xxx.xxx.xxx

Port: 3712

Pass: xxxx (blabla) 

 4/27/2010 7:47 PM 
2010.04.27 22:32:28 : You have item(s) left to settle in the sales agency window.

As you can see, most lines start with a timestamp, but there are exceptions. What I’d like to do in Antlr3 is write a parser that uses only the lines starting with the timestamp while silently discarding the others.

This is what I’ve written so far (I’m a beginner with these things so please don’t laugh :D)

grammar Antlr;

options {
  language = Java;
}

logfile: line* EOF;

line : dataline | textline;

dataline: timestamp WS ':' WS text NL ;
textline: ~DIG text NL;

timestamp: four_dig '.' two_dig '.' two_dig WS two_dig ':' two_dig ':' two_dig ;

four_dig: DIG DIG DIG DIG;
two_dig: DIG DIG;

text: ~NL+;

/* Whitespace */ 
WS: (' ' | '\t')+;

/* New line goes to \r\n or EOF */
NL: '\r'? '\n' ;

/* Digits */
DIG : '0'..'9'; 

So what I need is an example of how to parse this without generating errors for lines without the timestamp.

Thanks!

  • 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-05-14T21:40:11+00:00Added an answer on May 14, 2026 at 9:40 pm

    No one is going to laugh. In fact, you did a pretty good job for a first try. Of course, there’s room for improvement! 🙂

    First some remarks: you can only negate single characters. Since your NL rule can possibly consist of two characters, you can’t negate it. Also, when negating from within your parser rule(s), you don’t negate single characters, but you’re negating lexer rules. This may sound a bit confusing so let me clarify with an example. Take the combined (parser & lexer) grammar T:

    grammar T;
    
    // parser rule
    foo
      :  ~A
      ;
    
    // lexer rules
    A
      :  'a'
      ;
    
    B
      :  'b'
      ;
    
    C
      :  'c'
      ;
    

    As you can see, I’m negating the A lexer-rule in the foo parser-rule. The foo rule does now not match any character except the 'a', but it matches any lexer rule except A. In other words, it will only match a 'b' or 'c' character.

    Also, you don’t need to put:

    options {
      language = Java;
    }
    

    in your grammar: the default target is Java (it does not hurt to leave it in there of course).

    Now, in your grammar, you can already make a distinction between data– and text-lines in your lexer grammar. Here’s a possible way to do so:

    logfile
      :  line+
      ;
    
    line
      :  dataline 
      |  textline
      ;
    
    dataline
      :  DataLine
      ;
    
    textline
      :  TextLine
      ;
    
    DataLine
      :  TwoDigits TwoDigits '.' TwoDigits '.' TwoDigits Space+ TwoDigits ':' TwoDigits ':' TwoDigits Space+ ':' TextLine
      ;
    
    TextLine
      :  ~('\r' | '\n')* (NewLine | EOF)
      ;
    
    fragment
    NewLine
      :  '\r'? '\n'
      |  '\r'
      ;
    
    fragment
    TwoDigits
      :  '0'..'9' '0'..'9'
      ;
    
    fragment
    Space
      :  ' ' 
      |  '\t'
      ;
    

    Note that the fragment part in the lexer rules mean that no tokens are being created from those rules: they are only used in other lexer rules. So the lexer will only create two different type of tokens: DataLine‘s and TextLine‘s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little nmake makefile for my build process. The file types are
I need a little help getting a tar file to download from a website.
I need a little guidance here... I have 2 links: <div class=tarjBodyHolder> <div class=imageHolder>
I'm trying to debug my heroku app and I need a little guidance. Everything
I'm creating a chat application and I need a little bit of guidance. I
I need a little help with a Random Number Guessing Game in visual studio.
I need little help for url rewriting in wordpress. basically what i need: mydomain.com/mysomewordpresspost
I would need little help here. I'm trying to get the git respository from
Need a little help with a SQL / ActiveRecord query. Let's say I have
Need a little help with my jquery here I want all my button with

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.