On Wed, Feb 16, 2011 at 9:18 AM, devdoer bird <[email protected]> wrote:
> ...
> As you see, the last ')' is missed.
> So what's wrong with my grammar?
>
Nothing.
Given your grammar (and adding a `parse` rule to it):
grammar T;
parse
: logicExp EOF {System.out.println("parsed :: " + $logicExp.text);}
;
logicExp
: FIELDNAME ( '>' | '<' ) (CONST_INT | CONST_STRING)
| '(' logicExp')'
;
fragment DIGIT : '0'..'9';
fragment LOWER : 'a'..'z';
fragment UPPER : 'A'..'Z';
FIELDNAME : LOWER (LOWER|DIGIT)* ;
CONST_INT : DIGIT+;
CONST_STRING : '"' (LOWER|UPPER|DIGIT)* '"';
and creating the test class:
import org.antlr.runtime.*;
public class Main {
public static void main(String[] args) throws Exception {
ANTLRStringStream in = new ANTLRStringStream("(a>3)");
TLexer lexer = new TLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TParser parser = new TParser(tokens);
parser.parse();
}
}
I generated a lexer & parser, compiled all .java files and ran the main
class:
java -cp antlr-3.2.jar org.antlr.Tool T.g
javac -cp antlr-3.2.jar *.java
java -cp .:antlr-3.2.jar Main
which produced the output:
parsed :: (a>3)
So, if ANTLRWorks produces something different, there's something wrong with
it.
Regards,
Bart.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
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.