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…
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…
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…
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?
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…
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…
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.
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…
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…
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…
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…
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":
$…
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…
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 }
…
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?