Re: Fixing Parser Weirdness

View: New views
5 Messages — Rating Filter:   Alert me  

Re: Fixing Parser Weirdness

by twashing :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hey Chris, thanks for responding to this problem thus far. I've been tied up on other projects, but have come back to these problems. Right now I want to do 2 things:

A) Be able to add a new token (that provides an extra option in the language, -returninput).
B) Allow special characters in an XML block (<mytag value='twashing@...' />).

So looking at problem A), I actually was printing out the characters the Parser was picking from the Lexer. If I add the token on line 98 (see fig. 1), I get the error in fig. 2. Normally, using the expression "
login ( user -username root -password password );" works fine. But just with line 98, I get the error that the Parser / Lexer is expecting an opening bracket "(", which is obviously there. So now the question is i) what does it think the "login(..." is and ii) how does line 98 change a working token to this broken state? I've also re-attached my sablecc file.


97        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
98        returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
fig. 1 - bkeeping.cc sablecc file


login ( user -username root -password password );
debugging... action[0] / lexer.peek[login ] / state[0]
debugging... action[3] / lexer.peek[( ] / state[12]
ERROR [Thread-3] (Bkell.java:187) - [14,7] expecting: lbracket
com.interrupt.bookkeeping.cc.parser.ParserException: [14,7] expecting: lbracket
    at com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1024)
    at com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:146)
    at java.lang.Thread.run(Thread.java:637)
ERROR [Thread-3] (Util.java:96) - generateBkellException CALLED
ERROR [Thread-3] (Util.java:102) - TOP error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Util.java:103) - ROOT error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Bkell.java:189) - <logs xmlns='com/interrupt/logs' id='' ><log xmlns='com/interrupt/logs' level='ERROR' id='' ><logMessages xmlns='com/interrupt/logs' id='' ><logMessage xmlns='com/interrupt/logs' id='' >[14,7] expecting: lbracket</logMessage>
</logMessages>
</log>
</logs>
fig. 2 - logs


Thanks
Tim



----- Original Message ----
From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, September 3, 2009 10:47:11 PM
Subject: Re: Fixing Parser Weirdness

When I have a problem like this, generally I'll print out the token stream for the affected area and try to match it to the production I think the parser should choose. When I say print out the token stream, I mean print out the actual stream as generated by the lexer.

If you do that, I think you will find that you either have grammatical or lexical problems (either the token stream isn't what you think it is, or the syntax isn't what you want it to be). It's good to get into practice doing this sort of thing because this will come up from time to time and it's best to be able to resolve it by yourself.

Also note that SableCC is telling you what token it thinks should come next. From that you can deduce what production is actually being selected, which again should help you identify the problem.

--- On Thu, 9/3/09, Timothy Washington <timothyjwashington@...> wrote:

> From: Timothy Washington <timothyjwashington@...>
> Subject: Re: Fixing Parser Weirdness
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Thursday, September 3, 2009, 11:49 PM
>
> That's actually a really good point - I made that
> change. But the parser is still breaking with the error in
> fig. 1 when
> I do a simple command ( see fig. 0 ). Ultimately I want to
> make a command like in fig. 2. To remove the error, all I
> have to
> do is remove the "returninput_opt" parts ( lines
> 98 & 288 ). This is what I meant by a sensitive parser,
> because I can't see
> how those 2 lines would break an unrelated token /
> production.
>
>
> login ( user -username root -password password );
> fig. 0
>
>
> login ( user -username root -password password );
> ERROR [Thread-3] (Bkell.java:186) - [4,7] expecting:
> lbracket
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [4,7] expecting:
>  lbracket
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[4,7] expecting:
> lbracket</logMessage>
> </logMessages>
> </log>
> </logs>
>
> ERROR [Thread-3] (Bkell.java:186) - [1,2] expecting:
> 'var', 'create', 'add',
> 'update', 'remove', 'reverse',
> 'find', 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [1,2] expecting: 'var', 'create',
> 'add', 'update', 'remove',
>  'reverse', 'find', 'list',
> 'print', 'commit', 'load',
> 'login', 'logout',
> 'exit'
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[1,2] expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print', 'commit',
> 'load', 'login', 'logout',
> 'exit'</logMessage>
> </logMessages>
> </log>
> </logs>
> ...
>
> fig. 1
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>           
>  <user xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000' >
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details' >
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...'
>  />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>           
>    </profileDetails>
>           
> </user>
>            ,
>           
> -returninput
> true
>        );
>
> fig. 2
>
>
> Tim
>
>
>
> From: Christopher Van Kirk
> <chris.vankirk@...>
> To:
> Discussion mailing list for the SableCC project
> <sablecc-discussion@...>
> Sent:
> Thursday, September 3, 2009 12:08:21 AM
> Subject: RE:
> Fixing Parser Weirdness
>
>
>
>

>
>

>
>
>
>
>
>
>
>
>
> This is
> probably your problem:
>

>
> dash = '-';
>
> .
>
> .
>
> .
>
> entry_opt = '-entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> You’ve
> defined a dash token in the lexer
> section, but you’re expecting to see it joined to a word
> in the parser,
> Remember that what comes out of the Tokens section is a
> stream of tokens you
> have defined there, so what your parser will see
> is
>

>
> dash
> entry …
> not -entry
>

>
> Try
> changing your production to something
> like:
>

>
> entry_opt = dash
> 'entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> Cheers,
>

>
> Chris…
>

>
> -----Original
> Message-----
>
> From:
> sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
> [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...]
> On Behalf Of
> Timothy Washington
>
> Sent:
> Wednesday,
>  September 02, 2009
> 11:43
> PM
>
> To:
> sablecc-discussion@...
>
> Subject:
> Fixing Parser Weirdness
>

>
>
>
>
>
> Hey
> all, I've implemented a language using sablecc that
> looks like in fig. 1.
>
>
>
> command(
>
>    ( <context/> )
>
>        <input/>,
>
>        `/input[
> @att='value' ]`,
>
>        -inputoption value
>
> );
>
> fig. 1
>
>
>
>
>
>
>
> A) I'm trying to implement an input option, "
> -inputoption value ",
> but if I try to implement the command in fig. 2, I get the
> error
>
> seen in fig. 4.
>
>
>
> var removedE = remove ( ( load( `/system[
> @id="main.system" ]/groups[
> @id="main.groups" ]/group[
> @id="seven.group" ]/bookkeeping[
> @id="main.bookkeeping" ]/journals[
> @id="main.journals"
> ]/journal[ @id="generalledger" ]/entries[
> @id="main.entries" ]` ) )
>
>        <entry
> xmlns='com/interrupt/bookkeeping/journal'
> id='qwer' entrynum='' state=''
> journalid='' date='02022006'
> currency='CDN' > 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='asdf' amount='11.00' entryid=''
> accountid='1' account='office equipment'
> currency='CDN' /> 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='zxcv' amount='1.50' entryid=''
> accountid='2' account='tax'
> currency='CDN' /> 
>
>           
> <credit
> xmlns='com/interrupt/bookkeeping/account'
> id='tyui' amount='12.50' entryid=''
> accountid='3' account='bank'
> currency='CDN' /> 
>
>        </entry>
>
>        ,
>
>       
> -returninput
> true
>
>    );
>
> fig. 2
>
>
>
>
>
>
>
> B) I'm also trying to get SableCC to ignore special
> characters between single
> and double quotes ( ' " ). So for example, I want
>
>
> to be able to say <profileDetail
> value='twashing@...' />, but the
> parser dies with the error in fig. 5.
>
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>
>           
> <user
> xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000'
> >
>
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details'
> >
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>
>           
>    </profileDetails>
>
>           
> </user>
>
>        );
>
> fig. 3
>
>
>
>
>
> It feels like Sablecc is very sensitive in the order of
> tokens. Can anyone help
> me isolate and fix this problem. I've attached
>
> my sablecc file.
>
>
>
>
>
> Thanks in advance
>
> Tim
>
>
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [1,1]
> expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1028)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 4
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [19,3]
> expecting:
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit', 'system',
> 'debit', 'credit',
> 'entry', 'entries', 'journal',
> 'journals', 'transaction',
> 'account',
> 'accounts', 'user', 'users',
> 'group', 'groups', 'allowedActions',
> 'command',
> 'profileDetails', 'profileDetail',
> 'userSession', '<', rbracket, atsign,
> '`'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 5
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
> Looking for the
> perfect gift? Give the gift of
> Flickr!
>
>
>
>
>
>     
> Looking for the perfect gift? Give
> the gift of Flickr!
> -----Inline Attachment Follows-----
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion



Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!



Package com.interrupt.bookkeeping.cc;


