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
19
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,357
  • 20
  • 27
15
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,786
  • 1
  • 15
  • 33
13
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
  • 98,325
  • 22
  • 197
  • 231
12
votes
2 answers

Is there an haskell EDSL for writing lexers?

Mixing the lexer and parsing phases in one phase sometimes makes Parsec parsers less readable but also slows them down. One solution is to use Alex as a tokenizer and then Parsec as a parser of the token stream. This is fine but it would be even…
Paul Brauner
  • 1,307
  • 1
  • 10
  • 17
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
  • 87,131
  • 49
  • 199
  • 315
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": $…
sshine
  • 15,635
  • 1
  • 41
  • 66
7
votes
1 answer

Are there any off-the-shelf solutions for lexical analysis in Haskell that allow for a run-time dynamic lexicon?

I'm working on a small Haskell project that needs to be able to lex a very small subset of strictly formed English in to tokens for semantic parsing. It's a very naïve natural language interface to a system with many different end effectors than…
Doug Stephen
  • 7,181
  • 1
  • 38
  • 46
6
votes
2 answers

Using Alex in Haskell to make a lexer that parses Dice Rolls

I'm making a parser for a DSL in Haskell using Alex + Happy. My DSL uses dice rolls as part of the possible expressions. Sometimes I have an expression that I want to parse that looks like: [some code...] 3D6 [... rest of the code] Which should…
Zeb
  • 73
  • 3
6
votes
1 answer

RegEx match for paragraphs

I can not figure out the correct RegEx to use for parsing a text file and identifying paragraphs. What I currently have: [\n\n]+ Sample Text: Das Pensionat Klinger war bereits etwas zusammengeschmolzen, als das junge Ehepaar daselbst…
mjosh
  • 61
  • 3
6
votes
1 answer

Haskell/Alex: Warning: Tab character

I'm writing a toy language in haskell. I'm using Alex to generate a scanner. Every time I build my project with cabal, I get the following warnings: dist/build/optimiser/optimiser-tmp/Lexer.hs:465:1: Warning: Tab…
AlexJ136
  • 1,272
  • 1
  • 12
  • 21
6
votes
1 answer

How to pass command-line options to Alex in Cabal

In my current project I have a file Tokens.x that needs to be compiled to Tokens.hs by Alex. In my .cabal file I have listed Tokens in the other-modules section and cabal build happily creates the file. However it does so without the -g option that…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
6
votes
1 answer

Haskell Alex - error in wrapper template

I'm trying to understand Alex and lexers in general but I'm having trouble to run my lexer. I wrote lexers in "basic" and "posn" wrappers but I couldn't in "monad" wrapper. I think I have to use monad wrapper because I need to collect strings and…
sinan
  • 6,809
  • 6
  • 38
  • 67
4
votes
2 answers

How to trigger an ALEXA notification programmatically?

I searched extensively but cannot find any example code that would allow me to understand how to trigger the Alexa notification that makes the orange light come up? I believe it has to do with the SetDirective (function?) ... I just don't get…
DirkLX
  • 1,317
  • 1
  • 10
  • 16
4
votes
1 answer

Getting line number information in the Semantic Analysis Phase (using Alex,Happy)

I am doing semantic analysis for an experimental language. I am using Alex and Happy to generate the lexer and the parser (actually I am using BNFC tool to generate Alex and Happy files). I wanted to get an error message with the line number and the…
user5803465
  • 343
  • 2
  • 7
4
votes
2 answers

How do we keep multiple semantic values during parsing with Happy/Haskell

I'm trying to build a simple lexer/parser with Alex/Happy in Haskell, and I would like to keep some localisation information from the text file into my final AST. I managed to build a lexer using Alex that build a list of Tokens with…
Vinz
  • 5,997
  • 1
  • 31
  • 52
1
2 3 4 5