Questions tagged [alex]

A lexical analyser generator for Haskell

Alex is a tool for generating lexical analysers in Haskell, given a description of the tokens to be recognised in the form of regular expressions. It is similar to the tool lex or flex for C/C++. Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing.

Note: Alex is part of the Haskell Platform, thus when you install the platform you will automatically have a working Alex. The Haskell Platform is a single, standard Haskell development environment for everyone. It offers a set of blessed libraries and tools, to save you the task of picking and choosing which core Haskell libraries to use.

61 questions
4
votes
3 answers

Regular expressions versus lexical analyzers in Haskell

I'm getting started with Haskell and I'm trying to use the Alex tool to create regular expressions and I'm a little bit lost; my first inconvenience was the compile part. How I have to do to compile a file with Alex?. Then, I think that I have to…
Anny
  • 71
  • 2
4
votes
0 answers

Haskell Alex: basic-bytestring lexer leaks memory

I am trying to write a simple lexer that will print all words in its input, where a word is a maximal sequence of letters a-zA-Z. All other characters must be ignored. My Alex program for this which uses the basic-bytestring wrapper uses as much…
Jyotirmoy Bhattacharya
  • 9,317
  • 3
  • 29
  • 38
4
votes
1 answer

Haskell parsing - Parsec with Alex

How can I use Alex as the lexer, then feed the tokens into Parsec for parsing? Are there any examples? I think Alex is better (and easier?) to use for lexical analysis than Parsec, but Parsec seems easier than Happy for parsing. They would probably…
ruben2020
  • 1,549
  • 14
  • 24
3
votes
1 answer

Can't match single character in Alex grammar

I finally got back to fleshing out a GitCommit message mode that I want to add to YI but I seem to missing something basic. I can't seem to match a single character in a grammar, all my rules only work if they match the entire line. I know this…
asm
  • 8,758
  • 3
  • 27
  • 48
3
votes
1 answer

Cabal tries to build unknown package when building with alex, happy in nix-shell

I'm currently trying to build a Haskell project using nix-shell and cabal, with alex and happy as build tools. Building inside nix-shell (with and without --pure), I get the following strange error message: cabal: Could not resolve…
CH.
  • 556
  • 1
  • 5
  • 16
3
votes
1 answer

Alex right_ctx end-of-line ($) chokes on end of file

In Alex I have a rule that looks like this ^@ident\:$ {TLabel (init s)} So, a single line that starts with an identifier followed by a colon and then the end of the line. This works fine unless the line is the last in the file and there is not a…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
2
votes
1 answer

Why is this lexer not parsing this input?

I want to lex the following code example: prop levelBasedAlerter uni { a b } \I -> levelBasedAlerter a | a > I -> b: "ALERT: %a" this should…
Fabian Schneider
  • 799
  • 1
  • 13
  • 40
2
votes
1 answer

Alex lex.x compilation : Not in scope 'begin'

I have the below statements in Lex.x to parse block comments. <0> "//".* { tokWValue LTokComment } <0> "/*" { begin blockcomment } "*/" { begin 0 …
dfordivam
  • 169
  • 1
  • 6
2
votes
2 answers

How to match newlines with Alex/Haskell

I borrowed the example presented here http://www.haskell.org/alex/doc/html/introduction.html I am trying to make an interpreter for numerical expressions. (literals only, no variables) And I want to have newlines separate two different expressions.…
Rohit Garg
  • 21
  • 1
2
votes
1 answer

What causes Happy to throw a parse error?

I've written a lexer in Alex and I'm trying to hook it up to a parser written in Happy. I'll try my best to summarize my problem without pasting huge chunks of code. I know from my unit tests of my lexer that the string "\x7" is lexed…
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
2
votes
1 answer

What do I need to add to use monadUserState with alex when parsing?

I am trying to write a program that will understand a language where embedded comments are allowed. Such as: /* Here's a comment /* This comment is further embedded */ second comment is closed Must close first comment */ This should be…
Aserian
  • 1,047
  • 1
  • 15
  • 31
2
votes
1 answer

How to parse C-style comments with Alex lexer?

NB. I'm using this Alex template from Simon Marlow. I'd like to create lexer for C-style comments. My current approach creates separate tokens for starting comments, ending, middle and oneline %wrapper "monad" tokens :- <0> $white+ ; <0> "/*" …
danbst
  • 3,363
  • 18
  • 38
2
votes
1 answer

How to Lex, Parse, and Serialize-to-XML Email Messages using Alex and Happy

I am working toward being able to input any email message and output an equivalent XML encoding. I am starting small, with one of the email headers -- the "From Header" Here is an example of a From Header: From: John Doe I want it…
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
2
votes
1 answer

Haskell Alex - regex matches wrong string?

I'm trying to write lexer for an indentation-based grammar and I'm having trouble matching the indentation. Here's my code: { module Lexer ( main ) where import System.IO.Unsafe } %wrapper "monadUserState" $whitespace = [\ \t\b] $digit =…
sinan
  • 6,809
  • 6
  • 38
  • 67
2
votes
1 answer

How to compile BNF Converter?

Did anyone succeed in building BNFC with ghc-7.2.1 and alex-3? I was trying to fix it manually, but there are lots of errors. Does anybody know where can I find some patches that will help me to get it done? Thanks in advance.
k_wisniewski
  • 2,439
  • 3
  • 24
  • 31