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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:03:00+00:00 2026-05-30T23:03:00+00:00

I’m just getting to grips with ParseKit, read the Basic Grammar Syntax but it’s

  • 0

I’m just getting to grips with ParseKit, read the “Basic Grammar Syntax” but it’s only a very basic introduction. I’m quickly out of my depth now that I want to set about defining my own grammar. Where do I go from here?

For example, I want to parse a log file in a very custom format. Breaking it down to header, body and footer, this would be my BNF for first line of the header:

<header-line-1> ::= <log-format> <log-id> "," <category> <EOL> 
<log-format> ::= "Type A Logfile" | "Logfile II" | "Some Other Format" 
<log-id> ::= "#" <long-int> 
<category> ::= <some unknown string>

How do I define that, for ParseKit to understand? I’ve got this far;

@start = header-line-1;
header-line-1 = log-format log-id "," category EOL;
log-format = 'Type A Logfile';
log-id = '#' ; // and then how to specify a long-int?!?
category = char+;
char = 'A' | 'a' | 'B' | 'b' | 'C'; //..etc...   Surely not?!?

I suspect there must be at least a ways to define a range of charachters?

FOr sure, the book quoted by the author of parsekit will probably help me, but would be nice if somebody can help me get going with my own small example, before I dig deeper into the subject. Am only just investigating an idea, just proof of concept.

  • 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-30T23:03:02+00:00Added an answer on May 30, 2026 at 11:03 pm

    Developer of ParseKit here.

    Unfortunately, there is no further (good) documentation on ParseKit’s grammar syntax. Currently the best resources are:

    1. Steven Metsker’s Book Building Parsers in Java. The good news: This will teach you about the design/innards of ParseKit. The bad news: the “Grammar syntax” feature of ParseKit is an additional feature layered on top of ParseKit which I designed and added myself. So it is not described in Metsker’s book as his Java library does not have this feature.

    2. The .grammar files in the Test target of the ParseKit Xcode project. There’s lots of real-world example grammars here. You can learn a lot by example.

    3. The ParseKit tag here on StackOverflow. I’ve answered a lot of questions which may be helpful to you.


    As for your specific example, here’s how I’d probably define it in ParseKit syntax.

    @symbolState = '\n'; // Tokenizer Directive
                         // tells tokenizer to treat new line chars as 
                         // individual Symbol tokens rather than whitespace
    @start = headerLine*;
    headerLine = logFormat logId comma category eol;
    logFormat = ('Type' 'A' 'Logfile') | ('Logfile' 'II') | ('Some' 'Other' 'Format');
    logId = hash Number;
    category = Any+;
    
    comma = ',';
    hash = '#';
    eol = '\n';
    

    One important thing to keep in mind is that parsing in ParseKit is a two Phase process:

    1. Tokenizing (done by PKTokenizer and altered by Tokenizer Directives in your grammar)
    2. Parsing (done by the parser constructed by the Declarations in your grammar)

    So the Parser created by your grammar works on Tokens which have already been tokenized by the Tokenizer. It does not work on either individual chars or long strings composed of multiple tokens.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.