[erlang-questions] Question of yecc

22 views
Skip to first unread message

Solomon

unread,
Nov 15, 2012, 2:10:49 AM11/15/12
to erlang-q...@erlang.org
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?

Álvaro

unread,
Nov 15, 2012, 11:35:27 AM11/15/12
to Solomon, erlang-q...@erlang.org
Hi,

I think the problem is that yecc does not recognize the terminal 'num'.
The default scanner recognizes 'integer' and 'float'.
Change your 'num' for 'integer' and try again.

Best,
Álvaro

2012/11/15 Solomon <solom...@gmail.com>
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


Solomon

unread,
Nov 15, 2012, 8:27:52 PM11/15/12
to Álvaro, erlang-q...@erlang.org
Thanks, you are right. Maybe I should try to write a xrl file to do the lexical analysis.


2012/11/16 Álvaro <avalorm...@gmail.com>
Reply all
Reply to author
Forward
0 new messages