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
11
votes
2 answers

Are There Yacc Grammar Debuggers?

I've been helping augment a twenty-some year old proprietary language within my company. It is a large, Turing-complete language. Translating it to another grammar regime (such as Antlr) is not an option (I don't get to decide this). For the most…
Don Wakefield
  • 8,693
  • 3
  • 36
  • 54
11
votes
2 answers

Getting: warning, rule cannot be matched

I am working on building a lexical and syntax analyzer. I am getting the following warning when I try to use flex with my .l file. littleDuck.l:26: warning, rule cannot be matched Rule 26 is the one that starts with {cteI}, my rules section is the…
gabrielbaca
  • 123
  • 1
  • 2
  • 10
10
votes
2 answers

Simplest of parsers in go tool yacc

Using this command: go tool yacc -p Verb -o verb.go boilerplate.y Trying to build this yacc file: // boilerplate.y %{ package main import ( "bufio" "fmt" "os" "unicode" ) %} %% .|\n ECHO; %% func main() { fi :=…
Justin Thomas
  • 5,680
  • 3
  • 38
  • 63
10
votes
1 answer

How do i implement If statement in Flex/bison

I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return…
Imran
  • 157
  • 1
  • 2
  • 9
10
votes
1 answer

Multiple YACC grammars in one program

How do I compile, link and call different YACC grammars using yyparse() in one program?
Shaya
  • 141
  • 1
  • 6
10
votes
1 answer

extract BNF grammar rules from yacc file

I have a yacc file describing a certain language for which i am developing an Editor using IMP (eclipse project).I am using LPG as a parser generator, so I needed to extract a BNF rules from my yacc file. the yacc file i received contains rules and…
lferasu
  • 185
  • 2
  • 10
10
votes
6 answers

how to use yy_scan_string in lex

I want to parse a string which I give to the parser in the main function of yacc . I know that this could be done by using yy_scan_string but I don't know how to use it. I searched the web and the man pages but it is still not clear to me. Please…
ajai
  • 363
  • 3
  • 6
  • 14
10
votes
3 answers

How should I handle lexical errors in my Flex lexer?

I'm currently trying to write a small compiler using Flex+Bison but I'm kinda of lost in terms of what to do with error handlling, specially how to make everything fit together. To motivate the discussion consider the following lexer fragment I'm…
hugomg
  • 68,213
  • 24
  • 160
  • 246
10
votes
3 answers

How to use yylval with strings in yacc

I want to pass the actual string of a token. If I have a token called ID, then I want my yacc file to actually know what ID is called. I thing I have to pass a string using yylval to the yacc file from the flex file. How do I do that?
neuromancer
  • 53,769
  • 78
  • 166
  • 223
10
votes
1 answer

in lex how to make yyin point to a file with the main function in yacc?

I am storing the arguments passed to main in yacc in a file. Now I want the lex to read its input from this file rather than the terminal. I know I can point yyin to a file like yyin = fopen("fn","r"); but this works only when main is in lex. When…
ajai
  • 363
  • 3
  • 6
  • 14
10
votes
2 answers

Parsing optional semicolon at statement end

I was writing a parser to parse C-like grammars. First, it could now parse code like: a = 1; b = 2; Now I want to make the semicolon at the end of line optional. The original YACC rule was: stmt: expr ';' { ... } Where the new line is processed by…
shouya
  • 2,863
  • 1
  • 24
  • 45
9
votes
2 answers

yacc - field has incomplete type

yacc doesn't seem to like when my tokens are of a type that I defined. At the top of my grammar (.y) file in a %{ ... %} block, I include a header file that defines the following structure: typedef struct _spim_register { spim_register_type…
ArIck
  • 418
  • 3
  • 10
9
votes
4 answers

How to get the AST from YACC?

I know how to make YACC generate an AST, but how do you actaully get it? I mean, how do you actaully get the value of the root node from YACC?
mtk358
  • 565
  • 1
  • 7
  • 20
9
votes
1 answer

Fatal error: start symbol does not derive any sentence

Iam trying to develop a program for a calculator using lex and yacc. I keeping getting the following error: calc.y: warning: 5 nonterminals useless in grammar [-Wother] calc.y: warning: 8 rules useless in grammar [-Wother] calc.y:8.1: fatal error:…
Anoop saju
  • 480
  • 3
  • 17
9
votes
2 answers

Creating comments in Lex and Yacc

How does one make a comment in Lex and Yacc? So far I haven't tried Yacc, but in Lex I have tried /* comment */ and // comment, but neither of these compile. I am on a Mac, using the builtin Lex and Yacc compilers, (or maybe the X-Code ones, I don't…
jellies
  • 639
  • 1
  • 5
  • 17