Helpers
       
        all = [0 .. 127];
       
        lowercase = ['a' .. 'z'];
        uppercase = ['A' .. 'Z'];
        digit = ['0' .. '9'];
        hex_digit = [ digit+ [['a' .. 'f'] + ['A' .. 'F']] ];
       
        tab = 9;
        cr = 13;
        lf = 10;
        eol = cr lf | cr | lf; // This takes care of different platforms
        dash = '-';
        dot = '.';
        forwardslash = '/';
        backslash = '\';
        asterix = 42;
        equals_helper = '=';
        colon_helper = ':';
        ats = '@';
        underscore = '_';
       
        single_quote = ''';
        double_quote = '"';
       
        lsquare_bracket = '[';
        rsquare_bracket = ']';
       
        left_bracket = '(';
        right_bracket = ')';
       
       
        ws = (' ' | tab | eol);
       
       
       
States
    bkeeping, freetext; // we need a way to ignore commands in freetext
   
   
Tokens
       
       
        //** VARIABLE
        {bkeeping} var = 'var';
       
       
        //** COMMANDS
        {bkeeping} create = 'create';
        {bkeeping} add = 'add';
        {bkeeping} update = 'update';
        {bkeeping} remove = 'remove';
        {bkeeping} reverse = 'reverse';
        {bkeeping} find = 'find';
        {bkeeping} list = 'list';
       
        {bkeeping} print = 'print';
        {bkeeping} commit = 'commit';
       
        {bkeeping} load = 'load';
        {bkeeping} login = 'login';
        {bkeeping} logout = 'logout';
        {bkeeping} exit = 'exit';
       
        {bkeeping} semicolon = ( 59 )?;
       
        whitespace = (' ' | tab | eol);
        comment_line = forwardslash forwardslash all* eol;
        comment_block = forwardslash asterix all* asterix forwardslash;
       
       
        //** COMMAND OPTIONS  
        entry_opt = '-entry' ws+ ( lowercase | uppercase | dash | colon_helper |  ats | underscore | digit | dot )*;
        entryid_opt = '-entryid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        account_opt = '-account' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        accountid_opt = '-accountid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        journal_opt = '-journal' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        name_opt = '-name' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        type_opt = '-type' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        counterweight_opt = '-counterWeight' ws+ lowercase+;
        amount_opt = '-amount' ws+ digit+'.'digit+;
        id_opt = '-id' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        entrynum_opt = '-entrynum' ws+ digit*;
        date_opt = '-date' ws+ digit+'/'digit+'/'digit+;
        file_opt = '-F' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
       
        group_opt = '-group' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        uname_opt = '-username' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        passwd_opt = '-password' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        groupid_opt = '-groupid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        userid_opt = '-userid' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
        //returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
       
       
       
        //** COMMAND TOKENS
        system_tok = 'system';
        debit_tok = 'debit';
        credit_tok = 'credit';
        entry_tok = 'entry';
        entries_tok = 'entries';
        journal_tok = 'journal';
        journals_tok = 'journals';
        transaction_tok = 'transaction';
        account_tok = 'account';
        accounts_tok = 'accounts';
       
        user_tok = 'user';
        users_tok = 'users';
        group_tok = 'group';
        groups_tok = 'groups';
       
        allowedactions_tok = 'allowedActions';
        command_tok = 'command';
        profiledetails_tok = 'profileDetails';
        profiledetail_tok = 'profileDetail';
        usersession_tok = 'userSession';
       
       
        lparen = '<';
        rparen = '>';
       
       
        listdelimiter = ',';
        exclamation = 33;
        question = 63;
        doubledash = dash dash;
       
       
        lbracket = left_bracket;
        rbracket = right_bracket;
        //lsbracket = lsquare_bracket;
        //rsbracket = rsquare_bracket;
       
        equals = equals_helper;
        fslash = forwardslash;
        atsign = ats;
        colon = colon_helper;
       
        {bkeeping -> freetext, freetext -> bkeeping} quote = ( double_quote | single_quote );
        {bkeeping -> freetext, freetext -> bkeeping} backquote = '`';
       
        word = ( lowercase | uppercase | dash | underscore | digit | dot )+;
       
        //xpath_chars = ( ats | forwardslash | colon_helper | left_bracket | right_bracket | lsquare_bracket | rsquare_bracket | equals_helper | double_quote | single_quote );
        xpath_chars = ( colon_helper | left_bracket | right_bracket | lsquare_bracket | rsquare_bracket );
       
       
        xmlns = 'xmlns';
        decl_xml = 'xml';
        decl_dtd = 'DOCTYPE';
        eoll = (cr | lf | cr lf)?;
       
       
Ignored Tokens
       
        whitespace,
        comment_line,
        comment_block;
       
       
Productions
       
       
        expr = {cmd} command semicolon |
                        {thexpr} twohandexpr semicolon;
       
        /***************************
         * VARIABLES
         *
         * @memory
         * @previous
         *
         */
        twohandexpr = var word equals command; // assigning results to variables
        varname = atsign word?; // put an '@' sign in front of variable name to reference it
       
       
        /***************************
         * COMMANDS
         *
         * add ((token.literal) token.literal, ...)
         * update ((token.literal) token.literal, ...)
         * remove ((token.literal) token.literal, ...)
         *
         * reverse ((token.literal) (token.literal) token.literal)
         *
         *
         * find ((token.literal) token -opts)
         * list ((token.literal) token -opts)
         *
         * create (token -opts)
         *
         * load (token -opts) <-- DB  
         * commit (token.literal) <-- DB
         *
         * print (token.literal)
         *
         * login (token -opts) <-- DB
         * logout <-- DB
         * exit
         *
         */
        command = {c1} command1 |
                                {c5} command5 |
                                {c2} command2 |
                                {c3} command3 |
                                {c4} command4 |
                                {c6} command6 |
                                {c7} command7;
       
       
        command1 = {add} add [lbdepth1]:lbracket [lbdepth2]:lbracket command_input [rbdepth2]:rbracket ilist* [rbdepth1]:rbracket |
                                {update} update [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket |
                                {remove} remove [lbdepth1]:lbracket [lbdepth2]:lbracket command_input [rbdepth2]:rbracket ilist* [rbdepth1]:rbracket;
       
        command5 = {reverse} reverse [lbdepth1]:lbracket [lbdepth2]:lbracket [ci1]:command_input [rbdepth2]:rbracket [lbdepth3]:lbracket [ci2]:command_input [rbdepth3]:rbracket [ci3]:command_input [rbdepth1]:rbracket;
       
        //** input list & delimiter
        ilist = command_input ilistpart*;
        ilistpart = listdelimiter command_input;
       
       
        command2 = {find} find [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket|
                                {list} list [lbdepth1]:lbracket [lbdepth2]:lbracket [c1]:command_input [rbdepth2]:rbracket [c2]:command_input [rbdepth1]:rbracket;
       
        command3 = {load} load lbracket command_input rbracket |
                                {create} create lbracket command_input rbracket |
                                {login} login lbracket command_input rbracket;
       
        command4 = {logout} logout|
                                {exit} exit;
       
        command6 = {print} print lbracket command_input rbracket;
       
        command7 = {commit} commit [lbdepth1]:lbracket [lbdepth2]:lbracket [input1]:command_input [rbdepth2]:rbracket [input2]:command_input [rbdepth1]:rbracket;
       
       
       
        /**************************
         * COMMAND INPUT
         */
        command_input = {var} varname |
                                                {xml} xmlblock |
                                                {opts} input_option |
                                                {cmd} command |
                                                {xpath} xpath;
       
       
        // token -opts
        input_option = commandtoken commandoption*;
       
       
        xpath = [left]:backquote xpath_part* [right]:backquote;
                xpath_part = {wd} wordetal |
                                                {xpc} xpath_chars |
                                                {fslash} fslash |
                                                {quote} quote |
                                                {ats} atsign |
                                                {equals} equals;
       
       
       
        /***************************
         * COMMAND OPTIONS
         */
        commandoption = {entry} entry_opt |
                                                {entryid} entryid_opt |
                                                {account} account_opt |
                                                {accountid} accountid_opt |
                                                {journal} journal_opt |
                                                {name} name_opt |
                                                {type} type_opt |
                                                {cweight} counterweight_opt |
                                                {amount} amount_opt |
                                                {id} id_opt |
                                                {entrynum} entrynum_opt |
                                                {date} date_opt |
                                                {file} file_opt |
                                                {group} group_opt |
                                                {uname} uname_opt |
                                                {passwd} passwd_opt |  
                                                {groupid} groupid_opt |
                                                {userid} userid_opt |
                                                {currency} currency_opt;  
       
       
       
        /***************************
         * XML BLOCKS
         */
        xmlblock = xml_decl? fulltag;
       
        fulltag = {fulltag} opentag fulltag* wordetal* closetag |
                                {emptytag} emptytag |
                                {comment} xmlcomment;
       
        opentag = lparen nsprefix? wordetal attribute* rparen;
        emptytag = lparen nsprefix? wordetal attribute* fslash rparen;
        closetag = lparen fslash nsprefix? wordetal rparen;
       
       
       
        xml_decl =  {xml_schem} xml_decl_schem |
                                {xml_dtd} xml_decl_dtd;
       
        // <?xml version="1.0" encoding="iso8859-1" ?>
        xml_decl_schem = lparen [left]:question wordetal attribute+ [right]:question rparen;
       
        // <!DOCTYPE greeting SYSTEM "hello.dtd" >
        xml_decl_dtd = lparen exclamation word_dtd+ rparen;
        word_dtd  = {attrhs} attributerhs |
                                {word} word;
       
       
        attribute = nsprefix? attributelhs equals attributerhs;  
        attributelhs = wordetal;
        attributerhs = [left]:quote zzz* [right]:quote;
       
        nsprefix = wordetal colon;
       
        xmlcomment = xml_opencomment wordetal* xml_closecomment;  
       
        xml_opencomment = lparen exclamation doubledash;
        xml_closecomment = doubledash rparen;
       
       
        zzz = {one} wordetal |
                        {two} fslash;
       
        wordetal = {word} word |
                                {ctoken} commandtoken;
       
       
       
        /***************************
         * COMMAND TOKENS
         */
        commandtoken = {system} system_tok |
                                        {debit} debit_tok |  
                                        {credit} credit_tok |  
                                        {entry} entry_tok |
                                        {entries} entries_tok |
                                        {journal} journal_tok |
                                        {journals} journals_tok |
                                        {transaction} transaction_tok |  
                                        {accounts} accounts_tok |
                                        {account} account_tok |
                                        {user} user_tok |
                                        {users} users_tok |
                                        {group} group_tok |
                                        {groups} groups_tok |
                                        {allowedactions} allowedactions_tok |
                                        {command} command_tok |
                                        {profiledetails} profiledetails_tok |
                                        {profiledetail} profiledetail_tok |
                                        {usersession} usersession_tok;
       
       
         
        // >>>>>>>>>> TODO
       
        // 7. include CDATA blocks
        // <a> <![CDATA[ do something ]]> </a>
       
       
       
        /**
         *
         * TEST XMLs
         */
        // <xml>
        // <xml/>
        // <xml> ccc </xml>
        // <xml> lorem ipsum some text </xml>
        // <xml attr1="" attr2="wert" />
        // <xml attr1="" attr2="wert" > </xml>

        // <xml:xml />
        // <xml:xml></xml:xml>
       
        // <xml:xml attr1="" attr2="wert" />
        // <xml:xml attr1="" attr2="wert" ></xml:xml>
       
        // <xml:xml attr1="" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml:xml>
        // <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
        // <xml:xml pre:attr1="" pref:attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
       
        // <?xml version="1.0" encoding="iso8859-1" ?> <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
        // <!DOCTYPE greeting SYSTEM "hello.dtd" > <xml:xml attr1="" attr2="wert" > <a> <!-- this is comments --> <b/> </a> lorem ipsum some text </xml:xml>
       
        // <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />
        // <?xml version="1.0" encoding="iso8859-1" ?><credit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />  
       
        // <account xmlns='com/interrupt/bookkeeping/account' id='1' name='office equipment' type='asset' counterWeight='debit' ><debit xmlns='com/interrupt/bookkeeping/account' id='' amount='10.00' entryid='' accountid='1' /></account>
   
   
    /**
     *
     * SCRATCH XML
     */
        // <lebit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />  
        // <lebit xmlns='comaccount' id='def' amount='1.50' entryid='e1' accountid='2' />
        // <debit xmlns='comaccount' id='def' amount='1.50' entryid='e1' accountid='2' />
        // <xml:xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml:xml>
        // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum some text </xml>
        // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> </xml>
       
        // <xml attr1="comaccount" attr2="wert" > <a> <b/> </a> </xml>
        // <xml attr1="comaccount" attr2="wert" > <a> <b/> </a> lorem ipsum </xml>
        // <xml attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> lorem ipsum </xml>
       
        // <debit attr1="com/interrupt/bookkeeping/account" attr2="wert" > <a> <b/> </a> </debit>
        // <debit attr1="com/interrupt/bookkeeping/account" attr2="wert" > </debit>
   
   
   
    /**
     *
     * TEST OPTIONS
     */
    // -entry journal
        // -type type -name some
        // -type type -name some -id qerfb1435c -date 06/24/2003
       
        //[X] -account "account name"
        //[X] -journal journal name -entry journal
       
        // -counterWeight debit
        // -amount 123.33
        // -id qerfb1435c
        // -entrynum 765
        // -date 06/24/2003
        // -F filename
       
       
        // login ( user -username root -password password );
        // load ( users -id aauth.users );
       
       
        //** create ( debit -id erfg -amount 123.33 );
        // create ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' /> );
   
   
    // load ( users -id aauth.users );
    // load ( debit -amount 10.00 );
    // load ( debit -id abc -amount 10.00 );
    // load ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' /> );
   
   
    //** add ((create ( entry -id ez ) ) create ( debit -id dbzz -amount 10.00 ) );
        // add ((create ( entry -id ez ) ) load ( debit -id abc -amount 10.00 ) );
   
    // add ((create ( entry -id ez -currency CDN ) ) create ( <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' currency='CDN' /> ) );
   
   
    // remove ( (load ( entry -id e1 )) );
    // remove ( (load ( entry -id e1 )) load ( debit -id abc -amount 10.00 ) );
   
   
    /* reverse ( (
      <entries xmlns='com/interrupt/bookkeeping/journal' id='' >
      <entry xmlns='com/interrupt/bookkeeping/journal' id='e1' entrynum='' state='closed' journalid='' date='' >  
                                                <debit xmlns='com/interrupt/bookkeeping/account' id='abc' amount='10.00' entryid='e1' accountid='1' />  
                                                <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />  
                                                <credit xmlns='com/interrupt/bookkeeping/account' id='ghi' amount='11.50' entryid='e1' accountid='3' />  
                                        </entry>
                                </entries>
      )
      (
  <entry xmlns='com/interrupt/bookkeeping/journal' id='e1' entrynum='' state='closed' journalid='' date='' >  
                                        <debit xmlns='com/interrupt/bookkeeping/account' id='abc' amount='10.00' entryid='e1' accountid='1' />  
                                        <debit xmlns='com/interrupt/bookkeeping/account' id='def' amount='1.50' entryid='e1' accountid='2' />  
                                        <credit xmlns='com/interrupt/bookkeeping/account' id='ghi' amount='11.50' entryid='e1' accountid='3' />  
                                </entry>
      )
    <entry xmlns='com/interrupt/bookkeeping/journal' id='ereverse' entrynum='' state='closed' journalid='' date='' >  
                                        <debit xmlns='com/interrupt/bookkeeping/account' id='reverseabc' amount='11.50' entryid='ereverse' accountid='1' />  
                                        <credit xmlns='com/interrupt/bookkeeping/account' id='reverseghi' amount='11.50' entryid='ereverse' accountid='3' />  
                                </entry>
    );
    */
        // reverse ( (entries -id es1) (entry -id e1) <entry xmlns='com/interrupt/bookkeeping/journal' id='newid' state='closed' > </entry> );
   
   
    // find ( (load ( account -id 2 )) load ( debit -amount 1.50 ) );
   
   
    // list ( (load ( entry -id e1 )) load ( debit -entryid e1) );
    //** list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' / > );
        // list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' entryid='e1' / > );
   
   
   
    //** VARIABLES
    // var timmy = list ( (load ( entry -id e1 )) <debit xmlns='com/interrupt/bookkeeping/account' / > );
    // find ( (load ( entry -id e1 )) @timmy );
   
    // print ( @timmy );
   
   
    //** COMMITING
    /*
    add ( (load ( entries -id es1 ))
      add (
    (create ( entry -id e2 ))
    create (debit -id nsfada -entryid e2 -amount 52.30 -accountid 1 ),
    create (credit -id efiafd -entryid e2 -amount 52.30 -accountid 3 )
    )
    );
    */
   
    // add ( ( create (entries) ) create ( entry ) );
    // add ( ( create (entries) ) create ( entry ), create ( entry ) );
   

        /*
                var tim = add (
                                        (create ( entry -id e2 ))
                                                create (debit -id nsfada -entryid e2 -amount 52.30 -accountid 1 ),
                                                create (credit -id efiafd -entryid e2 -amount 52.30 -accountid 3 )
                                        );
        */
        // var result = add ( (load ( entries -id es1 )) @tim );
        // commit ( @result );
       
   
       
       
        // >>>>>>>>>> DONE
        // * Tokens cannot use other tokens
       
        // [OK] multiple attributes
        // [OK] include 2 tokens in a production rule
       
        // [OK] include xml comments
        // <!-- -->
       
        // [OK] include namespace declarations; namespace usage in tags and attributes
        // xmlns='' xmlns:ans='' <ans:tagname att='' />
       
        // [OK] text in open/close tags
        // <a att='' >
        // <b/>
        // some text
        // </a>
       
       
        // [OK] include document declaration ( DTD & schema )
        // <?xml version="1.0" encoding="iso8859-1"  **allow any and all characters between** ?>
        // <!DOCTYPE greeting SYSTEM "hello.dtd" **allow any and all characters between** >
       
        // [OK] implement token & options (this will also be the short form of inputs )
       
        // [OK] comments
       
       
       
       
       

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

RE: Fixing Parser Weirdness

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Have you tried the approach to solving ‘A’ that I suggested in my last posting? If you have and you’re still confused then post the token stream emitted by your lexer and we can go from there.

 

In solving A you may acquire the skills you need to solve B, so I think you should just let B slide for the moment.

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Thursday, October 08, 2009 7:50 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey Chris, thanks for responding to this problem thus far. I've been tied up on other projects, but have come back to these problems. Right now I want to do 2 things:

A) Be able to add a new token (that provides an extra option in the language, -returninput).
B) Allow special characters in an XML block (<mytag value='twashing@...' />).

So looking at problem A), I actually was printing out the characters the Parser was picking from the Lexer. If I add the token on line 98 (see fig. 1), I get the error in fig. 2. Normally, using the expression "login ( user -username root -password password );" works fine. But just with line 98, I get the error that the Parser / Lexer is expecting an opening bracket "(", which is obviously there. So now the question is i) what does it think the "login
(..." is and ii) how does line 98 change a working token to this broken state? I've also re-attached my sablecc file.


97        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
98        returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;

fig. 1 - bkeeping.cc sablecc file


login ( user -username root -password password );
debugging... action[0] / lexer.peek[login ] / state[0]
debugging... action[3] / lexer.peek[( ] / state[12]

ERROR [Thread-3] (Bkell.java:187) - [14,7] expecting: lbracket
com.interrupt.bookkeeping.cc.parser.ParserException: [14,7] expecting: lbracket
    at com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1024)
    at com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:146)
    at java.lang.Thread.run(Thread.java:637)
ERROR [Thread-3] (Util.java:96) - generateBkellException CALLED
ERROR [Thread-3] (Util.java:102) - TOP error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Util.java:103) - ROOT error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Bkell.java:189) - <logs xmlns='com/interrupt/logs' id='' ><log xmlns='com/interrupt/logs' level='ERROR' id='' ><logMessages xmlns='com/interrupt/logs' id='' ><logMessage xmlns='com/interrupt/logs' id='' >[14,7] expecting: lbracket</logMessage>
</logMessages>
</log>

</logs>
fig. 2 - logs


Thanks
Tim



----- Original Message ----
From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, September 3, 2009 10:47:11 PM
Subject: Re: Fixing Parser Weirdness

When I have a problem like this, generally I'll print out the token stream for the affected area and try to match it to the production I think the parser should choose. When I say print out the token stream, I mean print out the actual stream as generated by the lexer.

If you do that, I think you will find that you either have grammatical or lexical problems (either the token stream isn't what you think it is, or the syntax isn't what you want it to be). It's good to get into practice doing this sort of thing because this will come up from time to time and it's best to be able to resolve it by yourself.

Also note that SableCC is telling you what token it thinks should come next. From that you can deduce what production is actually being selected, which again should help you identify the problem.

--- On Thu, 9/3/09, Timothy Washington <timothyjwashington@...> wrote:

> From: Timothy Washington <timothyjwashington@...>
> Subject: Re: Fixing Parser Weirdness
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Thursday, September 3, 2009, 11:49 PM
>
> That's actually a really good point - I made that
> change. But the parser is still breaking with the error in
> fig. 1 when
> I do a simple command ( see fig. 0 ). Ultimately I want to
> make a command like in fig. 2. To remove the error, all I
> have to
> do is remove the "returninput_opt" parts ( lines
> 98 & 288 ). This is what I meant by a sensitive parser,
> because I can't see
> how those 2 lines would break an unrelated token /
> production.
>
>
> login ( user -username root -password password );
> fig. 0
>
>
> login ( user -username root -password password );
> ERROR [Thread-3] (Bkell.java:186) - [4,7] expecting:
> lbracket
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [4,7] expecting:
>  lbracket
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[4,7] expecting:
> lbracket</logMessage>
> </logMessages>
> </log>
> </logs>
>
> ERROR [Thread-3] (Bkell.java:186) - [1,2] expecting:
> 'var', 'create', 'add',
> 'update', 'remove', 'reverse',
> 'find', 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [1,2] expecting: 'var', 'create',
> 'add', 'update', 'remove',
>  'reverse', 'find', 'list',
> 'print', 'commit', 'load',
> 'login', 'logout',
> 'exit'
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[1,2] expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print', 'commit',
> 'load', 'login', 'logout',
> 'exit'</logMessage>
> </logMessages>
> </log>
> </logs>
> ...
>
> fig. 1
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>           
>  <user xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000' >
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details' >
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...'
>  />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>           
>    </profileDetails>
>           
> </user>
>            ,
>           
> -returninput
> true
>        );
>
> fig. 2
>
>
> Tim
>
>
>
> From: Christopher Van Kirk
> <chris.vankirk@...>
> To:
> Discussion mailing list for the SableCC project
> <sablecc-discussion@...>
> Sent:
> Thursday, September 3, 2009 12:08:21 AM
> Subject: RE:
> Fixing Parser Weirdness
>
>
>
>

>
>

>
>
>
>
>
>
>
>
>
> This is
> probably your problem:
>

>
> dash = '-';
>
> .
>
> .
>
> .
>
> entry_opt = '-entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> You’ve
> defined a dash token in the lexer
> section, but you’re expecting to see it joined to a word
> in the parser,
> Remember that what comes out of the Tokens section is a
> stream of tokens you
> have defined there, so what your parser will see
> is
>

>
> dash
> entry …
> not -entry
>

>
> Try
> changing your production to something
> like:
>

>
> entry_opt = dash
> 'entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> Cheers,
>

>
> Chris…
>

>
> -----Original
> Message-----
>
> From:
> sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
> [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...]
> On Behalf Of
> Timothy Washington
>
> Sent:
> Wednesday,
>  September 02, 2009
> 11:43
> PM
>
> To:
> sablecc-discussion@...
>
> Subject:
> Fixing Parser Weirdness
>

>
>
>
>
>
> Hey
> all, I've implemented a language using sablecc that
> looks like in fig. 1.
>
>
>
> command(
>
>    ( <context/> )
>
>        <input/>,
>
>        `/input[
> @att='value' ]`,
>
>        -inputoption value
>
> );
>
> fig. 1
>
>
>
>
>
>
>
> A) I'm trying to implement an input option, "
> -inputoption value ",
> but if I try to implement the command in fig. 2, I get the
> error
>
> seen in fig. 4.
>
>
>
> var removedE = remove ( ( load( `/system[
> @id="main.system" ]/groups[
> @id="main.groups" ]/group[
> @id="seven.group" ]/bookkeeping[
> @id="main.bookkeeping" ]/journals[
> @id="main.journals"
> ]/journal[ @id="generalledger" ]/entries[
> @id="main.entries" ]` ) )
>
>        <entry
> xmlns='com/interrupt/bookkeeping/journal'
> id='qwer' entrynum='' state=''
> journalid='' date='02022006'
> currency='CDN' > 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='asdf' amount='11.00' entryid=''
> accountid='1' account='office equipment'
> currency='CDN' /> 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='zxcv' amount='1.50' entryid=''
> accountid='2' account='tax'
> currency='CDN' /> 
>
>           
> <credit
> xmlns='com/interrupt/bookkeeping/account'
> id='tyui' amount='12.50' entryid=''
> accountid='3' account='bank'
> currency='CDN' /> 
>
>        </entry>
>
>        ,
>
>       
> -returninput
> true
>
>    );
>
> fig. 2
>
>
>
>
>
>
>
> B) I'm also trying to get SableCC to ignore special
> characters between single
> and double quotes ( ' " ). So for example, I want
>
>
> to be able to say <profileDetail
> value='twashing@...' />, but the
> parser dies with the error in fig. 5.
>
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>
>           
> <user
> xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000'
> >
>
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details'
> >
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>
>           
>    </profileDetails>
>
>           
> </user>
>
>        );
>
> fig. 3
>
>
>
>
>
> It feels like Sablecc is very sensitive in the order of
> tokens. Can anyone help
> me isolate and fix this problem. I've attached
>
> my sablecc file.
>
>
>
>
>
> Thanks in advance
>
> Tim
>
>
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [1,1]
> expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1028)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 4
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [19,3]
> expecting:
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit', 'system',
> 'debit', 'credit',
> 'entry', 'entries', 'journal',
> 'journals', 'transaction',
> 'account',
> 'accounts', 'user', 'users',
> 'group', 'groups', 'allowedActions',
> 'command',
> 'profileDetails', 'profileDetail',
> 'userSession', '<', rbracket, atsign,
> '`'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 5
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
> Looking for the
> perfect gift? Give the gift of
> Flickr!
>
>
>
>
>
>     
> Looking for the perfect gift? Give
> the gift of Flickr!
> -----Inline Attachment Follows-----
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date: 10/07/09 20:49:00


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Fixing Parser Weirdness

by twashing :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hey there, thanks for the feedback. Agreed, I think that if I solve 'A', thenthe rest will fall into place. What I am spitting out, the stream as you put it, is the "action array / lexer.peek() / state" as seen from the Parser's point of view. The output was in bold red in fig. 2 (logs). Line 98 in fig. 1 was what generated that error (everything works if I remove 98). And see line 166 from the Parser.parse method below. That's where I'm putting the debug information. But there's probably a better way of isolating the error.


Parser.java (client won't let me attach java file)
...
 112     @SuppressWarnings("unchecked")
 113     public Start parse() throws ParserException, LexerException, IOException
 114     {
 115         push(0, null, true);
 116         List<Node> ign = null;
 117         while(true)
 118         {
 119             while(index(this.lexer.peek()) == -1)
 120             {
 121                 if(ign == null)
 122                 {
 123                     ign = new LinkedList<Node>();
 124                 }
 125
 126                 ign.add(this.lexer.next());
 127             }
 128
 129             if(ign != null)
 130             {
 131                 this.ignoredTokens.setIn(this.lexer.peek(), ign);
 132                 ign = null;
 133             }
 134
 135             this.last_pos = this.lexer.peek().getPos();
 136             this.last_line = this.lexer.peek().getLine();
 137             this.last_token = this.lexer.peek();
 138
 139             int index = index(this.lexer.peek());
 140             this.action[0] = Parser.actionTable[state()][0][1];
 141             this.action[1] = Parser.actionTable[state()][0][2];
 142
 143             int low = 1;
 144             int high = Parser.actionTable[state()].length - 1;
 145
 146             while(low <= high)
 147             {
 148                 int middle = (low + high) / 2;
 149
 150                 if(index < Parser.actionTable[state()][middle][0])
 151                 {
 152                     high = middle - 1;
 153                 }
 154                 else if(index > Parser.actionTable[state()][middle][0])
 155                 {
 156                     low = middle + 1;
 157                 }
 158                 else
 159                 {
 160                     this.action[0] = Parser.actionTable[state()][middle][1];
 161                     this.action[1] = Parser.actionTable[state()][middle][2];
 162                     break;
 163                 }
 164             }
 165
 166             System.out.println("debugging... action["+this.action[0]+"] / lexer.peek["+this.lexer.peek()+"] / state["+state()+"]");
 167
 168             switch(this.action[0])
 169             {
 170                 case SHIFT:
 171                     {


Thanks
Tim



From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Wed, October 7, 2009 8:18:22 PM
Subject: RE: Fixing Parser Weirdness

Have you tried the approach to solving ‘A’ that I suggested in my last posting? If you have and you’re still confused then post the token stream emitted by your lexer and we can go from there.

 

In solving A you may acquire the skills you need to solve B, so I think you should just let B slide for the moment.

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Thursday, October 08, 2009 7:50 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey Chris, thanks for responding to this problem thus far. I've been tied up on other projects, but have come back to these problems. Right now I want to do 2 things:

A) Be able to add a new token (that provides an extra option in the language, -returninput).
B) Allow special characters in an XML block (<mytag value='twashing@...' />).

So looking at problem A), I actually was printing out the characters the Parser was picking from the Lexer. If I add the token on line 98 (see fig. 1), I get the error in fig. 2. Normally, using the expression "login ( user -username root -password password );" works fine. But just with line 98, I get the error that the Parser / Lexer is expecting an opening bracket "(", which is obviously there. So now the question is i) what does it think the "login
(..." is and ii) how does line 98 change a working token to this broken state? I've also re-attached my sablecc file.


97        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
98        returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;

fig. 1 - bkeeping.cc sablecc file


login ( user -username root -password password );
debugging... action[0] / lexer.peek[login ] / state[0]
debugging... action[3] / lexer.peek[( ] / state[12]

ERROR [Thread-3] (Bkell.java:187) - [14,7] expecting: lbracket
com.interrupt.bookkeeping.cc.parser.ParserException: [14,7] expecting: lbracket
    at com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1024)
    at com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:146)
    at java.lang.Thread.run(Thread.java:637)
ERROR [Thread-3] (Util.java:96) - generateBkellException CALLED
ERROR [Thread-3] (Util.java:102) - TOP error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Util.java:103) - ROOT error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Bkell.java:189) - <logs xmlns='com/interrupt/logs' id='' ><log xmlns='com/interrupt/logs' level='ERROR' id='' ><logMessages xmlns='com/interrupt/logs' id='' ><logMessage xmlns='com/interrupt/logs' id='' >[14,7] expecting: lbracket</logMessage>
</logMessages>
</log>

</logs>
fig. 2 - logs


Thanks
Tim



----- Original Message ----
From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, September 3, 2009 10:47:11 PM
Subject: Re: Fixing Parser Weirdness

When I have a problem like this, generally I'll print out the token stream for the affected area and try to match it to the production I think the parser should choose. When I say print out the token stream, I mean print out the actual stream as generated by the lexer.

If you do that, I think you will find that you either have grammatical or lexical problems (either the token stream isn't what you think it is, or the syntax isn't what you want it to be). It's good to get into practice doing this sort of thing because this will come up from time to time and it's best to be able to resolve it by yourself.

Also note that SableCC is telling you what token it thinks should come next. From that you can deduce what production is actually being selected, which again should help you identify the problem.

--- On Thu, 9/3/09, Timothy Washington <timothyjwashington@...> wrote:

> From: Timothy Washington <timothyjwashington@...>
> Subject: Re: Fixing Parser Weirdness
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Thursday, September 3, 2009, 11:49 PM
>
> That's actually a really good point - I made that
> change. But the parser is still breaking with the error in
> fig. 1 when
> I do a simple command ( see fig. 0 ). Ultimately I want to
> make a command like in fig. 2. To remove the error, all I
> have to
> do is remove the "returninput_opt" parts ( lines
> 98 & 288 ). This is what I meant by a sensitive parser,
> because I can't see
> how those 2 lines would break an unrelated token /
> production.
>
>
> login ( user -username root -password password );
> fig. 0
>
>
> login ( user -username root -password password );
> ERROR [Thread-3] (Bkell.java:186) - [4,7] expecting:
> lbracket
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [4,7] expecting:
>  lbracket
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[4,7] expecting:
> lbracket</logMessage>
> </logMessages>
> </log>
> </logs>
>
> ERROR [Thread-3] (Bkell.java:186) - [1,2] expecting:
> 'var', 'create', 'add',
> 'update', 'remove', 'reverse',
> 'find', 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [1,2] expecting: 'var', 'create',
> 'add', 'update', 'remove',
>  'reverse', 'find', 'list',
> 'print', 'commit', 'load',
> 'login', 'logout',
> 'exit'
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[1,2] expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print', 'commit',
> 'load', 'login', 'logout',
> 'exit'</logMessage>
> </logMessages>
> </log>
> </logs>
> ...
>
> fig. 1
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>           
>  <user xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000' >
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details' >
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...'
>  />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>           
>    </profileDetails>
>           
> </user>
>            ,
>           
> -returninput
> true
>        );
>
> fig. 2
>
>
> Tim
>
>
>
> From: Christopher Van Kirk
> <chris.vankirk@...>
> To:
> Discussion mailing list for the SableCC project
> <sablecc-discussion@...>
> Sent:
> Thursday, September 3, 2009 12:08:21 AM
> Subject: RE:
> Fixing Parser Weirdness
>
>
>
>

>
>

>
>
>
>
>
>
>
>
>
> This is
> probably your problem:
>

>
> dash = '-';
>
> .
>
> .
>
> .
>
> entry_opt = '-entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> You’ve
> defined a dash token in the lexer
> section, but you’re expecting to see it joined to a word
> in the parser,
> Remember that what comes out of the Tokens section is a
> stream of tokens you
> have defined there, so what your parser will see
> is
>

>
> dash
> entry …
> not -entry
>

>
> Try
> changing your production to something
> like:
>

>
> entry_opt = dash
> 'entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> Cheers,
>

>
> Chris…
>

>
> -----Original
> Message-----
>
> From:
> sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
> [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...]
> On Behalf Of
> Timothy Washington
>
> Sent:
> Wednesday,
>  September 02, 2009
> 11:43
> PM
>
> To:
> sablecc-discussion@...
>
> Subject:
> Fixing Parser Weirdness
>

>
>
>
>
>
> Hey
> all, I've implemented a language using sablecc that
> looks like in fig. 1.
>
>
>
> command(
>
>    ( <context/> )
>
>        <input/>,
>
>        `/input[
> @att='value' ]`,
>
>        -inputoption value
>
> );
>
> fig. 1
>
>
>
>
>
>
>
> A) I'm trying to implement an input option, "
> -inputoption value ",
> but if I try to implement the command in fig. 2, I get the
> error
>
> seen in fig. 4.
>
>
>
> var removedE = remove ( ( load( `/system[
> @id="main.system" ]/groups[
> @id="main.groups" ]/group[
> @id="seven.group" ]/bookkeeping[
> @id="main.bookkeeping" ]/journals[
> @id="main.journals"
> ]/journal[ @id="generalledger" ]/entries[
> @id="main.entries" ]` ) )
>
>        <entry
> xmlns='com/interrupt/bookkeeping/journal'
> id='qwer' entrynum='' state=''
> journalid='' date='02022006'
> currency='CDN' > 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='asdf' amount='11.00' entryid=''
> accountid='1' account='office equipment'
> currency='CDN' /> 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='zxcv' amount='1.50' entryid=''
> accountid='2' account='tax'
> currency='CDN' /> 
>
>           
> <credit
> xmlns='com/interrupt/bookkeeping/account'
> id='tyui' amount='12.50' entryid=''
> accountid='3' account='bank'
> currency='CDN' /> 
>
>        </entry>
>
>        ,
>
>       
> -returninput
> true
>
>    );
>
> fig. 2
>
>
>
>
>
>
>
> B) I'm also trying to get SableCC to ignore special
> characters between single
> and double quotes ( ' " ). So for example, I want
>
>
> to be able to say <profileDetail
> value='twashing@...' />, but the
> parser dies with the error in fig. 5.
>
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>
>           
> <user
> xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000'
> >
>
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details'
> >
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>
>           
>    </profileDetails>
>
>           
> </user>
>
>        );
>
> fig. 3
>
>
>
>
>
> It feels like Sablecc is very sensitive in the order of
> tokens. Can anyone help
> me isolate and fix this problem. I've attached
>
> my sablecc file.
>
>
>
>
>
> Thanks in advance
>
> Tim
>
>
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [1,1]
> expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1028)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 4
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [19,3]
> expecting:
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit', 'system',
> 'debit', 'credit',
> 'entry', 'entries', 'journal',
> 'journals', 'transaction',
> 'account',
> 'accounts', 'user', 'users',
> 'group', 'groups', 'allowedActions',
> 'command',
> 'profileDetails', 'profileDetail',
> 'userSession', '<', rbracket, atsign,
> '`'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 5
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
> Looking for the
> perfect gift? Give the gift of
> Flickr!
>
>
>
>
>
>     
> Looking for the perfect gift? Give
> the gift of Flickr!
> -----Inline Attachment Follows-----
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date: 10/07/09 20:49:00



Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

RE: Fixing Parser Weirdness

by Christopher Van Kirk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

This is a useful gem from Indrek Mandre that prints out the lexer stream (my version is for .net but you can translate easily). Use this then analyse the lexer output and see if you can match it to your syntax. I suspect you’re getting tokens you don’t expect.

 

class TestLexer

{

  public static void Main(String[] args)

  {

    Lexer l = new Lexer(Console.In);

    while (true)

    {

        Token token = l.Next();

        Console.WriteLine ("Read token '" + token.GetType().Name +

            "', Text = [" + token.Text + "] at [" + token.Line +

            "," + token.Pos + "]");

        if ( token is EOF ) break;

    }

  }

}

 

 

 

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Friday, October 09, 2009 5:37 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey there, thanks for the feedback. Agreed, I think that if I solve 'A', thenthe rest will fall into place. What I am spitting out, the stream as you put it, is the "action array / lexer.peek() / state" as seen from the Parser's point of view. The output was in bold red in fig. 2 (logs). Line 98 in fig. 1 was what generated that error (everything works if I remove 98). And see line 166 from the Parser.parse method below. That's where I'm putting the debug information. But there's probably a better way of isolating the error.


Parser.java (client won't let me attach java file)
...
 112     @SuppressWarnings("unchecked")
 113     public Start parse() throws ParserException, LexerException, IOException
 114     {
 115         push(0, null, true);
 116         List<Node> ign = null;
 117         while(true)
 118         {
 119             while(index(this.lexer.peek()) == -1)
 120             {
 121                 if(ign == null)
 122                 {
 123                     ign = new LinkedList<Node>();
 124                 }
 125
 126                 ign.add(this.lexer.next());
 127             }
 128
 129             if(ign != null)
 130             {
 131                 this.ignoredTokens.setIn(this.lexer.peek(), ign);
 132                 ign = null;
 133             }
 134
 135             this.last_pos = this.lexer.peek().getPos();
 136             this.last_line = this.lexer.peek().getLine();
 137             this.last_token = this.lexer.peek();
 138
 139             int index = index(this.lexer.peek());
 140             this.action[0] = Parser.actionTable[state()][0][1];
 141             this.action[1] = Parser.actionTable[state()][0][2];
 142
 143             int low = 1;
 144             int high = Parser.actionTable[state()].length - 1;

 145
 146             while(low <= high)
 147             {
 148                 int middle = (low + high) / 2;
 149
 150                 if(index < Parser.actionTable[state()][middle][0])
 151                 {
 152                     high = middle - 1;
 153                 }
 154                 else if(index > Parser.actionTable[state()][middle][0])
 155                 {
 156                     low = middle + 1;
 157                 }
 158                 else
 159                 {
 160                     this.action[0] = Parser.actionTable[state()][middle][1];
 161                     this.action[1] = Parser.actionTable[state()][middle][2];
 162                     break;
 163                 }
 164             }
 165
 166             System.out.println("debugging... action["+this.action[0]+"] / lexer.peek["+this.lexer.peek()+"] / state["+state()+"]");
 167
 168             switch(this.action[0])
 169             {
 170                 case SHIFT:
 171                     {



Thanks
Tim

 


From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent:
Wed, October 7, 2009 8:18:22 PM
Subject: RE: Fixing Parser Weirdness

Have you tried the approach to solving ‘A’ that I suggested in my last posting? If you have and you’re still confused then post the token stream emitted by your lexer and we can go from there.

 

In solving A you may acquire the skills you need to solve B, so I think you should just let B slide for the moment.

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Thursday, October 08, 2009 7:50 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey Chris, thanks for responding to this problem thus far. I've been tied up on other projects, but have come back to these problems. Right now I want to do 2 things:

A) Be able to add a new token (that provides an extra option in the language, -returninput).
B) Allow special characters in an XML block (<mytag value='twashing@...' />).

So looking at problem A), I actually was printing out the characters the Parser was picking from the Lexer. If I add the token on line 98 (see fig. 1), I get the error in fig. 2. Normally, using the expression "login ( user -username root -password password );" works fine. But just with line 98, I get the error that the Parser / Lexer is expecting an opening bracket "(", which is obviously there. So now the question is i) what does it think the "login
(..." is and ii) how does line 98 change a working token to this broken state? I've also re-attached my sablecc file.


97        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
98        returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;

fig. 1 - bkeeping.cc sablecc file


login ( user -username root -password password );
debugging... action[0] / lexer.peek[login ] / state[0]
debugging... action[3] / lexer.peek[( ] / state[12]

ERROR [Thread-3] (Bkell.java:187) - [14,7] expecting: lbracket
com.interrupt.bookkeeping.cc.parser.ParserException: [14,7] expecting: lbracket
    at com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1024)
    at com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:146)
    at java.lang.Thread.run(Thread.java:637)
ERROR [Thread-3] (Util.java:96) - generateBkellException CALLED
ERROR [Thread-3] (Util.java:102) - TOP error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Util.java:103) - ROOT error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Bkell.java:189) - <logs xmlns='com/interrupt/logs' id='' ><log xmlns='com/interrupt/logs' level='ERROR' id='' ><logMessages xmlns='com/interrupt/logs' id='' ><logMessage xmlns='com/interrupt/logs' id='' >[14,7] expecting: lbracket</logMessage>
</logMessages>
</log>

</logs>
fig. 2 - logs


Thanks
Tim



----- Original Message ----
From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, September 3, 2009 10:47:11 PM
Subject: Re: Fixing Parser Weirdness

When I have a problem like this, generally I'll print out the token stream for the affected area and try to match it to the production I think the parser should choose. When I say print out the token stream, I mean print out the actual stream as generated by the lexer.

If you do that, I think you will find that you either have grammatical or lexical problems (either the token stream isn't what you think it is, or the syntax isn't what you want it to be). It's good to get into practice doing this sort of thing because this will come up from time to time and it's best to be able to resolve it by yourself.

Also note that SableCC is telling you what token it thinks should come next. From that you can deduce what production is actually being selected, which again should help you identify the problem.

--- On Thu, 9/3/09, Timothy Washington <timothyjwashington@...> wrote:

> From: Timothy Washington <timothyjwashington@...>
> Subject: Re: Fixing Parser Weirdness
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Thursday, September 3, 2009, 11:49 PM
>
> That's actually a really good point - I made that
> change. But the parser is still breaking with the error in
> fig. 1 when
> I do a simple command ( see fig. 0 ). Ultimately I want to
> make a command like in fig. 2. To remove the error, all I
> have to
> do is remove the "returninput_opt" parts ( lines
> 98 & 288 ). This is what I meant by a sensitive parser,
> because I can't see
> how those 2 lines would break an unrelated token /
> production.
>
>
> login ( user -username root -password password );
> fig. 0
>
>
> login ( user -username root -password password );
> ERROR [Thread-3] (Bkell.java:186) - [4,7] expecting:
> lbracket
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [4,7] expecting:
>  lbracket
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[4,7] expecting:
> lbracket</logMessage>
> </logMessages>
> </log>
> </logs>
>
> ERROR [Thread-3] (Bkell.java:186) - [1,2] expecting:
> 'var', 'create', 'add',
> 'update', 'remove', 'reverse',
> 'find', 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [1,2] expecting: 'var', 'create',
> 'add', 'update', 'remove',
>  'reverse', 'find', 'list',
> 'print', 'commit', 'load',
> 'login', 'logout',
> 'exit'
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[1,2] expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print', 'commit',
> 'load', 'login', 'logout',
> 'exit'</logMessage>
> </logMessages>
> </log>
> </logs>
> ...
>
> fig. 1
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>           
>  <user xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000' >
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details' >
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...'
>  />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>           
>    </profileDetails>
>           
> </user>
>            ,
>           
> -returninput
> true
>        );
>
> fig. 2
>
>
> Tim
>
>
>
> From: Christopher Van Kirk
> <chris.vankirk@...>
> To:
> Discussion mailing list for the SableCC project
> <sablecc-discussion@...>
> Sent:
> Thursday, September 3, 2009 12:08:21 AM
> Subject: RE:
> Fixing Parser Weirdness
>
>
>
>

>
>

>
>
>
>
>
>
>
>
>
> This is
> probably your problem:
>

>
> dash = '-';
>
> .
>
> .
>
> .
>
> entry_opt = '-entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> You’ve
> defined a dash token in the lexer
> section, but you’re expecting to see it joined to a word
> in the parser,
> Remember that what comes out of the Tokens section is a
> stream of tokens you
> have defined there, so what your parser will see
> is
>

>
> dash
> entry …
> not -entry
>

>
> Try
> changing your production to something
> like:
>

>
> entry_opt = dash
> 'entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> Cheers,
>

>
> Chris…
>

>
> -----Original
> Message-----
>
> From:
> sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
> [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...]
> On Behalf Of
> Timothy Washington
>
> Sent:
> Wednesday,
>  September 02, 2009
> 11:43
> PM
>
> To:
> sablecc-discussion@...
>
> Subject:
> Fixing Parser Weirdness
>

>
>
>
>
>
> Hey
> all, I've implemented a language using sablecc that
> looks like in fig. 1.
>
>
>
> command(
>
>    ( <context/> )
>
>        <input/>,
>
>        `/input[
> @att='value' ]`,
>
>        -inputoption value
>
> );
>
> fig. 1
>
>
>
>
>
>
>
> A) I'm trying to implement an input option, "
> -inputoption value ",
> but if I try to implement the command in fig. 2, I get the
> error
>
> seen in fig. 4.
>
>
>
> var removedE = remove ( ( load( `/system[
> @id="main.system" ]/groups[
> @id="main.groups" ]/group[
> @id="seven.group" ]/bookkeeping[
> @id="main.bookkeeping" ]/journals[
> @id="main.journals"
> ]/journal[ @id="generalledger" ]/entries[
> @id="main.entries" ]` ) )
>
>        <entry
> xmlns='com/interrupt/bookkeeping/journal'
> id='qwer' entrynum='' state=''
> journalid='' date='02022006'
> currency='CDN' > 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='asdf' amount='11.00' entryid=''
> accountid='1' account='office equipment'
> currency='CDN' /> 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='zxcv' amount='1.50' entryid=''
> accountid='2' account='tax'
> currency='CDN' /> 
>
>           
> <credit
> xmlns='com/interrupt/bookkeeping/account'
> id='tyui' amount='12.50' entryid=''
> accountid='3' account='bank'
> currency='CDN' /> 
>
>        </entry>
>
>        ,
>
>       
> -returninput
> true
>
>    );
>
> fig. 2
>
>
>
>
>
>
>
> B) I'm also trying to get SableCC to ignore special
> characters between single
> and double quotes ( ' " ). So for example, I want
>
>
> to be able to say <profileDetail
> value='twashing@...' />, but the
> parser dies with the error in fig. 5.
>
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>
>           
> <user
> xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000'
> >
>
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details'
> >
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>
>           
>    </profileDetails>
>
>           
> </user>
>
>        );
>
> fig. 3
>
>
>
>
>
> It feels like Sablecc is very sensitive in the order of
> tokens. Can anyone help
> me isolate and fix this problem. I've attached
>
> my sablecc file.
>
>
>
>
>
> Thanks in advance
>
> Tim
>
>
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [1,1]
> expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1028)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 4
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [19,3]
> expecting:
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit', 'system',
> 'debit', 'credit',
> 'entry', 'entries', 'journal',
> 'journals', 'transaction',
> 'account',
> 'accounts', 'user', 'users',
> 'group', 'groups', 'allowedActions',
> 'command',
> 'profileDetails', 'profileDetail',
> 'userSession', '<', rbracket, atsign,
> '`'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 5
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
> Looking for the
> perfect gift? Give the gift of
> Flickr!
>
>
>
>
>
>     
> Looking for the perfect gift? Give
> the gift of Flickr!
> -----Inline Attachment Follows-----
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date:
10/07/09 20:49:00

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date: 10/08/09 18:33:00


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: Fixing Parser Weirdness

by twashing :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Ok great. I got this problem sorted out. A long haul, but looking at the token stream definitely helped.

Thanks a bunch Chris
Tim



From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, October 8, 2009 10:39:39 PM
Subject: RE: Fixing Parser Weirdness

This is a useful gem from Indrek Mandre that prints out the lexer stream (my version is for .net but you can translate easily). Use this then analyse the lexer output and see if you can match it to your syntax. I suspect you’re getting tokens you don’t expect.

 

class TestLexer

{

  public static void Main(String[] args)

  {

    Lexer l = new Lexer(Console.In);

    while (true)

    {

        Token token = l.Next();

        Console.WriteLine ("Read token '" + token.GetType().Name +

            "', Text = [" + token.Text + "] at [" + token.Line +

            "," + token.Pos + "]");

        if ( token is EOF ) break;

    }

  }

}

 

 

 

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Friday, October 09, 2009 5:37 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey there, thanks for the feedback. Agreed, I think that if I solve 'A', thenthe rest will fall into place. What I am spitting out, the stream as you put it, is the "action array / lexer.peek() / state" as seen from the Parser's point of view. The output was in bold red in fig. 2 (logs). Line 98 in fig. 1 was what generated that error (everything works if I remove 98). And see line 166 from the Parser.parse method below. That's where I'm putting the debug information. But there's probably a better way of isolating the error.


Parser.java (client won't let me attach java file)
...
 112     @SuppressWarnings("unchecked")
 113     public Start parse() throws ParserException, LexerException, IOException
 114     {
 115         push(0, null, true);
 116         List<Node> ign = null;
 117         while(true)
 118         {
 119             while(index(this.lexer.peek()) == -1)
 120             {
 121                 if(ign == null)
 122                 {
 123                     ign = new LinkedList<Node>();
 124                 }
 125
 126                 ign.add(this.lexer.next());
 127             }
 128
 129             if(ign != null)
 130             {
 131                 this.ignoredTokens.setIn(this.lexer.peek(), ign);
 132                 ign = null;
 133             }
 134
 135             this.last_pos = this.lexer.peek().getPos();
 136             this.last_line = this.lexer.peek().getLine();
 137             this.last_token = this.lexer.peek();
 138
 139             int index = index(this.lexer.peek());
 140             this.action[0] = Parser.actionTable[state()][0][1];
 141             this.action[1] = Parser.actionTable[state()][0][2];
 142
 143             int low = 1;
 144             int high = Parser.actionTable[state()].length - 1;

 145
 146             while(low <= high)
 147             {
 148                 int middle = (low + high) / 2;
 149
 150                 if(index < Parser.actionTable[state()][middle][0])
 151                 {
 152                     high = middle - 1;
 153                 }
 154                 else if(index > Parser.actionTable[state()][middle][0])
 155                 {
 156                     low = middle + 1;
 157                 }
 158                 else
 159                 {
 160                     this.action[0] = Parser.actionTable[state()][middle][1];
 161                     this.action[1] = Parser.actionTable[state()][middle][2];
 162                     break;
 163                 }
 164             }
 165
 166             System.out.println("debugging... action["+this.action[0]+"] / lexer.peek["+this.lexer.peek()+"] / state["+state()+"]");
 167
 168             switch(this.action[0])
 169             {
 170                 case SHIFT:
 171                     {



Thanks
Tim

 


From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent:
Wed, October 7, 2009 8:18:22 PM
Subject: RE: Fixing Parser Weirdness

Have you tried the approach to solving ‘A’ that I suggested in my last posting? If you have and you’re still confused then post the token stream emitted by your lexer and we can go from there.

 

In solving A you may acquire the skills you need to solve B, so I think you should just let B slide for the moment.

 

-----Original Message-----
From: sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@... [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...] On Behalf Of Timothy Washington
Sent:
Thursday, October 08, 2009 7:50 AM
To: Discussion mailing list for the SableCC project
Subject: Re: Fixing Parser Weirdness

 

Hey Chris, thanks for responding to this problem thus far. I've been tied up on other projects, but have come back to these problems. Right now I want to do 2 things:

A) Be able to add a new token (that provides an extra option in the language, -returninput).
B) Allow special characters in an XML block (<mytag value='twashing@...' />).

So looking at problem A), I actually was printing out the characters the Parser was picking from the Lexer. If I add the token on line 98 (see fig. 1), I get the error in fig. 2. Normally, using the expression "login ( user -username root -password password );" works fine. But just with line 98, I get the error that the Parser / Lexer is expecting an opening bracket "(", which is obviously there. So now the question is i) what does it think the "login
(..." is and ii) how does line 98 change a working token to this broken state? I've also re-attached my sablecc file.


97        currency_opt = '-currency' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;
98        returninput_opt = '-returninput' ws+ ( lowercase | uppercase | dash | colon_helper | ats | underscore | digit | dot )*;

fig. 1 - bkeeping.cc sablecc file


login ( user -username root -password password );
debugging... action[0] / lexer.peek[login ] / state[0]
debugging... action[3] / lexer.peek[( ] / state[12]

ERROR [Thread-3] (Bkell.java:187) - [14,7] expecting: lbracket
com.interrupt.bookkeeping.cc.parser.ParserException: [14,7] expecting: lbracket
    at com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1024)
    at com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:146)
    at java.lang.Thread.run(Thread.java:637)
ERROR [Thread-3] (Util.java:96) - generateBkellException CALLED
ERROR [Thread-3] (Util.java:102) - TOP error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Util.java:103) - ROOT error message[[14,7] expecting: lbracket]
ERROR [Thread-3] (Bkell.java:189) - <logs xmlns='com/interrupt/logs' id='' ><log xmlns='com/interrupt/logs' level='ERROR' id='' ><logMessages xmlns='com/interrupt/logs' id='' ><logMessage xmlns='com/interrupt/logs' id='' >[14,7] expecting: lbracket</logMessage>
</logMessages>
</log>

</logs>
fig. 2 - logs


Thanks
Tim



----- Original Message ----
From: Christopher Van Kirk <chris.vankirk@...>
To: Discussion mailing list for the SableCC project <sablecc-discussion@...>
Sent: Thu, September 3, 2009 10:47:11 PM
Subject: Re: Fixing Parser Weirdness

When I have a problem like this, generally I'll print out the token stream for the affected area and try to match it to the production I think the parser should choose. When I say print out the token stream, I mean print out the actual stream as generated by the lexer.

If you do that, I think you will find that you either have grammatical or lexical problems (either the token stream isn't what you think it is, or the syntax isn't what you want it to be). It's good to get into practice doing this sort of thing because this will come up from time to time and it's best to be able to resolve it by yourself.

Also note that SableCC is telling you what token it thinks should come next. From that you can deduce what production is actually being selected, which again should help you identify the problem.

--- On Thu, 9/3/09, Timothy Washington <timothyjwashington@...> wrote:

> From: Timothy Washington <timothyjwashington@...>
> Subject: Re: Fixing Parser Weirdness
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Date: Thursday, September 3, 2009, 11:49 PM
>
> That's actually a really good point - I made that
> change. But the parser is still breaking with the error in
> fig. 1 when
> I do a simple command ( see fig. 0 ). Ultimately I want to
> make a command like in fig. 2. To remove the error, all I
> have to
> do is remove the "returninput_opt" parts ( lines
> 98 & 288 ). This is what I meant by a sensitive parser,
> because I can't see
> how those 2 lines would break an unrelated token /
> production.
>
>
> login ( user -username root -password password );
> fig. 0
>
>
> login ( user -username root -password password );
> ERROR [Thread-3] (Bkell.java:186) - [4,7] expecting:
> lbracket
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [4,7] expecting:
>  lbracket
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[4,7] expecting:
> lbracket</logMessage>
> </logMessages>
> </log>
> </logs>
>
> ERROR [Thread-3] (Bkell.java:186) - [1,2] expecting:
> 'var', 'create', 'add',
> 'update', 'remove', 'reverse',
> 'find', 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
> com.interrupt.bookkeeping.cc.parser.ParserException:
> [1,2] expecting: 'var', 'create',
> 'add', 'update', 'remove',
>  'reverse', 'find', 'list',
> 'print', 'commit', 'load',
> 'login', 'logout',
> 'exit'
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>    at
> java.lang.Thread.run(Thread.java:637)
> ERROR [Thread-3] (Bkell.java:188) - <logs
> xmlns='com/interrupt/logs' id='' ><log
> xmlns='com/interrupt/logs' level='ERROR'
> id='' ><logMessages
> xmlns='com/interrupt/logs' id=''
> ><logMessage xmlns='com/interrupt/logs'
> id='' >[1,2] expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print', 'commit',
> 'load', 'login', 'logout',
> 'exit'</logMessage>
> </logMessages>
> </log>
> </logs>
> ...
>
> fig. 1
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>           
>  <user xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000' >
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details' >
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...'
>  />
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>           
>    </profileDetails>
>           
> </user>
>            ,
>           
> -returninput
> true
>        );
>
> fig. 2
>
>
> Tim
>
>
>
> From: Christopher Van Kirk
> <chris.vankirk@...>
> To:
> Discussion mailing list for the SableCC project
> <sablecc-discussion@...>
> Sent:
> Thursday, September 3, 2009 12:08:21 AM
> Subject: RE:
> Fixing Parser Weirdness
>
>
>
>

>
>

>
>
>
>
>
>
>
>
>
> This is
> probably your problem:
>

>
> dash = '-';
>
> .
>
> .
>
> .
>
> entry_opt = '-entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> You’ve
> defined a dash token in the lexer
> section, but you’re expecting to see it joined to a word
> in the parser,
> Remember that what comes out of the Tokens section is a
> stream of tokens you
> have defined there, so what your parser will see
> is
>

>
> dash
> entry …
> not -entry
>

>
> Try
> changing your production to something
> like:
>

>
> entry_opt = dash
> 'entry' ws+ (
> lowercase | uppercase | dash | colon_helper |  ats |
> underscore | digit | dot
> )*;
>

>
> Cheers,
>

>
> Chris…
>

>
> -----Original
> Message-----
>
> From:
> sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...
> [mailto:sablecc-discussion-bounces+chris.vankirk=fdcjapan.com@...]
> On Behalf Of
> Timothy Washington
>
> Sent:
> Wednesday,
>  September 02, 2009
> 11:43
> PM
>
> To:
> sablecc-discussion@...
>
> Subject:
> Fixing Parser Weirdness
>

>
>
>
>
>
> Hey
> all, I've implemented a language using sablecc that
> looks like in fig. 1.
>
>
>
> command(
>
>    ( <context/> )
>
>        <input/>,
>
>        `/input[
> @att='value' ]`,
>
>        -inputoption value
>
> );
>
> fig. 1
>
>
>
>
>
>
>
> A) I'm trying to implement an input option, "
> -inputoption value ",
> but if I try to implement the command in fig. 2, I get the
> error
>
> seen in fig. 4.
>
>
>
> var removedE = remove ( ( load( `/system[
> @id="main.system" ]/groups[
> @id="main.groups" ]/group[
> @id="seven.group" ]/bookkeeping[
> @id="main.bookkeeping" ]/journals[
> @id="main.journals"
> ]/journal[ @id="generalledger" ]/entries[
> @id="main.entries" ]` ) )
>
>        <entry
> xmlns='com/interrupt/bookkeeping/journal'
> id='qwer' entrynum='' state=''
> journalid='' date='02022006'
> currency='CDN' > 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='asdf' amount='11.00' entryid=''
> accountid='1' account='office equipment'
> currency='CDN' /> 
>
>           
> <debit
> xmlns='com/interrupt/bookkeeping/account'
> id='zxcv' amount='1.50' entryid=''
> accountid='2' account='tax'
> currency='CDN' /> 
>
>           
> <credit
> xmlns='com/interrupt/bookkeeping/account'
> id='tyui' amount='12.50' entryid=''
> accountid='3' account='bank'
> currency='CDN' /> 
>
>        </entry>
>
>        ,
>
>       
> -returninput
> true
>
>    );
>
> fig. 2
>
>
>
>
>
>
>
> B) I'm also trying to get SableCC to ignore special
> characters between single
> and double quotes ( ' " ). So for example, I want
>
>
> to be able to say <profileDetail
> value='twashing@...' />, but the
> parser dies with the error in fig. 5.
>
>
>
> var aauthUsers = add ( ( load ( `/system[
> @id='main.system' ]` ) )
>
>           
> <user
> xmlns='com/interrupt/bookkeeping/users'
> id='seven' username='seven'
> password='seven' logintimeout='600000'
> >
>
>               
> <profileDetails
> xmlns='com/interrupt/bookkeeping/users'
> id='user.details'
> >
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='firstname' name='first.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='lastname' name='last.name'
> value='seven' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='email' name='email'
> value='twashing@...' />
>
>               
>    <profileDetail
> xmlns='com/interrupt/bookkeeping/users'
> id='country' name='country'
> value='U.S.A' />
>
>           
>    </profileDetails>
>
>           
> </user>
>
>        );
>
> fig. 3
>
>
>
>
>
> It feels like Sablecc is very sensitive in the order of
> tokens. Can anyone help
> me isolate and fix this problem. I've attached
>
> my sablecc file.
>
>
>
>
>
> Thanks in advance
>
> Tim
>
>
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [1,1]
> expecting: 'var',
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1028)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 4
>
>
>
>
>
> com.interrupt.bookkeeping.cc.parser.ParserException: [19,3]
> expecting:
> 'create', 'add', 'update',
> 'remove', 'reverse', 'find',
> 'list', 'print',
> 'commit', 'load', 'login',
> 'logout', 'exit', 'system',
> 'debit', 'credit',
> 'entry', 'entries', 'journal',
> 'journals', 'transaction',
> 'account',
> 'accounts', 'user', 'users',
> 'group', 'groups', 'allowedActions',
> 'command',
> 'profileDetails', 'profileDetail',
> 'userSession', '<', rbracket, atsign,
> '`'
>
>    at
> com.interrupt.bookkeeping.cc.parser.Parser.parse(Parser.java:1022)
>
>    at
> com.interrupt.bookkeeping.cc.bkell.Bkell.run(Bkell.java:145)
>
>    at
> java.lang.Thread.run(Thread.java:637)
>
> fig. 5
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
> Looking for the
> perfect gift? Give the gift of
> Flickr!
>
>
>
>
>
>     
> Looking for the perfect gift? Give
> the gift of Flickr!
> -----Inline Attachment Follows-----
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion
>

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date:
10/07/09 20:49:00

 


Yahoo! Canada Toolbar : Search from anywhere on the web and bookmark your favourite sites. Download it now!

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.421 / Virus Database: 270.14.3/2414 - Release Date: 10/08/09 18:33:00



Get the name you've always wanted ! @ymail.com or @rocketmail.com.
_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion