GithubHelp home page GithubHelp logo

antlr-test's Introduction

ANTLR Example Parser

This repository is an example of a minimal ANTLR parser that works.

It is a silly test parser for a language about soup.

A note about setup: Usually to use antlr.jar in a project you must add it to your build path. To do this in eclipse, right click antlr.jar and select "Build Path" -> "Add to Build Path". I have already done this for this repo (as evidenced in /.classpath), but for other projects this is worth remembering.

I don't know much about parsing so there might be parts of this that are weird, like building the soup from the syntax tree.

This repo includes:

  • An eclipse project
  • An ANTLR 4 grammar file in /src/souplang/grammar/Soup.g4
  • An example junit test suite in /src/souplang/grammar/tests/SoupGrammarTest.java
  • A factory that builds a Soup instance from a parsed tree in /src/souplang/grammar/SoupFactory.java
  • A usage example in /src/souplang/Main.java

This is the salient part of the parser:

    BOWLSTART : 'bowl' ;
    MODIFIER : 'hot' | 'mild' | 'gross' ;
    RAWINGREDIENT : 'onion' | 'eggs' | 'peppers' ;
    WHITESPACE : [ \t\r\n]+ -> skip ;

    soup : BOWLSTART ingredient+ ;
    ingredient : modifier? rawingredient ;
    modifier : MODIFIER ;
    rawingredient : RAWINGREDIENT ;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.