Questions tagged [happy]

Happy is a YACC-like parse generator for Haskell

Happy is a like parse generator for the programming language.

108 questions
1
vote
1 answer

Haskell, No instance for (Show ([String, Int)] -> Int

Trying to compile Haskell.Happy example here: http://www.haskell.org/happy/doc/html/sec-using.html#sec-other-datatypes, after generating .hs file with happy, I'm getting the No instance for (Show ([String, Int)] -> Int error, trying to compile it,…
Herokiller
  • 2,891
  • 5
  • 32
  • 50
1
vote
1 answer

Alex, Happy, Cabal, and Re-preprocessing

I am using Alex 3.0.5, Happy 1.18.10, Cabal 1.16.0.2 I have a small compiler project that is built using Cabal. I am exposing the compiler's internals as a library, so I have in the exposed modules section, MyLangLex and MyLangPar. If I delete the…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
1
vote
1 answer

Haskell - Happy - "No instance ..." error

I'm trying to get familiar with Happy parser generator for Haskell. Currently, I have an example from the documentation but when I compile the program, I get an error. This is the code: { module Main where import Data.Char } %name calc %tokentype {…
John Smith
  • 1,276
  • 4
  • 17
  • 35
1
vote
1 answer

Reduce/Reduce conflict when introducing pointers in my grammar

I'm working on a small compiler in order to get a greater appreciation of the difficulties of creating one's own language. Right now I'm at the stage of adding pointer functionality to my grammar but I got a reduce/reduce conflict by doing it. Here…
Tarrasch
  • 10,199
  • 6
  • 41
  • 57
1
vote
2 answers

haskell happy - "Couldn't match expected type"

I have some problems to understand error messages of the parser generator system happy for haskell. For instance this code { module Test_parser where import System.IO import Test_lexer } %name parse %tokentype { Token } %error { parseError…
jimmyt
  • 491
  • 4
  • 10
0
votes
1 answer

LEETCODE 202 HAPPY NUMBER (PYTHON)

class Solution: def isHappy(self, n: int) -> bool: visit = set() def happy(n): temp = n n = 0 for i in str(temp): n += int(i)**2 if n == 1: return…
0
votes
1 answer

How can i get a false value if the inputted number isn't a happy one?

*hi there here is my answer for this challenge : Write an algorithm to determine if a number n is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares…
0
votes
1 answer

Parsing switch statements with Happy

So, I'm trying to parse code containg switch statements like this function (a : Boolean) equals (b : Boolean) : Boolean { switch (a) { case true: switch (b) { case true: …
Anthony
  • 410
  • 1
  • 4
  • 8
0
votes
1 answer

Optional prefix in LBNF/BNFC grammar without shift/reduce conflicts

I am trying to write a LBNF/BNFC grammar for a C-like language. In C there are many possible modifiers that you may or may not write in front of a declaration (like inline, const, volatile and so on). I am trying to write my grammar to reuse code…
Grisu47
  • 530
  • 5
  • 16
0
votes
1 answer

Happy/YACC reducing when it should shift

I'm working on a parser and I'm really frustrated. In the language, we can have an expression like: new int[3][][] or new int[3] Most of it parses correctly, except for the empty arrays at the end. In my parser I have: Expression : int …
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
0
votes
1 answer

Resolve conflict in bison grammar with space separated expression lists + if/then/else

I have the following yacc/bison/happy grammar: %token if TokenIf then TokenThen else TokenElse true TokenTrue false TokenFalse %left APP %right IF %% Hungry : NoHungry |…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
0
votes
0 answers

Cabal Build Producing Errors - Code Seems Fine Manually?

Throughout my development i've been manually running alex/happy to generate my parser files and then running ghci to test the code. This works fine and loads me into GHCI, but whenever I run cabal repl the program throws an error in my Parser.hs…
Sheldor
  • 11
  • 4
0
votes
0 answers

Does happy allow single-line comments?

Is there a way to comment everything to the end of the line, like -- in Haskell? The only comment syntax I could find was the {- commented stuff -} syntax.
sid-kap
  • 941
  • 1
  • 10
  • 17
0
votes
1 answer

Happy Parse Error

I'm currently using the alex and happy lexer/parser generators to implement a parser for the Ethereum Smart contract language solidity. Currently I'm using a reduced grammar in order to simplify the initial development. I'm running into an error…
Sheldor
  • 11
  • 4
0
votes
0 answers

Generating "expected" style error messages from Happy

As Happy generates a state machine and runs through it upon parsing, I presume when hitting a parse error it will be able to tell what tokens it was expecting. Is there anyway to get this information as part of printing the error? Currently I'm just…
Clinton
  • 22,361
  • 15
  • 67
  • 163