blynn / nex

Lexer for Go
http://cs.stanford.edu/~blynn/nex/
GNU General Public License v3.0
416 stars 47 forks source link

ternary operators throw unexpected error #29

Closed drewwells closed 8 years ago

drewwells commented 8 years ago

Given the nex file:

%{
package main

%}

%union {
    n int
}

%token NUMBER
%token ADD SUB MUL DIV ABS
%token EOL

%%

start:           term
        ;
term:           NUMBER
        |       ABS term { $$ = $2 >= 0? $2 : - $2; }
        ;
%%

Got:

# command-line-arguments
desk.y:33[/Users/drew/src/snazzle/desk/y.go:468]: syntax error: unexpected ?

Expected: $2 is returned as positive number

drewwells commented 8 years ago

c code won't work for go