Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Download and install AntlrWorks from the AntlrWorks page of the ANTLR website

3.

...

Run ANTLR 3 on a simple grammar

3.1 Create a simple grammar

Java

Code Block

grammar Simple;

@header
{
    package antlr3.tutorial.simple;
}

OR : '||' ;

C#

Code Block

grammar Simple;

options 
{
    language=CSharp;
}

OR : '||' ;

Objective-C

Code Block

grammar Simple;

options 
{
    language=ObjC;
}

OR : '||' ;

C

Code Block

grammar Simple;

options 
{
    language=C;
}

OR : '||' ;

3.2 Run ANTLR 3 on the simple grammar


To be written. Volunteers?

3.3 Revisit the simple grammar and learn basic ANTLR 3 syntax


To be written. Volunteers?

Code Block

parser grammar Simple;

@header
{
    package antlr3.tutorial.simple;
}

OR : '||' ;

Construct

Description

Example

(...)*

Kleene closure - matches zero or more occurrences

LETTER DIGIT* - match a LETTER followed by zero or more occurrences of DIGIT

(...)+

Positive Kleene closure - matches one or more occurrences

('0'..'9')+ - match one or more occurrences of a numerical digit
LETTER (LETTER|DIGIT)+ - match a LETTER followed one or more occurrences of either LETTER or DIGIT

...

Java

Code Block
parser grammar MyLangParser;

@header
{
    package antlr3.tutorial.mylang;
}

OR : '||' ;

3.2 ANTLR 3 lexer grammar syntax

Java

Code Block

lexer grammar MyLangLexer;

@header
{
    package antlr3.tutorial.mylang;
}

OR : '||' ;

...