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

Simple Flex/Bison C++

I already looked for my answer but I didn't get any quick response for a simple example. I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things. Searching over internet I've…
Jack
  • 131,802
  • 30
  • 241
  • 343
14
votes
2 answers

Lex strings with single, double, or triple quotes

My objective is to parse like Python does with strings. Question: How to write a lex to support the following: "string..." 'string...' """multi line string \n \n end""" '''multi line string \n \n end''' Some code: states = ( ('string',…
Steve Peak
  • 2,657
  • 1
  • 17
  • 18
14
votes
5 answers

How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)

I want my yylex() to parse a string rather than a file or standard input. How can I do it with the Lex and Yacc provided with Solaris?
ajai
  • 363
  • 3
  • 6
  • 14
14
votes
5 answers

A notation for empty right-hand sides of rules

When writing a ("theoretical") grammar with a rule with an empty right-hand side, one always use a symbol such as ε (or 1) to make this emptiness explicit: A → ε | a A Such a grammar in Yacc and others would then look like a: | 'a' a or "worse" a:…
akim
  • 8,255
  • 3
  • 44
  • 60
13
votes
5 answers

Is there a Sublime Text Syntax for Flex and Bison?

I'm looking for a syntax in Sublime Text that highlights my Flex and Bison files (or lex/yacc) in a way that makes them readable... Sublime Text automatically chooses Lisp for Flex files, but that doesn't do the trick all that well. Any suggestions…
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
13
votes
5 answers

bison end of file

If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not…
user34537
12
votes
2 answers

Python/YACC Lexer: Token priority?

I'm trying to use reserved words in my grammar: reserved = { 'if' : 'IF', 'then' : 'THEN', 'else' : 'ELSE', 'while' : 'WHILE', } tokens = [ 'DEPT_CODE', 'COURSE_NUMBER', 'OR_CONJ', 'ID', ] + list(reserved.values()) t_DEPT_CODE =…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
12
votes
3 answers

Looking for a Java grammar in lex/yacc format

Does anyone know an online repository for lex/yacc format grammars? I'm looking for a Java grammar to make a quicky sourcecode converter. Thank you! edit: I'm preferably looking for lex/yacc because I want to use fslex/fsyacc with as little grammar…
12
votes
2 answers

How can I implement #include constructs with Flex and YACC?

During parsing, if I encounter a include token I want to instruct YACC to open the file specified as input and to begin parsing this. Once this parsing is finished, I want to instruct YACC to return to the file and continue parsing directly after…
Gozzy
  • 121
  • 1
  • 3
12
votes
4 answers

Yacc/Jay grammar file for JavaScript?

Possible Duplicate: Where can I find a yacc gammar for ECMAscript/Actionscript/Javascript I'm trying to find a grammar file for JavaScript for Yacc (preferably for Jay, but since Jay is a Yacc clone I should be fine, since I need to implement it…
thr
  • 19,160
  • 23
  • 93
  • 130
12
votes
2 answers

C11 grammar ambiguity between _Atomic type specifier and qualifier

I'm trying to write a lex/yacc grammar for C11 based off of N1570. Most of my grammar is copied verbatim from the informative syntax summary, but some yacc conflicts arose. I've managed to resolve all of them except for one: there seems to be some…
jbatez
  • 1,772
  • 14
  • 26
11
votes
2 answers

Haskell parsing tools - yacc:lex :: happy:?

So, it seems like Happy is a robust replacement for yacc in Haskell. Is there an equally robust lexer generator to replace lex/flex?
Geoff
  • 873
  • 1
  • 7
  • 14
11
votes
2 answers

Trying to build a C# grammar for bison/wisent

I've never done Bison or Wisent before. how can I get started? My real goal is to produce a working Wisent/Semantic grammar for C#, to allow C# to be edited in emacs with code-completion, and all the other CEDET goodies. (For those who don't know,…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
11
votes
2 answers

Resolving reduce/reduce conflict in yacc/ocamlyacc

I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular yacc) which supports function application with no operators (like in Ocaml or Haskell), and the normal assortment of binary and unary operators. I'm getting a reduce/reduce…
Jay Conrod
  • 28,943
  • 19
  • 98
  • 110
11
votes
1 answer

Generating a compiler from lex and yacc grammar

I'm trying to generate a compiler so I can pass him a .c file after. I've downloaded both YACC and LEX grammars from http://www.quut.com/c/ANSI-C-grammar-y.html and named them clexyacc.l and clexyacc.y When generating it on terminal I did : yacc -d…
ChasingCars
  • 125
  • 1
  • 1
  • 6