Questions tagged [yacc]

The computer program yacc is a parser generator developed by Stephen C. Johnson at AT&T for the Unix operating system.

The name is an acronym for "Yet Another Compiler Compiler." It generates a parser (the part of a compiler that tries to make syntactic sense of the source code) based on an analytic grammar written in a notation similar to BNF. Historically, Yacc has generated the code for the parser in the C programming language.

Yacc used to be available as the default parser generator on most Unix systems. It has since been supplanted as the default by more recent, largely compatible, programs such as Berkeley Yacc, GNU bison, MKS yacc and Abraxas pcyacc. An updated version of the original AT&T version is included as part of Sun's OpenSolaris project. Each offers slight improvements and additional features over the original yacc, but the concept has remained the same. Yacc has also been rewritten for other languages, including Ratfor, ML, Ada, Pascal, Java, Python and Common Lisp.

The parser generated by yacc requires a lexical analyzer. Lexical analyzer generators, such as Lex or Flex are widely available. The IEEE POSIX P1003.2 standard defines the functionality and requirements for both Lex and Yacc.

Some versions of AT&T Yacc have become open source. For example, source code (for different implementations) is available with the standard distributions of Plan 9 and OpenSolaris.

http://en.wikipedia.org/wiki/Yacc

Books

See also:

1902 questions
8
votes
3 answers

Compiling and executing the Shakespeare Programming Language translator spl2c on Mac OS X 10.6 results in warnings/errors

I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make. The compilation of spl2c executes with a couple warnings: scanner.l:600: warning, rule cannot be…
Redwood
  • 66,744
  • 41
  • 126
  • 187
8
votes
2 answers

$1 of [...] has no declared type

I am unfamiliar with Yacc and trying to get an example I found here to work. When I try to compile with yacc -d calc.yacc, I get the following errors. calc.yacc:42.17-18: $1 of `stat' has no declared type calc.yacc:96.22-23: $1 of `expr' has no…
emilytrabert
  • 137
  • 1
  • 1
  • 7
8
votes
6 answers

M4 "No such file or directory".Bison

This is my code in file skener.y %{ #include %} %token T_Int %% exp: T_Int { $$ = $1; } | exp exp '+' { $$ = $1 + $2; } | exp exp '-' { $$ = $1 - $2; } | exp exp '*' { $$ = $1 * $2; } | exp exp…
Bodo Hombah
  • 209
  • 1
  • 3
  • 9
7
votes
2 answers

Bison java examples

Does anyone knows if there are some tutorials and/or examples of using GNU Bison with Java over the net. I've searched through the net. But i didn't manage to find anything. I have tried to implement an example but I could not compile it (since I…
TheHube
  • 752
  • 1
  • 10
  • 23
7
votes
5 answers

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

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 '+'…
Zifre
  • 26,504
  • 11
  • 85
  • 105
7
votes
1 answer

Using Yacc and Lex in Xcode

I have read that Xcode 4 (and I suppose previous versions) have built in support for Yacc and Lex which I am just learning about. I'm trying to set up a simple project to test them out but as I'm new to Xcode and Yacc/Lex I can't seem to figure out…
JPC
  • 8,096
  • 22
  • 77
  • 110
7
votes
1 answer

How can I manage mutual recursion, retaining associativity rules?

The overall question is: How does my grammar have to look like to allow for arbitrarily nested expr := '(' expr ')' => expr | expr_without_short_closure and expr_without_short_closure := [expr_without_short_closure => expr] | yield…
bwoebi
  • 23,637
  • 5
  • 58
  • 79
7
votes
5 answers

Is there a good yacc/bison type LALR parser generator for .NET?

Is there a good yacc/bison type LALR parser generator for .NET ?
Phil Bennett
  • 4,809
  • 4
  • 30
  • 28
7
votes
1 answer

y.tab.c: undefined reference to yylex

I am trying to run an example I found online of a calculator. But I have this error showing every time I run my gcc command. Here are the commands that I run: flex -l calc3.l yacc -vd calc3.y gcc y.tab.c -lm -ll -> at this point I got this error…
user4506618
  • 103
  • 1
  • 1
  • 3
7
votes
7 answers

Creating a small programming language for beginners

I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with…
7
votes
5 answers

Multiple flex/bison parsers

What is the best way to handle multiple Flex/Bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from…
Jack
  • 131,802
  • 30
  • 241
  • 343
6
votes
2 answers

How do I implement forward references in a compiler?

I'm creating a compiler with Lex and YACC (actually Flex and Bison). The language allows unlimited forward references to any symbol (like C#). The problem is that it's impossible to parse the language without knowing what an identifier is. The only…
Zifre
  • 26,504
  • 11
  • 85
  • 105
6
votes
2 answers

SQL lex yacc grammar

All, Developing a validating application for embedded sql i'll use ansi c or c++ as developement language Where do i get an sql grammar for lex and yacc?
user1119406
6
votes
2 answers

Is there any example of language grammar that possible for Yacc to express but impossible for Antlr4?

I try to learn about language parser recently and always seen the review about difference in Yacc and Antlr (about LALR and LL). It was always some concluded wording like "LALR is more powerful". But I can't understand what its really means So could…
Thaina Yu
  • 1,372
  • 2
  • 16
  • 27
6
votes
3 answers

What does $$ = $1 + $3 mean in yacc?

Lex part : %% [0-9]+ { yyval = atoi (yytext); return num; } %% Yacc part : %token num %% exp:num '+' num ; {$$ = $1 + $3;} %% In this part of the code what do $$, $1 and $2 stand for? How can I print $$ now? And if I send 5+9 as input to this…
πTh0n
  • 75
  • 1
  • 1
  • 6