Questions tagged [happy]

Happy is a YACC-like parse generator for Haskell

Happy is a like parse generator for the programming language.

106 questions
27
votes
5 answers

What is the advantage of using a parser generator like happy as opposed to using parser combinators?

To learn how to write and parse a context-free grammar I want to choose a tool. For Haskell, there are two big options: Happy, which generates a parser from a grammar description and *Parsec, which allows you to directly code a parser in…
fuz
  • 76,641
  • 24
  • 165
  • 316
20
votes
1 answer

Managing position information with Alex and Happy

I'm learning to use Alex and Happy to write a small compiler. I want to maintain line and column information for my AST nodes so that I can provide meaningful error messages to the user. To illustrate how I plan to do it, I wrote a small example…
gnuvince
  • 2,109
  • 17
  • 26
19
votes
1 answer

cabal-install does not retain the version for happy

I've trying to do cabal install hoogle but there is a hickup with the haskell-src-exts-1.13.5 dependency: Configuring haskell-src-exts-1.13.5... setup: The program happy version >=1.17 is required but it could not be found. When I try to do cabal…
Alexander Kondratskiy
  • 4,062
  • 1
  • 27
  • 41
16
votes
1 answer

How can I make Stack call Happy, Alex and other build tools?

As part of my compiler, I need alex and happy to run as part of my build process. How does Stack support this scenario? Bonus: how can I register alex and happy as compile-time dependencies?
Carl Patenaude Poulin
  • 4,468
  • 4
  • 17
  • 36
16
votes
1 answer

Parsec or happy (with alex) or uu-parsinglib

I am going to write a parser of verilog (or vhdl) language and will do a lot of manipulations (sort of transformations) of the parsed data. I intend to parse really big files (full Verilog designs, as big as 10K lines) and I will ultimately support…
Dilawar
  • 4,808
  • 9
  • 37
  • 54
13
votes
2 answers

Using alex/happy with Cabal

I'm writing a compiler for a class I'm taking. The class isn't specifically Haskell but I'm using Haskell to write my compiler and interpreter. I have a cabal package setup to hopefully make it easy for my prof to run/compile. I have happy and alex…
Edward
  • 1,696
  • 1
  • 14
  • 32
12
votes
4 answers

Are there any tutorials on building a simple interpreter using Alex + Happy?

I'm working on a school project where I have to build an interpreter for a simple language using Alex + Happy in Haskell. After looking through the documentation I understand most of it, but would like to see a full blown example on using the tools.
Carlos G.
  • 4,313
  • 2
  • 34
  • 57
12
votes
1 answer

How to use an Alex monadic lexer with Happy?

I'm trying to learn using Alex + Happy to build parser, in particular I'm interested in learning to use the monad wrapper of Alex. I have already looked at the documentation of Alex and Happy but I they are both, for me, really lacking any useful…
Bakuriu
  • 85,459
  • 18
  • 168
  • 202
11
votes
1 answer

Overriding "Internal Happy Error" - notHappyAtAll

I am using Happy to generate a parser. I have found that when I give it tokens which match part of the grammar at a lower level than the top level (such as giving it an expression on it's own, that isn't part of a statement), I get an "Internal…
Jack
  • 1,835
  • 5
  • 24
  • 41
10
votes
1 answer

How do Happy and Alex bootstrap themselves into being?

The source tree for happy contains AttrGrammarParser.ly and Parser.ly and the source tree for alex contains Scan.x. Yet, as far as I can tell in order to compile happy, we need to transform the .ly files into .lhs files using... happy, and in order…
rampion
  • 82,104
  • 41
  • 185
  • 301
8
votes
0 answers

Happy: Order of Productions Removes R/R Conflicts

I have a grammar that, depending on the order of productions, happy reports 3 reduce/reduce conflicts or none. The minimal example I can find is: %tokentype {Token} %token int { Int } '-' { Neg } both { Both } %nonassoc…
sfogarty
  • 81
  • 1
8
votes
1 answer

Suppress certain Haskell Alex/Happy compilation messages

When creating either a Lexer.x or a Parser.y parser using the Alex lexer generator or the Happy parser generator, compiling those into Haskell files, and compiling those into object files, by default this will generate the following "warnings": $…
Simon Shine
  • 14,573
  • 1
  • 40
  • 60
8
votes
5 answers

JS: regex for numbers and spaces?

I'm using happyJS and use the regex underneath for phone validation phone: function (val) { return /^(?:[0-9]+$)/.test(val); } However this ONLY allows numbers. I want the user to be able to enter spaces as well like 238 238 45383 Any…
matt
  • 37,699
  • 99
  • 250
  • 390
6
votes
1 answer

Happy Context-Dependent Operator Precedence

I have two snippets of Happy code here, one that uses normal precedence rules, and one that uses context-dependent precedence rules (both of which are described here). Normal: %left '+' %left '*' %% Exp :: { Exp } : Exp '+' Exp { Plus $1 $3 } …
5
votes
1 answer

What's the %% for in Happy?

I'm building a parser with Happy and noticed this is the online documentation: Like yacc, we include %% here, for no real reason. %% There must be a reason though, even if it's trivial. Does anyone know what it is?
Nick Brunt
  • 8,361
  • 6
  • 48
  • 80
1
2 3 4 5 6 7 8