[antlr-interest] Re: java15.g: Can't parse only conditionalExpression

Jens Theeß j.theess at tu-bs.de
Tue Nov 23 13:54:41 PST 2004


Terence Parr wrote:

>On Nov 23, 2004, at 9:54 AM, Jens Theeß wrote:
>  
>
>>Next thing is how to best switch lexers. Fortunately, I have control
>>over the syntax of the language (I'm extending the sequence diagram
>>syntax to allow for embedded java actions). Following example is what I
>>would like to do:
>>
>>a -> b.foo(5, String d:d.startsWith("ha"), 10);
>>
>>This is a sequence diagram event meaning that obj. a calls b.foo with
>>the parameters 5, a String that starts with "ha", and 10. To support
>>this, I think I would have to switch lexers from the parser, which is a
>>no-no. So I could modify the syntax to look like this:
>>
>>a -> b.foo(5, String d:j{d.startsWith("ha")}, 10);
>>
>>or something similar, where I would switch to Java lexer upon seeing
>>"j{" and switch back upon "}". Or is there any easy way to support the
>>first version?
>>    
>>
>
>Not sure why you need it.  Why doesn't the following work:
>
>a -> b.foo(5, d.startsWith("ha"), 10);
>
>?
>
>Ter
>
To give you the big picture, I'm developing a tool to translate a 
sequence diagram into a junit test (as java source). All "x -> y" events 
in the sd are translated into java classes which can compare events from 
a tracer to the expected event. So a

"a -> b.foo(int i: 5)"

in the sd is translated into a class including a function compareArgs, 
which binds a new sd-variable i upon succesful match:

public boolean compareArgs(Object[] args)
{
    int i = args[0];
    if (i == 5)
    {
        sdVariables.put("i", i);
        return true;
    }
    else
        return false;
}


Now for the embedded java. I am to implement sd events of the form

"a -> b.foo(String d: d.startsWith(e));"

where e is a variable bound previously in the sd and d is bound upon 
successful match.This translates to

public boolean compareArgs(Object[] args)
{
    String d = (String) args[0];
    String e = (String) sdVariables.get("e");
    if (d.startsWith(e))
    {
        sdVariables.put("d", d);
        return true;
    }
    else
        return false;
}

So I need to parse the "d.startsWith(e)" part of the sd event with the 
JavaRecognizer, to find out variables used in the expression. The rest 
of  the sd event needs to be parsed by the SDParser.

Jens


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list