Hi All,

I am new to ANTLR. I am generating a subset of ECMA-262/ActionScript
grammar. Please help me in validating the grammar.
Can anyone please let me know the following grammar will generate
proper AST and tokens?

___________________________________________________________________________________________________________

grammar TEST;

options{
        output=AST;
}
tokens{
        PACKAGE;
        CLASS;
        LPARA;
        RPARA;
        IDENTIFIER;
        NEW;
        VAR;
        WS;
}

@parser::header{
        package test;
}

@lexer::header{
        package test;
}

compilationUnit :       packageDecl packageBlock* EOF!;

packageDecl     :       PACKAGE IDENTIFIER packageBlock;

packageBlock    :       LPARA packageBlockEntry* RPARA;

packageBlockEntry       :       importDefinition* classDefinition;

importDefinition        :       IMPORT  IDENTSTAR SEMI!;

classDefinition         :       CLASS IDENTIFIER LPARA classBody RPARA;

classBody               :       variableDefinition* methodDefinition*;

variableDefinition      :       VAR IDENTIFIER SEMI!
                        |       VAR IDENTIFIER EQUALS NEW IDENT LPARA RPARA 
SEMI!
                        |       VAR IDENTIFIER EQUALS IDENTIFIER SEMI!
                        |       VAR IDENTIFIER EQUALS CONSTLITERAL SEMI!;

methodDefinition        :       modifier? (STATIC | NATIVE)? FUNCTION IDENTIFIER
(COLON (VOID|IDENTIFIER))? LPARA statement* RPARA;

statement               :       SEMI!
                        |       declarationStatement
                        |       expressionStatement
                        |       ifStatement
                        |       forStatement
                        |       forEachStatement
                        |       whileStatement
                        |       doWhileStatement
                        |       switchStatement
                        |       breakStatement
                        |       continueStatement
                        |       returnStatement
                        |       throwStatement
                        |       tryStatement;


modifier        :       'public'
                |       'private'
                |       'protected';



PACKAGE :       'package';
IMPORT  :       'import;
CLASS   :       'class';
NEW     :       'new';
VAR     :       'var' | 'const';
FUNCTION:       'function';
VOID    :       'void';
STATIC  :       'static';
NATIVE  :       'native';

LPARA   :       '{';
RPARA   :       '}';
EQUALS  :       '=';
UNDERSCORE      :       '_';
HYPHEN  :       '-';
DOT     :       '.';
STAR    :       '*';
COLON   :       ':';

IDENTIFIER      :       ('a'..'z' | 'A'..'Z')+ ('a'..'z' | '0'..'9' | UNDERSCORE
| HYPHEN)*;
IDENT   :       ('a'..'z' | 'A'..'Z')+ ('a'..'z' | '0'..'9' | UNDERSCORE |
HYPHEN | DOT)*;
IDENTSTAR       :       ('a'..'z' | 'A'..'Z')+ ('a'..'z' | '0'..'9' | 
UNDERSCORE |
HYPHEN | DOT | STAR)*;

CONSTLITERAL    :       (('a'...'z')* | ('0..9')*);

WS      :       (' ' | '\t' | '\f')+ {skip();};
SEMI    :       ';';

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to