I am trying to build a if()else if() else if() else example.Is there any way to fix this without %nonassoc and specify the terminal symbol? As you see at code i have some flex and bison.At flex there is not any keyword elseif but only else and if.
Flex
keyword_if [Ii][Ff]
keyword_else [Ee][Ll][Ss][ee]
keyword_start [Ss][Tt][Aa][Rr][Tt]
keyword_then [Tt][Hh][Ee][Nn]
{keyword_if} return key_if;
{keyword_else} return key_else;
{keyword_start} return key_start;
{keyword_then} return key_then;
Bison
%token key_if
%token key_else
%token key_start
%token key_then
%start:program;
program:start commands ;
commands:command
|commands command;
command:ifcommand
|whilecommand
|forcommand;
ifcommand:key_if exp key_then commands checkelse;
checkelse:/*empty*/
|key_else commands;
That works for the simple version that there are nested if inside else and not like this
if a == 10 then
/* some commands */
else if a == 20 then
/*some commands*/
else if a == 30 then
/*some commands*/
else
/*some commands*/