Hey Guys,
I think I need your help for this. I'm trying to create a little test
application for my grammar (both attached to the mail) with ANTLR IDE
1.3 using Eclipse and getting the following error stack trace on execution:
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at
org.antlr.runtime.debug.DebugEventSocketProxy.handshake(DebugEventSocketProxy.java:75)
at SelectShortParser.<init>(SelectShortParser.java:169)
at SelectShortParser.<init>(SelectShortParser.java:158)
at Test.main(Test.java:24)
I asked Google for help and read that I should change the port, cause
the default port 49153 is used by another app - I asked netstat for
that, it's svchost.exe (I'm working with Vista Business).
No Problem I thought, just change the port - I used 49100. For now the
BindException doesn't appear, but my app seems to run in an endless loop.
Running the same grammar with the interpreter of ANTLR IDE or with
interpreter or debugger in ANTLRWorks everything seems correct, giving
me the expected AST.
Also everything is OK when I use a small sample grammar within Eclipse.
I hope you find or know something that helps me, so I can get my AST for
further work.
Thank you in advance for any help.
Regards,
Matthias
--
Matthias Kiehl
Albert-Förster-Str. 1
03042 Cottbus
Mail: [email protected]
Phone: +49-355-7557926
Mobile: +49-170-4688357
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
grammar SelectShort;
options{
output = AST;
// ASTLabelType = CommonTree;
}
tokens{
SIGMA;
PI;
}
select : stat+ {
Tree result = (Tree) $stat.tree;
System.out.println( result.toStringTree());
}
;
stat : query_exp^ order_by_clause? ';'!;
query_exp
: query_term ((UNION | EXCEPT)^ ALL? //corresponding_spec?
query_term)*
;
query_term
: query_primary (INTERSECT^ ALL? //corresponding_spec?
query_primary)*
;
query_primary
: (simple_table)^ //=> simple_table
| LP! query_exp^ RP!
;
simple_table
: query_spec
;
query_spec
: SELECT (DISTINCT | ALL)? select_list from_clause where_clause?
-> ^(SELECT ^(PI select_list) from_clause where_clause?)
;
from_clause
: FROM^ table_ref_simple (COMMA! table_ref_simple)*
;
where_clause
: WHERE search_condition -> ^(SIGMA search_condition)
;
order_by_clause
: ORDERBY^ sort_spec_list;
select_list
: select_sublist (COMMA select_sublist)* -> select_sublist+
| STAR -> STAR
;
select_sublist
: derived_column
| qualified_name DOT STAR
;
sort_spec_list
: sort_spec (COMMA sort_spec)* -> sort_spec+
;
derived_column
: value_exp as_clause? -> value_exp
;
column_name_list
: ID (COMMA ID)* -> ID+
;
as_clause
: AS? ID -> ^(AS ID)
;
value_exp
: string_value_exp
// | num_value_exp
;
value_exp_primary
: unsigned_value_spec
| qualified_name
| LP! query_spec RP!
| LP value_exp (COMMA value_exp)* RP -> value_exp+
// | set_fct_spec
;
sort_spec
: (DIGIT+ | qualified_name) ('asc' | 'desc')?
;
unsigned_value_spec
: unsigned_lit
| general_value_spec
;
general_value_spec
: ':' ID (INDICATOR? ':' ID)?
| '?'
| USER
| CURRENT_USER
| SESSION_USER
| SYSTEM_USER
| VALUE
;
string_value_exp
: char_value_exp
;
char_value_exp
: s1=char_factor (CONCAT s2=char_factor)*
;
num_value_exp
: term (PLUS_MINUS^ term)*
;
table_ref_simple
: (qualified_name | LP (table_ref_simple | query_spec) RP) (ID)?
;
predicate
options{
memoize = true;
}
: (row_value_constructor comp_op) => comp_predicate
| (char_value_exp NOT? LIKE) => like_predicate
| (row_value_constructor IS) => row_value_constructor IS NOT? NULL
| (row_value_constructor SIMILAR_TO) => similar_predicate
;
comp_predicate
: row_value_constructor comp_op^ row_value_constructor
;
like_predicate
: char_value_exp NOT? LIKE char_value_exp (ESCAPE
char_value_exp)? -> NOT? ^(LIKE char_value_exp char_value_exp)
;
similar_predicate
: row_value_constructor SIMILAR_TO num_value_exp (WEIGHTED_BY
num_value_exp | CUT_BY num_value_exp)? (LIMITED_BY num_value_exp)?
;
comp_op : EQ
| LW
| GR
| UNEQ
| GL
| LE
| GE
;
row_value_constructor
options{
memoize = true;
}
: (row_value_constructor_elem) => row_value_constructor_elem
| (LP row_value_constructor_elem) => LP
row_value_constructor_elem (COMMA row_value_constructor_elem)* RP
-> row_value_constructor_elem+
| LP query_spec RP
-> query_spec
;
row_value_constructor_elem
: (value_exp | NULL | DEFAULT)
;
search_condition
: boolean_term (OR^ boolean_term)*
;
term : factor (('*'|'/')^ factor)*;
boolean_term
: boolean_factor (AND^ boolean_factor)*
;
factor : PLUS_MINUS? num_primary;
boolean_factor
: NOT? boolean_primary (IS NOT? (TRUE|FALSE|UNKNOWN))?
;
num_primary
: value_exp_primary
| num_value_fct
;
boolean_primary
options{
memoize = true;
}
: (predicate) => predicate
| LP search_condition RP
;
qualified_name
: ID ('.' ID)* -> ^(TABLE ID+)
;
char_factor
: char_primary //collate_clause?
;
char_primary
: value_exp_primary
| string_value_fct
;
bit_primary
: value_exp_primary
| string_value_fct
;
string_value_fct
options{
memoize = true;
}
: char_value_fct
;
char_value_fct
: (UPPER | LOWER)^ LP! char_value_exp RP!
| CONVERT LP char_value_exp USING qualified_name RP
-> ^(CONVERT char_value_exp ^(USING qualified_name))
| TRANSLATE LP char_value_exp USING qualified_name RP
-> ^(TRANSLATE char_value_exp ^(USING qualified_name))
| SUBSTRING LP (char_value_exp) FROM n1=num_value_exp (FOR
n2=num_value_exp)? RP
-> ^(SUBSTRING char_value_exp ^(FROM $n1 $n2?))
| TRIM^ LP! trim_operands RP!
;
trim_operands
: SINGLE_QUOTED_CHAR FROM^ char_value_exp
| (LEADING | TRAILING | BOTH) SINGLE_QUOTED_CHAR? FROM^
char_value_exp
| char_value_exp
;
num_value_fct
: position_exp
| length_exp
;
length_exp
: CHAR_LENGTH LP string_value_exp RP -> ^(CHAR_LENGTH
string_value_exp)
| OCTET_LENGTH LP string_value_exp RP -> ^(OCTET_LENGTH
string_value_exp)
| BIT_LENGTH LP string_value_exp RP -> ^(BIT_LENGTH
string_value_exp)
;
position_exp
: POSITION LP c1=char_value_exp IN c2=char_value_exp RP ->
^(POSITION ^(IN $c1 $c2))
;
general_lit
: ( (U_SCORE char_set_spec)? (SINGLE_QUOTED_STRING)+)
| ('n' (SINGLE_QUOTED_STRING)+)
;
unsigned_lit
: UNSIGNED_NUM_LIT
| general_lit
;
host_id : ID;
char_set_spec
: (qualified_name '.')? ID
;
// L E X I C A L R U L E S
UNSIGNED_NUM_LIT
: ( DIGIT+ (DOT DIGIT* )? | DOT DIGIT+) (EULER PLUS_MINUS?
DIGIT+)?
;
//delimited_string
// :;
SINGLE_QUOTED_CHAR
: //S_QUOT (SINGLE_LATIN_LETTER | DIGIT | WS | '#' | U_SCORE)
S_QUOT
S_QUOT (options {greedy=false;} : ~(S_QUOT)) S_QUOT
;
SINGLE_QUOTED_STRING
: S_QUOT (options {greedy=false;} : ~(S_QUOT) (~(S_QUOT))+) S_QUOT
| SINGLE_QUOTED_CHAR
;
SELECT : S E L E C T;
FROM : F R O M;
WHERE : W H E R E;
ORDERBY : O R D E R ' '+ B Y;
ALL : A L L;
AND : A N D;
AS : A S;
OR : O R;
NOT : N O T;
IS : I S;
TRUE : T R U E;
FALSE : F A L S E;
UNKNOWN : U N K N O W N;
UPPER : U P P E R;
LOWER : L O W E R;
NULL : N U L L;
DEFAULT : D E F A U L T;
UNION : U N I O N ;
USING : U S I N G;
BY : B Y;
EXCEPT : E X C E P T;
TRIM : T R I M;
FOR : F O R;
LEADING : L E A D I N G;
BOTH : B O T H;
CONVERT : C O N V E R T;
USER : U S E R;
VALUE : V A L U E;
VALUES : V A L U E S;
LIKE : L I K E ;
ESCAPE : E S C A P E;
IN : I N;
TABLE : T A B L E;
CONCAT : '||';
S_QUOT : '\'';
STAR : '*';
DOT : '.';
COMMA : ',';
U_SCORE : '_';
EULER : 'E';
LP : '(';
RP : ')';
EQ : '=';
LW : '<';
GR : '>';
UNEQ : '!=';
GL : '<>';
LE : '<=';
GE : '=>';
PLUS_MINUS
: ('+' | '-')
;
SIMILAR_TO
: S I M I L A R ' '+ T O
;
WEIGHTED_BY
: W E I G H T E D ' '+ B Y
;
CUT_BY : C U T ' '+ B Y
;
LIMITED_BY
: L I M I T E D ' '+ B Y
;
DISTINCT
: D I S T I N C T
;
TRANSLATE
: T R A N S L A T E
;
SUBSTRING
: S U B S T R I N G
;
TRAILING
: T R A I L I N G
;
SYSTEM_USER
: S Y S T E M '_' U S E R
;
SESSION_USER
: S E S S I O N '_' U S E R
;
CURRENT_USER
: C U R R E N T '_' U S E R
;
INDICATOR
: I N D I C A T O R
;
CHAR_LENGTH
: (C H A R '_' L E N G T H | C H A R A C T E R '_' L E N G T H)
;
OCTET_LENGTH
: O C T E T '_' L E N G T H
;
BIT_LENGTH
: B I T '_' L E N G T H
;
POSITION
: P O S I T I O N
;
CORRESPONDING
: C O R R E S P O N D I N G
;
INTERSECT
: I N T E R S E C T
;
ID
: (SINGLE_LATIN_LETTER | DIGIT) (SINGLE_LATIN_LETTER | DIGIT |
U_SCORE | '#' | '$')*
;
fragment
BIT_DIGIT
: '0'..'1'
;
fragment
HEX_DIGIT
: 'a'..'f'|'A'..'F'|DIGIT
;
fragment
SINGLE_LATIN_LETTER
: 'a'..'z'
| 'A'..'Z'
;
fragment
DIGIT : '0'..'9';
WS : (' ' | '\t' | '\n' | '\r')+ {$channel = HIDDEN;} ;
fragment A : ('A'|'a');
fragment B : ('B'|'b');
fragment C : ('C'|'c');
fragment D : ('D'|'d');
fragment E : ('E'|'e');
fragment F : ('F'|'f');
fragment G : ('G'|'g');
fragment H : ('H'|'h');
fragment I : ('I'|'i');
fragment J : ('J'|'j');
fragment K : ('K'|'k');
fragment L : ('L'|'l');
fragment M : ('M'|'m');
fragment N : ('N'|'n');
fragment O : ('O'|'o');
fragment P : ('P'|'p');
fragment Q : ('Q'|'q');
fragment R : ('R'|'r');
fragment S : ('S'|'s');
fragment T : ('T'|'t');
fragment U : ('U'|'u');
fragment V : ('V'|'v');
fragment W : ('W'|'w');
fragment X : ('X'|'x');
fragment Y : ('Y'|'y');
fragment Z : ('Z'|'z');
import java.io.FileInputStream;
import java.io.IOException;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
public class Test {
static final TreeAdaptor adaptor = new CommonTreeAdaptor() {
public Object create(Token payload) {
return new CommonTree(payload);
}
};
public static void main (String[] args) {
try {
// create lexer attached to stdin
FileInputStream fs = new FileInputStream("test.sql");
ANTLRInputStream input = new ANTLRInputStream(fs);
// ANTLRInputStream input = new
ANTLRInputStream(System.in);
SelectShortLexer lexer = new SelectShortLexer(input);
// create the buffer of tokens between the lexer and
parser
TokenRewriteStream tokens = new
TokenRewriteStream(lexer);
// create the parser attached to the token buffer
SelectShortParser parser = new
SelectShortParser(tokens);
// launch the parser starting on rule select,
// get return object
parser.setTreeAdaptor(adaptor);
SelectShortParser.select_return result =
parser.select();
// pull out the tree and cast it
Tree t = (Tree) result.getTree();
System.out.println(t.toStringTree());
} catch (IOException ioe) {
// TODO Auto-generated catch block
ioe.printStackTrace();
} catch (RecognitionException re) {
// TODO Auto-generated catch block
re.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address