[antlr-interest] How can I generate output with ANTLR?
Luciana Nunes Leal
lucianaleal2002 at yahoo.com.br
Thu Sep 1 12:06:51 PDT 2005
Skipped content of type multipart/alternative-------------- next part --------------
class LNCParser extends Parser;
options {
k=10; // needed for newline junk
buildAST=true;
}
tokens {
// -- LNC Keyword tokens --
IF = "if";
IF_NOT = "if not";
ELSE = "else";
FOR_EACH = "for each";
FOR_ALL = "for all";
WHEN = "when";
AND = "and";
OR = "or";
EQUAL = "equal";
NOT_EQUAL = "not equal to";
EQUAL_OR_GREATER_THAN = "equal or greater than";
GREATER_THAN = "greater than";
EQUAL_OR_LOWER_THAN = "equal or lower than";
LOWER_THAN = "lower than";
IS = "is";
ARE = "are";
TO = "to";
NOT = "not";
THAN = "than";
}
if_not : IF NOT;
equal : EQUAL TO ;
not_equal : NOT EQUAL TO;
equal_or_greater_than : EQUAL OR GREATER THAN;
greater_than : GREATER THAN;
equal_or_lower_than : EQUAL OR LOWER THAN;
lower_than : LOWER THAN;
rule : (sentence DOT)+ NEWLINE;
sentence : ( (when {System.out.println("when");} COMMA statement ((COMMA | AND) statement)* )
| (for_clause COMMA statement ((COMMA | AND) statement)*)
| (if_clause COMMA statement ((COMMA | AND) statement)*)
| (if_not_clause statement ((COMMA | AND) statement)*)
)
;
when : WHEN condicao
;
condicao : alpha_numeric verb ( (equal | not_equal | equal_or_greater_than | greater_than | equal_or_lower_than | lower_than) {System.out.println("==");} ) alpha_numeric
;
verb : IS | ARE
;
alpha_numeric : CHARACTER (DIGIT | CHARACTER)*
;
for_clause: (FOR_EACH | FOR_ALL) collection
;
collection: alpha_numeric
;
if_clause: IF condicao
;
if_not_clause: ELSE
;
statement: alpha_numeric
;
class LNCLexer extends Lexer;
options {
k=10; // needed for newline junk
charVocabulary='\u0000'..'\u007F'; // allow ascii
}
CHARACTER : ('a'..'z'|'A'..'Z')+;
COMMA : ',';
DOT : ".";
DIGIT : ('0'..'9');
WS : ( ' ' | '\t')
{$setType(Token.SKIP);} ;
NEWLINE : ("\r\n") | ("\n") | ("\r")
;
More information about the antlr-interest
mailing list