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
23
votes
4 answers

How to find shift/reduce conflict in this yacc file?

When I try to use yacc on the following file I get the error conflicts: 1 shift/reduce How can I find and fix the conflict? /* C-Minus BNF Grammar */ %token ELSE %token IF %token INT %token RETURN %token VOID %token WHILE %token ID %token…
neuromancer
  • 53,769
  • 78
  • 166
  • 223
22
votes
13 answers

How much time would it take to write a C++ compiler using flex/yacc?

How much time would it take to write a C++ compiler using lex/yacc? Where can I get started with it?
Madhu
  • 1,176
  • 1
  • 13
  • 18
21
votes
7 answers

Lisp grammar in yacc

I am trying to build a Lisp grammar. Easy, right? Apparently not. I present these inputs and receive errors... ( 1 1) 23 23 23 ui ui This is the grammar... %% sexpr: atom {printf("matched sexpr\n");} | list ; list: '('…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
21
votes
5 answers

Good parser generator (think lex/yacc or antlr) for .NET? Build time only?

Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL…
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
20
votes
8 answers

Is Yacc still used in the industry?

The software base I am developing for uses a signficant amount of yacc which I don't need to deal with. Some times I think it would be helpful in understanding some problems I find but most of the time I can get away with my complete ignorance of…
hhafez
  • 38,949
  • 39
  • 113
  • 143
20
votes
3 answers

Include struct in the %union def with Bison/Yacc

I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node *…
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
19
votes
2 answers

LALR vs LL parser

I've been using lex/yacc and now I'm trying to switch to ANTLR. The major concern is that ANTLR is an LL(*) parser unlike yacc which is LALR. I'm used to thinking bottom-up and I don't exactly know what the advantage of LL grammars is. People say…
K J
  • 4,505
  • 6
  • 27
  • 45
18
votes
1 answer

"Unknown type name" using YACC with xcode

I'm trying to use YACC with xcode, which is natively supported, and for that effect I found this sample which is working nicely. My idea is to build my own grammar, so I started experimenting with the project to see if it would support what I need.…
18
votes
2 answers

What's the difference between a parser and a scanner?

I already made a scanner, now I'm supposed to make a parser. What's the difference?
neuromancer
  • 53,769
  • 78
  • 166
  • 223
18
votes
5 answers

what is the difference between lex and yacc

I have worked with lex for executing some code whenever some regular expression is found, Can Yacc do something more than that? If yes, then what?
Manik Mahajan
17
votes
1 answer

Lex/Flex - Scanning for the EOF character

Other people have had the following problem that I am having but I can't find anyone that has reported a solution.. getting Flex to spot the EOF (end of file). I need Flex to find EOF and return a token indicating that it has found it so it can…
ale
  • 11,636
  • 27
  • 92
  • 149
17
votes
2 answers

Reasons for using lex/yacc alternatives?

About once a year I have to develop or at least design a grammar and a parser - that appears a constant of my working life. Every time I'm facing this task, thus about once year, I, quite a lex/yacc (flex/bison resp.) guy, consider, or reconsider,…
Solkar
  • 1,228
  • 12
  • 22
16
votes
3 answers

Making YACC output an AST (token tree)

Is it possible to make YACC (or I'm my case MPPG) output an Abstract Syntax Tree (AST). All the stuff I'm reading suggests its simple to make YACC do this, but I'm struggling to see how you know when to move up a node in the tree as your building…
Sprotty
  • 5,676
  • 3
  • 33
  • 52
16
votes
2 answers

%left and %right in yacc

{% #include #include %} %token ID NUM IF THEN LE GE EQ NE OR AND ELSE %right '=' %left AND OR %left '<' '>' LE GE EQ NE %left '+''-' %left '*''/' %right UMINUS %left '!' %% The code mentioned above is part of the yacc for a…
Arjun K P
  • 2,081
  • 4
  • 20
  • 33
15
votes
7 answers

C grammar in GCC source code

I'm looking for the C grammar in GCC source code, more specifically for the grammar in the yacc/bison form.
Haruki
  • 674
  • 1
  • 9
  • 24