[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Grammar Troubles: "juxtaposition" operator
From: |
Nick Johnson |
Subject: |
Grammar Troubles: "juxtaposition" operator |
Date: |
Mon, 16 Jun 2008 19:55:58 -0400 |
Hello,
I am trying to implement a grammar with an odd feature. This grammar
must allow for a "juxtaposition" operator--an implicit operator
between two expressions. When I remove the juxtaposition operator,
the language works exactly as I would expect. However, once I add the
juxtaposition operator, it exhibits unexpected behavior.
The grammar is listed below in its barest terms. Here, the last rule
having the lowest precedence:
expr -> 'a'
expr -> '(' expr ')'
expr -> '~' expr
expr -> expr '*'
expr -> expr expr // juxtaposition operator
expr -> expr '|' expr
I have observed at least two problems:
(1) The juxtaposition operator appears to be right-associative, though
it is declared left-associative; and
(2) The juxtaposition operator has a higher precedence than the '~'
operator, though the opposite is declared.
I do not think this is a Bison bug; rather, I think it is a bug in my
grammar. I think the absense of a terminal token in the juxtaposition
rule causes things to mess up. If anyone could help me out, I would
really appreciate it.
I have attached a minimal yacc file (minimal.y) which translates
simple expressions (such as testcase.in) into a graphical parse-tree
(using graphviz). To build and run this, perform:
$ bison minimal.y
$ gcc minimal.tab.c -o minimal
$ ./minimal <testcase.in | dot -Tjpg >testcase.jpg
I have also attached a sample output (testcase.jpg) to save you the
trouble. I am using Bison version 2.3, built from source, and gcc
version 3.4.4 on linux.
Thank you,
--
Nick Johnson
minimal.y
Description: Binary data
testcase.in
Description: Binary data
testcase.jpg
Description: JPEG image
- Grammar Troubles: "juxtaposition" operator,
Nick Johnson <=