[erlang-questions] Question of yecc

Solomon <>
Thu Nov 15 08:10:49 CET 2012


I want to write a parser to parse the string like this:
  a.id = b.id
  a.id = 10

My yrl file like this:
*Nonterminals
    val expr alias field.

Terminals
    '=' '>' '>=' '<=' '<' '!=' '.' 'atom'
    'num'.

Rootsymbol
    expr.

expr->val '=' val:['$1', '$3', {'opt', '='}].
expr->val '>' val:['$1', '$3', {'opt', '>'}].
expr->val '>=' val:['$1', '$3', {'opt', '>='}].
expr->val '<' val:['$1', '$3', {'opt', '<'}].
expr->val '<=' val:['$1', '$3', {'opt', '<='}].
expr->val '!=' val:['$1', '$3', {'opt', '!='}].

val->alias '.' field:{'$1', '$3'}.
val->num:{'num', '$1'}.

alias->atom:{'alias', '$1'}.
field->atom:{'field', '$1'}.*

it is ok for "a.id=b.id":
*{ok,[{{alias,{atom,1,a}},{field,{atom,1,id}}},
     {{alias,{atom,1,b}},{field,{atom,1,id}}},
     {opt,'='}]}*

and it is ok for "a.id=b":*
{ok,[{{alias,{atom,1,a}},{field,{atom,1,id}}},
     {num,{atom,1,a}},
     {opt,'='}]}*

but it error for "a.id=12":
*{error,{1,my_parser,["syntax error before: ","12"]}}*

what is wrong with my yrl file?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121115/1cbe2d62/attachment.html>


More information about the erlang-questions mailing list