Explanation for my following grammar which I am getting errors written in
ANTLR 4
I have a sample grammar written in ANTLR 4
query : select from ';' !? EOF!
I have understood query : select from ';' how it works
What does !? EOF! means in the grammar and how it works?
WHAT I HAVE UNDERSTOOD
SYMBOL '!'
Here, the symbol '!' can be used in ANTLR 3 but not in ANTLR 4
SYMBOL '?'
The explanation for '?' I have read is ? which means that the symbol (or
group of symbols in parenthesis) to the left of the operator is optional
(it can appear zero or one times).
1) If '?' is optional, then it should execute the query without ';'. Am I
right? For example: If I execute the query, (SELECT COLUMN1 FROM TABLE1) I
am getting an error. I am getting result only when I insert ';' at the end
of the query (SELECT COLUMN1 FROM TABLE1;).
2) The definitions say that it can appear even zero times. In that case,
if my above query is not having ';' I should get the result. right? then
why I am not getting the result if my query is not having ';'?
EOF!
EOF! means the end-of-file
COMPILATION AND TESTING
c:\antlr4 sample.g4
c:\java org.antlr.v4.Tool sample.g4
c:\javac sample*.java
c:\grun sample query -gui
c:\java org.antlr.v4.runtime.misc.TestRig sample query -gui
select column from table
^Z
line 2:0 no viable alternative at input 'selectcolumnfromtable'
C:\grun sample query -gui
C:\java org.antlr.v4.runtime.misc.TestRig sample query -gui
select column from table;
^Z
C:\grun sample query -tree
C:\java org.antlr.v4.runtime.misc.TestRig sample query -tree
select column from table;
^Z
(query (select select (selectExpr (identifiedPathSeq (selectVar
(identifiedPath column))))) (from from (fromExpr (containsExpression
(containExpressionBool (contains (simpleClassExpr table)))))) ; )
C:\grun sample query -tree
C:\java org.antlr.v4.runtime.misc.TestRig sample query -tree
select column from table
^Z
line 2:0 no viable alternative at input 'selectcolumnfromtable' (query
select column from table)
C:\Javalib\tmp1>grun sample query -tokens
C:\Javalib\tmp1>java org.antlr.v4.runtime.misc.TestRig sample query -tokens
select column from table;
^Z
[@0,0:5='select',<6>,1:0]
[@1,7:12='column',<32>,1:7]
[@2,14:17='from',<14>,1:14]
[@3,19:23='table',<32>,1:19]
[@4,24:24=';',<4>,1:24]
[@5,27:26='',<-1>,2:0]
C:\Javalib\tmp1>grun sample query -tokens
C:\Javalib\tmp1>java org.antlr.v4.runtime.misc.TestRig sample query -tokens
select column from table
^Z
[@0,0:5='select',<6>,1:0]
[@1,7:12='column',<32>,1:7]
[@2,14:17='from',<14>,1:14]
[@3,19:23='table',<32>,1:19]
[@4,26:25='',<-1>,2:0]
line 2:0 no viable alternative at input 'selectcolumnfromtable'
No comments:
Post a Comment