alex

Haskell Alex - error in wrapper template

六月ゝ 毕业季﹏ 提交于 2019-12-04 06:42:13
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 token positions in input. I also need multiple states. For now I'm trying to run this simple exmaple: { module Main (main) where } %wrapper "monad" $whitespace = [\ \b\t\n\f\v\r] $digit = 0-9 $alpha = [a-zA-Z_] $upper = [A-Z] $lower = [a-z] @tidentifier = $upper($alpha|_|$digit)* @identifier = $lower($alpha|_|$digit)* tokens :- $whitespace+ ; $upper

Using alex/happy with Cabal

限于喜欢 提交于 2019-12-04 00:18:08
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 in the build-tools field for both executables but Cabal ignores that and then complains that it cannot find the modules that Happy and Alex should be generating. If I manually run: alex LimpScanner.x happy LimpParser.y then cabal runs perfectly. I thought I had cabal automatically running them earlier but perhaps I remember imperfectly. limp.cabal:

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

 ̄綄美尐妖づ 提交于 2019-12-03 04:30:39
问题 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. 回答1: Not on building interpreters, but on building lexers and parsers, yes. See the example for a lexical analyzer in Alex, here, combined with an intro to Happy here. I found the haskell.x and haskell.y files distributed in the darcs repos for

Day3

匿名 (未验证) 提交于 2019-12-02 23:52:01
1. For循环 for(关键字) i(变量)in(关键字) s(要迭代的对象) 冒号 for循环会把这个name指向的字符串里的每个元素打印出来。 for循环的数据结构: 字符串 列表 元祖 字典 集合 s = '今天天气很好' # s_len = len(s) # count = 0 # while count<s_len: # print(s[count]) # count += 1 for i in s : print ( i ) >>>今 天 天 气 很 好    2. 字符串方法   1. 大写首字母 s = 'alex' s1 = s . capitalize 's' print ( s1 ) >>> Alex    2. 全部大写或者全部小写 s = 'alex' s1 = s . upper ( s ) print ( s1 ) >>> ALEX s = 'aLEx' s2 = s . lower ( s ) print ( s2 ) >>> alex    3. 判断以什么为开头 s = 'alex' s1 = s . startwith ( a ) print ( s ) >>> True    4.判断以什么为结尾 s = 'alex' s1 = s . startwith ( x ) print ( s ) >>> True    5. 统计出现的次数 s

集合

余生颓废 提交于 2019-12-02 19:18:00
集合: 可变的数据类型,他里面的元素必须是不可变的数据类型,无序,不重复。 {} set = {1,2,3} #增 set1 = {'alex','wusir','ritian','egon','barry',} set1.add('啦啦啦') print(set1) set1.update('ABC') print(set1) #删除 #删除 set1 = {'alex','wusir','ritian','egon','barry',} set1.pop() #随机删除 有返回值 print(set1) set1.remove('alex') print(set1) #按元素去删 set1.clear() #清空集合print(set1)del set1 #删除集合print(set1) #查 #查 set1 = {'alex','wusir','ritian','egon','barry',} for i in set1: print(i) 来源: https://www.cnblogs.com/rxiaoxi/p/11756004.html

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

六眼飞鱼酱① 提交于 2019-12-02 18:30:51
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. Not on building interpreters, but on building lexers and parsers, yes. See the example for a lexical analyzer in Alex, here , combined with an intro to Happy here . I found the haskell.x and haskell.y files distributed in the darcs repos for Alex and Happy useful. You can find those here and here. I wrote a series of posts at bjbell.wordpress.com

Day7 - Python基础7 面向对象编程进阶

倖福魔咒の 提交于 2019-12-02 06:08:29
面向对象高级语法部分 经典类vs新式类 把下面代码用python2 和python3都执行一下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #_*_coding:utf-8_*_ class A: def __init__( self ): self .n = 'A' class B(A): # def __init__(self): # self.n = 'B' pass class C(A): def __init__( self ): self .n = 'C' class D(B,C): # def __init__(self): # self.n = 'D' pass obj = D() print (obj.n) classical vs new style: 经典类:深度优先 新式类:广度优先 super()用法 抽象接口 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import abc class Alert( object ): '''报警基类''' __metaclass__ = abc.ABCMeta @abc .abstractmethod def send( self ): '''报警消息发送接口''' pass class

编码,str

旧时模样 提交于 2019-12-01 16:25:56
一,编码    1. ascii. 最早的编码. 至今还在使用. 8位一个字节(字符) 2. GBK. 国标码. 16位2个字节. 3. unicode. 万国码. 32位4个字节 4. UTF-8. 可变长度的unicode. 英文: 8位. 1个字节 欧洲文字:16位. 2个字节 汉字. 24位. 3个字节 8bit = 1byte 1024byte = 1KB 1024KB = 1MB 1024MB = 1GB 1024GB = 1T 二,字符串(重点) 常见的基本数据类型: 1. int 整数 2. bool 布尔. 判断. if while 3. str 字符串, 一般放小量的数据. 4. list 列表. 可以存放大量的数据 5. dict 字典, 以key:value的形式存储数据 6. set 集合(数学) 7. tuple 元组 不可变 1. int 整数: 常见操作就那么几个 +-*/ // % ** bit_length() 一个数的二进制长度 2. bool(类型转换的问题) 没有操作 类型转换 字符串转换成整数 int(str) 结论1: 想要转化成什么类型就用这个类型括起来 结论2: True => 1 False => 0 结论3: 可以当做False来用的数据: 0 "" [] {} () None 3. 字符串 1. 字符: 单一文字符号 2.

day08

浪子不回头ぞ 提交于 2019-11-29 02:18:30
第一题 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中, 即: {'k1': 大于66的所有值, 'k2': 小于66的所有值} number_list = [11,22,33,44,55,66,77,88,99,90] K1_list = [] K2_list = [] number_dic= {'K1_list':K1_list,'K2_list':K2_list} for i in number_list: if i>66: K1_list.append(i) elif i<66: K2_list.append(i) else: continue print(number_dic) 第二题 统计s='hello alex alex say hello sb sb'中每个单词的个数,结果如:{'hello': 2, 'alex': 2, 'say': 1, 'sb': 2} 第一种解法 s = 'hello alex alex say hello sb sb' number_dic = {'hello': s.count('hello'), 'alex': s.count('alex'), 'say': s.count('say'), 'sb': s

How to use an Alex monadic lexer with Happy?

我的梦境 提交于 2019-11-28 09:16:04
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 information on using them together. I managed to make them work together with the basic and posn wrappers, but I'm at a loss with monad . I have already looked at different question on SO about Alex, Happy and monadic lexers (including: Are there any tutorials on building a simple interpreter using Alex + Happy? but none is able to provide a simple