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
0
votes
1 answer

backward compatibility for yacc in Go 1.5 and 1.6

Lex should return the token identifier, and place other token information in lval (which replaces the usual yylval). The above text taken from the go document. I used the variable(yylval) in the action part of grammar rules in the yacc…
IhtkaS
  • 1,314
  • 3
  • 15
  • 31
0
votes
1 answer

Ignoring new line characters in PLY/Yacc Productions

I'm trying to implement a struct in my grammar (in PLY). The parser generates no syntax errors if I write my struct on one line but if I write it on multiple lines it produces syntax errors on the lines containing braces. My code follows (without…
Bennet Leff
  • 376
  • 1
  • 4
  • 18
0
votes
2 answers

Bison: Shift/Reduce Conflict resolution when dealing with optional rules

On the grammar of a .y (yacc -- bison) file I've defined the following rules: C : E | D | F | A A : B | B '[' C ']' ; (this is something like B with optional [C]) when I compile the .y file in the appropriate way using a proper lexer file I get…
ysig
  • 447
  • 4
  • 18
0
votes
1 answer

How to remove shift-reduce conflict in yacc grammar?

I have the following grammar: Expression : SimpleExpression {$$ = $1;}; | SimpleExpression LTnum SimpleExpression { MkLeftC($1, $2); $$ = MkRightC($3, $2); } | SimpleExpression LEnum SimpleExpression { MkLeftC($1, $2); $$…
ExeCode
  • 21
  • 1
  • 6
0
votes
2 answers

Solving a reduce/reduce conflict

If I have a grammar where a certain expression can match two productions, I will obviously have a reduce/reduce conflict with yacc. Specifically, say I have two productions (FirstProduction and SecondProduction) where both of them could be TOKEN…
David Gomes
  • 5,644
  • 16
  • 60
  • 103
0
votes
1 answer

ML-Yacc error concerning 12 shift/reduce conflicts involving EXP -> EXP BINOP EXP

This is the error: 12 shift/reduce conflicts error: state 34: shift/reduce conflict (shift OR, reduce by rule 11) error: state 34: shift/reduce conflict (shift AND, reduce by rule 11) error: state 34: shift/reduce conflict (shift GE, reduce…
Joe
  • 1,076
  • 3
  • 10
  • 17
0
votes
1 answer

LEX: code to read a specific grammar error

Very new to lex. This is for project for Prog. Langs. class Consider a language built over the following grammar: ::= | ::= | | | ::=…
WallofKron
  • 33
  • 8
0
votes
0 answers

how to decompile lex file

I'm really new to lex/yacc/bison and parsers in general. I created lex and yacc files (not sure if the programs themselves are relevant here), then compiled with the following commands in Terminal on my Mac: lex lexer.l yacc -d example.y …
0
votes
2 answers

3 Address Code Generation using lex and yacc

I'm trying to generate 3 address code corresponding to basic arithmetic expressions. I haven't worked with lex and yacc tools before much (Newbie) and I'm having trouble understanding the flow of control/command among the two i.e how the two…
Swagnik Dutta
  • 129
  • 1
  • 15
0
votes
1 answer

Issue linking Yacc file to Symbol Table

I am building a compiler and I have some issues linking my parser to my SymbolTable. I am trying to compile simple expressions like: a = 3 + 2; output(a); I am not getting 5 as an output, and I can't figure out what I am doing wrong. I put my codes…
zuludictator
  • 65
  • 1
  • 2
  • 7
0
votes
1 answer

Resolving yacc conflicts - rules useless in parser due to conflicts

I am working on a yacc file to parse a given file and convert it to an equivalent c++ file. I have created the following grammar based on the provided syntax diagrams: program: PROGRAMnumber id 'is' comp_stmt ; comp_stmt: …
neomang
  • 117
  • 3
  • 10
0
votes
1 answer

How to build a parser using lex/yacc for definition of variables in c

Hi I am new in lex/yacc and i am practicing to implement a parser for definition of a set of variables say int x,y,z; double a, b; char c. I need to assign a constant value to variables and also manage character constants as well as print all…
Kofi kay
  • 11
  • 1
  • 3
0
votes
1 answer

Compiling Yacc code

Below is my yacc code to parse C source code. I am a little new to this and this is an already existing code. { %{ #include #include #include "Expression.c" %} %token Identifier %token Number %token '=' '+' '-' '*' '/'…
Abhijeet Mohanty
  • 334
  • 1
  • 6
  • 21
0
votes
1 answer

How to create grammar for applying De Morgan's theorem to an expression using yacc?

I would like to apply Demorgan's theorem to an input using yacc and lex. The input could be any expression such as a+b, !(A+B) etc: The expression a+b should result in !a∙!b The expression !(a+b) should result in a+b I think the lex part is done…
s.zen
  • 11
  • 6
0
votes
1 answer

How to write YACC grammar that builds a tree of tokens etc?

I have read about YACC, and I have seen a few examples of simple toy programs. But I have never seen a practical example that demonstrates how to build a tree of tokens and so on, nor has it been easy to find an example using Google search. Can…
hap
  • 1
  • 3