help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

%left solved


From: Sasan Forghani
Subject: %left solved
Date: Mon, 9 Aug 2010 17:24:54 -0400

 It seems that my code was somehow effecting how Bison was parsing. Or at
least this is the assumption I am left making. After deleting all the code
that had anything to do with the %left issue, the Bison parse is correct. Or
at least it is according to the printf statements. Using the printf
statements the trace of the shifts and reductions is below.


Input: a := b + c + d + e


key: id = identifier, r = ref_name, e = expr, s = stmt


shift

id reduce

r shift

r := shift

r := id reduce

r := r reduce

r := e shift

r := e + shift

r := e + id reduce

r := e + r reduce

r := e + e reduce

r := e shift

r := e + shift

r := e + id reduce

r := e + r reduce

r := e + e reduce

r := e shift

r := e + shift

r := e + id reduce

r := e + r reduce

r := e + e reduce

r := e reduce

s


the parse tree is:


e → e1 + e2

e1 → e3 + e4

e3 → e5 + e6

e5 → r

r → id

e6 → r

r → id

e4 → r

r → id

e2 → r

r → id


printf output:


const_decl -> Epsilon

ident_list -> IDENTIFIER

basic_type -> INTEGER

type -> basic_type

basic_var -> ident_list: type

ident_list -> IDENTIFIER

ident_list -> IDENTIFIER, ident_list

ident_list -> IDENTIFIER, ident_list

ident_list -> IDENTIFIER, ident_list

ident_list -> IDENTIFIER, ident_list

basic_type -> INTEGER

type -> basic_type

basic_var -> ident_list: type

var_list -> basic_var;

var_list -> basic_var; var_list

var_decl -> VAR var_list

proc_decl -> Epsilon

This is the value of $<blIdentifier>$ at ref_name begin: a

ref_name -> IDENTIFIER

This is the value of $<blIdentifier>$ at ref_name begin: b

ref_name -> IDENTIFIER

expr -> ref_name

This is the value of $<blIdentifier>$ at ref_name begin: c

ref_name -> IDENTIFIER

expr -> ref_name

expr -> expr ADDOP expr

This is the value of $<blIdentifier>$ at ref_name begin: d

ref_name -> IDENTIFIER

expr -> ref_name

expr -> expr ADDOP expr

This is the value of $<blIdentifier>$ at ref_name begin: e

ref_name -> IDENTIFIER

expr -> ref_name

expr -> expr ADDOP expr

stmt -> ref_name := expr

stmt_seq -> stmt;

comp_stmt -> BEGIN stmt_seq END

block -> const_decl var_decl proc_decl comp_stmt

prog -> PROGRAM IDENTIFIER; block .


reply via email to

[Prev in Thread] Current Thread [Next in Thread]