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
9
votes
5 answers

yacc/lex or hand-coding?

I am working on new programming language, but I was always puzzled by the fact that everyone is using yaxx/lex to parse the code, but I am not. My compiler (which is already working) is handcoded in C++/STL, and I cannot say it's complex or took too…
BarsMonster
  • 6,483
  • 2
  • 34
  • 47
9
votes
2 answers

Problems with PLY LEX and YACC

I am trying to run the first part of a simple example of the PLY but I encounter a strange error. When I run the following code, it gives me an error regarding lex.lex() Anyone knows what the problem is? import ply.lex as lex tokens = […
sabzdarsabz
  • 343
  • 5
  • 15
9
votes
1 answer

What is the meaning of yytext[0]?

What is the meaning of yytext[0]? And why should we use in the lex and yacc program? I'm learner so don't mind if it is a silly question.
sandy
  • 149
  • 1
  • 2
  • 8
9
votes
3 answers

On ocamlyacc, function application grammar and precedence

I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I can't figure this out. My grammar allows something like this: let sub = fun x -> fun y -> x - y;; However, if I want to use the function so defined, I can write: (sub 7) 3…
Amadan
  • 191,408
  • 23
  • 240
  • 301
8
votes
3 answers

Controlling Python PLY lexer states from parser

I am working on a simple SQL select like query parser and I need to be able to capture subqueries that can occur at certain places literally. I found lexer states are the best solution and was able to do a POC using curly braces to mark the start…
haridsv
  • 9,065
  • 4
  • 62
  • 65
8
votes
2 answers

How does the yacc/bison LALR(1) algorithm treat "empty" rules?

In a LALR(1) parser, the rules in the grammar are converted into a parse table that effectively says "If you have this input so far, and the lookahead token is X, then shift to state Y, or reduce by rule R". I have successfully constructed a LALR(1)…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
8
votes
1 answer

EOF error in parser YACC

I am trying to parse a string using the yacc parser provided in the PLY library for Python. The parser itself is very long, but the problem that i am having is that it always gives me the same error, no matter what kind of string i put. The error…
camelCase
  • 521
  • 2
  • 10
  • 22
8
votes
4 answers

Is it possible to have two or more Lex/Yacc parsers in the same application

I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose. Is it possible to have more than one? And if so how do you get another entry point? Thanks david allan…
David Allan Finch
  • 1,414
  • 8
  • 20
8
votes
3 answers

how to setup flex/bison rules for parsing a comma-delimited argument list

I would like to be able to parse a non-empty, one-or-many element, comma-delimited (and optionally parenthesized) list using flex/bison parse rules. some e.g. of parseable lists : 1 1,2 (1,2) (3) 3,4,5 (3,4,5,6) etc. I am using the following…
sriaudacity
  • 157
  • 1
  • 6
8
votes
2 answers

What does %prec '.' mean here in yacc?

notype_declarator: notype_declarator '(' parmlist_or_identifiers %prec '.' { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); } Anyone familiar with yacc rules?
assem
  • 3,023
  • 4
  • 20
  • 20
8
votes
2 answers

How can I eliminate the 'main' routine of the flex & bison so I can put the lexing and parsing process into a library?

I'm working on a parser that parses json string and I want to make it a library. The problem is that when I use ld to link the library I wrote, there's a error message: main.o: In function `main': main.c:(.text+0x0): multiple definition of…
mapcan
  • 81
  • 1
  • 2
8
votes
2 answers

Accessing result of a golang yacc generated parser

I am trying to create a parser using golang's yacc tool. I found nex to simplify creating a lexer to give the parser. My problem now is that the generated parser has no method or field to give me access to the parsing result. I could just store the…
Emil L
  • 20,219
  • 3
  • 44
  • 65
8
votes
1 answer

freeing the string allocated in strdup() from flex/bison

I have flex code that copies a string lexeme using strdup(). %{ #include "json.tab.h" #define YY_DECL extern "C" int yylex() %} %option noyywrap %% [ \t\n]+ ; \"[a-zA-Z]+\" {yylval.sval = strdup(yytext); return STRING; } [0-9]+ {yylval.ival…
prosseek
  • 182,215
  • 215
  • 566
  • 871
8
votes
2 answers

What is the difference between lex/yacc and fslex/fsyacc?

I'm learning F# because I'd like to write a lexer and parser. I have a tiny bit of experience with this sort of processing but really need to learn it properly as well as F#. When learning the lexing/parsing functionality of F#, is studying lex and…
Alex Angas
  • 59,219
  • 41
  • 137
  • 210
8
votes
2 answers

Simple yacc grammars give an error

I have a question for yacc compiler. I do not compile simple yacc grammar. Here is the code section : /*anbn_0.y */ %token A B %% start: anbn '\n' {printf(" is in anbn_0\n"); return 0;} anbn: empty | A anbn B ; empty: ; %% #include…
tilt_y
  • 119
  • 1
  • 1
  • 4