regex - Unambiguous Grammar for Regular Expressions -
regex - Unambiguous Grammar for Regular Expressions -
i'm trying develop recursive decent parser regular expressions homework assignment. wanted inquire community if grammar i've developed right or if i'm on right track:
-= regex grammar (ebnf) =- <start> -> <expr> '\n' <expr> -> <expr> { '|' <term> } // union | <expr> { <expr> } // concatenation | <expr> '*' // closure | <term> <term> -> '(' <expr> ')' | <char> // grouping | <char> <char> -> a|b|c| ... |z a few guidelines: 1. precedence: in order listed (highest lowest) closure, concatenation, union 2. associativity: closure right-associative; concatenation/union left-associative 3. must back upwards grouping parens
my question: grammar (above) meet guidelines? sense i'm not 100% , hoping few seasoned eyes point out issues/errors.
tia noob
<start> <expr> <expr><expr> <expr><expr><expr> <term><term><term> 'abc'
this ambiguous, because in 3rd step can either expand first <expr> or latter one. should able work around removing
<expr> -> <expr> { <expr> } and create
<term> -> <term> <expr> instead.
you repeating here
<term> -> '(' <expr> ')' | <char> // grouping | <char> (you have <char> 2 times, did mean have '(' <expr> ')' '|' <char> in first rule?) think clearer remove
<term> -> '(' <expr> ')' and create
<expr> -> '(' <expr> ')' instead.
then need add together quotation marks around characters in <char>.
this see looking through ebnf, it's been while since studying myself of corrections might wrong.
regex recursive-descent
Comments
Post a Comment