Burbas
Burbas

Reputation: 803

Problem with yecc grammar

I'm currently writing a small parser in erlang, using yecc, and have encountered some problems. The problems occur when I'm parsing rules with 'lbrack' in it. The following rule is an illustration of my problem:

program -> 'char' 'ident' 'lbrack' 'int_constant' 'rbrack' 'semi'

It compiles ok, but when I'm trying to parse the following tokens:

[{char,1},
 {ident,1,1,t},
 {lbrack,1},
 {int_constant,1,10},
 {rbrack,1},
 {semi,1}]

the parser crashes with

{error,
 {1,parser,["syntax error before: ","lbrack"]}}}

Upvotes: 1

Views: 509

Answers (1)

rvirding
rvirding

Reputation: 20926

I tried with the following yecc file, yt.yrl:

Nonterminals
program.

Terminals
char ident lbrack int_constant rbrack semi.

Rootsymbol
program.

program -> 'char' 'ident' 'lbrack' 'int_constant' 'rbrack' 'semi'.

with your input and it worked fine. It didn't return anything, well '$undefined', but that is as it should be as my example doesn't return anything. Note that none of your terminal symbols need to be quoted as they are just normal atoms with "ordinary" names.

Upvotes: 3

Related Questions