简体   繁体   中英

What is wrong with this ParseKit grammar?

Here is a document that I'm trying to parse:

Tha Dhi Thom Num ThaKaThaRiKiTaThaKa 
ThaKaThaRiKiTaThaKa = Ta Tha Chap Tha Ki Ta Tha Ka

and I've defined the grammar as follows:

@start = expr;

expr = singleExpr+ phraseDictionary*;

singleExpr = aksharaGroup;

phraseDictionary = phrase '='! aksharaGroup;

phrase = Word;

aksharaGroup = akshara+ ('/'! noteDuration)?;

akshara = tha | dhi | thom | num | ki | ta | ka | chap | phrase;

noteDuration = Number;

tha = 'Tha';
dhi = 'Dhi';
thom = 'Thom';
num = 'Num';
ki = 'Ki';
ta = 'Ta';
ka = 'Ka';
chap = 'Chap';

The part where I'm having problems is the phraseDictionary - the second ThaKaThaRiKiTaThaKa gets parsed as a phrase, akshara and aksharaGroup, as expected, but then I get exceptions where I expect it to match it phraseDictionary

Expected : /
Line : 2
Near : = Ta 
Found : =

Expected : Uppercase Word
Line : 2
Near : = Ta 
Found : =

Expected : «EOF»
Line : 2
Near : = Ta 
Found : =

With ParseKit's infinite lookahead, shouldn't it proceed and match the phraseDictionary grammar?

What am I missing?

Thanks, Sridhar

Developer of ParseKit here.

Your grammar is working for me with ParseKit head of trunk on google code.

Here's the PKAssembly output from the parse:

[Tha, Dhi, Thom, Num, ThaKaThaRiKiTaThaKa, ThaKaThaRiKiTaThaKa, Ta, Tha, Chap, Tha, Ki, Ta, Tha, Ka]Tha/Dhi/Thom/Num/ThaKaThaRiKiTaThaKa/ThaKaThaRiKiTaThaKa/=/Ta/Tha/Chap/Tha/Ki/Ta/Tha/Ka^

The stack (inside the square braces) and the caret at the end indicate the parser generated from your grammar was able to successfully recognize your input all the way to the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM