[antlr-interest] Unexpected results from an antlr parser

Loring Craymer lgcraymer at yahoo.com
Thu Aug 3 00:18:28 PDT 2006


Your result matches your grammar.  You would get the desired result if your second line was <<(d5=a)>>.  As it is, dict invokes alias (only one DICT_START) and expects (d5=1).  The desired result is that dict invokes metadict which invokes cell.

--Loring

Jeff Prickett <prickett at ineighborhood.info> wrote: 
Hello,

I am attempting to write a parser to parse the mozilla mork grammar. I 
am having problems.
In the first part of the file is usually a dictionary where data (or 
cells) are encoded between parenthesis like this

...(hexId=value)...

Everything works fine up to the equals sign and then it fails to match 
the value.

The output of the program is:

start
magic
space
space
items
object
dict
space
alias
id=D5
line 1:43: expecting LITERAL_1, found 'a'
space

I have tried substituting different rules for LITERAL_1 to see if it was 
not a problem with that rule, but it does not match anything. I even 
tried a dummy rule that match the character 'a' and the string 'a' and 
got no change in output.

I have attached the simplest mork file to demonstrate the problem and 
the Mork.g file.

I am using antlr 2.7.6.

Any help is greatly appreciated.

Thanks,
Jeff Prickett
prickett at ineighborhood.info


//  -->

<(D5=a)>
header
{
package info.ineighborhood.mork.antlr;
}

class MorkParser extends Parser;

options
{
    k=4;
}    

start
{
    System.out.println("start");
}
: magic (items | group)+;

space
{
    System.out.println("space");
}
: (WHITE)*;

items
{
    System.out.println("items");
}
: (object)*; 

group
{
    System.out.println("group");
}
: gather items (commit | abort);

gather
{
    System.out.println("gather");
}
: space GATHER_START id GATHER_START_2;

commit
{
    System.out.println("commit");
}
: space COMMIT_END id COMMIT_END_2;

abort
{
    System.out.println("abort");
}
: space ABORT_END id COMMIT_END_2;

id
: h:HEX_SEQUENCE
{
    System.out.println("id=" + h.getText());
};    
   

oid
{
    System.out.println("oid");
}
: id | id:scope;

object
{
    System.out.println("object");
}
: (dict);

edit
{
    System.out.println("edit");
}
: EDIT_CHARS;

update
{
    System.out.println("update");
}
: edit(row | table);

dict
{
    System.out.println("dict");
}
: space DICT_START (metadict|alias)* space DICT_END;

metadict
{
    System.out.println("metadict");
}
: DICT_START (cell)* DICT_END;

alias
{
    System.out.println("alias");
}
: CELL_START id EQUALS literal_1 CELL_END;

value
{
    System.out.println("value");
}
: (OID_START oid) | (EQUALS literal_1);

literal_1
{
    System.out.println("literal");
}
: LITERAL_1;

row
{
    System.out.println("row");
}
: ROW_START roid(metarow |cell)* ROW_END;

roid
{
    System.out.println("roid");
}
: oid;

metarow
{
    System.out.println("metarow");
}
: ROW_START (cell)* ROW_END;

cell
{
    System.out.println("cell");
}
: CELL_START col slot CELL_END;

col
{
    System.out.println("col");
}
: (OID_START oid)|name;

slot
{
    System.out.println("slot");
}
: (OID_START oid)|(EQUALS literal_1);

name
{
    System.out.println("name");
}
: (NAME_CHARS)+;

table
{
    System.out.println("table");
}
: TABLE_START toid(metatable | row | roid)* TABLE_END;

toid
{
    System.out.println("toid");
}
: oid;

metatable
{
    System.out.println("metatable");
}
: TABLE_START (cell)* TABLE_END;

magic
{
    System.out.println("magic");
}
: space MAGIC_STRING space;

scope
{
    System.out.println("scope");
}
: (COL1 | COL2 | ATOM1 | ATOM2);

class MorkLexer extends Lexer;

options
{
    k=4;
    charVocabulary='\u0000'..'\ufffe';
}

WHITE: ('\r' | '\f' | '\u0009' | '\u0020' | '\n');
GATHER_START: "@$${";
GATHER_START_2: "{@";
COMMIT_END: "@$$}";
ABORT_END: "@$$}~abort~";
COMMIT_END_2: "@}";
HEX_SEQUENCE: ('0'..'9' | 'a'..'f' | 'A'..'F')+;
EDIT_CHARS: ('+' | '-' | '!');
DICT_START: '<';
DICT_END: '>';
TABLE_START: '{';
TABLE_END: '}';
OID_START: '^';
CELL_START: '(';
CELL_END: ')';
EQUALS: '=';
NAME_CHARS: ('a'..'z' | 'A'..'Z' | ':' | '_')('a'..'z' | 'A'..'Z' | ':' | '_' | '+' | '-' | '?' | '!')*;
MAGIC_STRING: "//  -->";
COL1: 'c';
COL2: "col";
ATOM1: 'a';
ATOM2: "atom";
COLON: ':';
LITERALS_1: (~')')*;


 		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060803/3b8687b5/attachment.html


More information about the antlr-interest mailing list