bison

Adding functions to bison/jison calculator language

喜欢而已 提交于 2019-12-10 21:18:24
问题 I'm trying to expand the Jison calculator example with some simple functions. I'm rather new to parsing and bison/jison, but this is a bit of what I have so far: /* lexical grammar */ %lex %{ var funcs = { pow: function(a, b) { return Math.pow(a, b); }, test: function(a) { return a*2; } } %} %% \s+ /* skip whitespace */ [0-9]+("."[0-9]+)?\b return 'NUMBER' [a-zA-Z]+ return 'NAME' "," return ',' "*" return '*' "(" return '(' ")" return ')' <<EOF>> return 'EOF' . return 'INVALID' /lex %start

Flex/Bison EOF propagation from stdin vs a file

痞子三分冷 提交于 2019-12-10 19:28:13
问题 I have a scanner, parser and a main from which I create an executable via bison -d parser.y; flex scanner.l; gcc main.c parer.tab.c lex.yy.c When I run ./a.out it does what I want: If Ctrl+D is pressed an EOF is detected and main can act accordingly. This means: if yyin is stdin then hitting Return ends the parsing of that line and the main loop waits for the next input line. Pressing Ctrl+D ends parsing input with a break in the main loop and exits. If the input comes from a file, e,g,

Bison+Flex segfault no backtrace

最后都变了- 提交于 2019-12-10 12:35:20
问题 I'm trying to debug code generated by Bison + Flex (what a joy!). It segfaults so badly that there isn't even stack information available to gdb . Is there any way to make this combination generate code that's more debuggable? Note that I'm trying to compile a reentrant lexer and parser (which is in itself a huge pain). Below is the program that tries to use the yyparse : int main(int argc, char** argv) { int res; if (argc == 2) { yyscan_t yyscanner; res = yylex_init(&yyscanner); if (res != 0

Simple Java grammar using Flex & Bison

十年热恋 提交于 2019-12-10 11:56:06
问题 I recently started learning basic Flex and Bison because I have to make a parser for simple (but not too simple) grammar. I decided to make a simplified Java language in my grammar. I made the .l and the .y files and everything compiles without error (I'm using gcc to compile). The problem is that every time I run the generated program I get Syntax Error , even with a simple input like: private class Something{} . The only time I do not get a Syntax Error is when I enter an empty line ( \n ).

ANTLR grammar from bison

可紊 提交于 2019-12-10 10:54:27
问题 I'm trying to translate a grammar from bison to ANTLR. The grammar itself is pretty simple in bison but I cannot find a simple way for doing this. Grammar in bison: expr = expr or expr | expr and expr | (expr) Any hints/links/pointers are welcome. Thanks, Iulian 回答1: In ANTLR, you cannot create left recursive rules: a : a b ; tail recursion is fine: a : b a ; For more information on left recursive rules, see ANTLR's Wiki. So, your example could look like: parse : expr+ EOF ; expr : orExpr ;

How to fix a missing ld library for -lfl while compiling?

你离开我真会死。 提交于 2019-12-10 02:51:57
问题 I am trying to translate my .spl file into a C file (because there is no compiler). I have an example "Hello World" .spl file, and I have downloaded the Shakespeare Programming Language .tar and extracted it, but I have no idea what to do next. I can't seem to find instructions in any documentation. Can anyone help? Edit: When I type make -f "Makefile" , I get the following output: bison --verbose -d grammar.y gcc -O2 -Wall -c grammar.tab.c gcc -O2 -Wall -c makescanner.c gcc makescanner.o -O2

“make: yacc: Command not found” after installing Bison

我是研究僧i 提交于 2019-12-09 14:43:47
问题 While running a makefile in gcc 4.1.2 (linux 5), I got the following error make: yacc: Command not found By googling, I came to know that this error can be rectified by installing Bison-GNU parser generator. But even after installing Bison, I get the same error. How can this error be solved? 回答1: From the looks of things, your makefile is expecting a yacc executable to be available and either it's not, or it's not on your path. Since bison is supposed to be compatible with yacc so the first

centos 7 安装 php7 & php-fpm

99封情书 提交于 2019-12-09 11:29:07
1.下载源代码 2. 添加 epel 源 3.安装依赖 yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel gmp-devel libjpeg-devel libpng-devel 4.创建用户 # groupadd www # useradd -g www -s /sbin/nologin -M www 5.编译安装 收集的比较全的编译选项: ./configure \ --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-opcache \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ -

How to fix YACC shift/reduce conflicts from post-increment operator?

霸气de小男生 提交于 2019-12-08 20:16:00
问题 I'm writing a grammar in YACC (actually Bison), and I'm having a shift/reduce problem. It results from including the postfix increment and decrement operators. Here is a trimmed down version of the grammar: %token NUMBER ID INC DEC %left '+' '-' %left '*' '/' %right PREINC %left POSTINC %% expr: NUMBER | ID | expr '+' expr | expr '-' expr | expr '*' expr | expr '/' expr | INC expr %prec PREINC | DEC expr %prec PREINC | expr INC %prec POSTINC | expr DEC %prec POSTINC | '(' expr ')' ; %% Bison

Using bison to parse list of elements

我只是一个虾纸丫 提交于 2019-12-08 13:25:03
问题 I'm writing a compiler for a shading engine and every worked fine until I reached the statements parsing part. I used an abstract syntax tree defined with classes to do all the work (to simplify typechecking and intermediate code generation).. so I have an ancestor class ASTNode and all descending classes like ASTFloat , ASTExpression , ASTIdentifier and so on.. In .y file I'm able to build up the AST in the common way: nexp: T_LPAR nexp T_RPAR { $$ = $2; } | nexp OP_PLUS nexp { $$ = new