PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Yacc

Yacc

Yacc, aka Yet Another Compiler-Compiler, is a grammar language created in 1975.

#80on PLDB 47Years Old 3.1kUsers
4Books 1Papers 11kRepos

Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system. It is a Look Ahead Left-to-Right (LALR) parser generator, generating a parser, the part of a compiler that tries to make syntactic sense of the source code, specifically a LALR parser, based on an analytic grammar written in a notation similar to Backus–Naur Form (BNF). Yacc itself used to be available as the default parser generator on most Unix systems, though it has since been supplanted as the default by more recent, largely compatible, programs.. Read more on Wikipedia...


Example from Linguist:
%{ /* * Test program: Advanced Calculator * by Zhao Cheng 5/20/2012 */ %} %union { double val; /* For returning numbers. */ symrec *tptr; /* For returning symbol-table pointers. */ } %token <val> NUMBER %token <tptr> VAR FNCT %right '=' %left '+' '-' %left '*' '/' %right '^' %left NEG %type <val> expression %{ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "calc.h" /* Contains definition of `symrec'. */ %} %% statement : /* empty */ { exit(0); } | expression { printf("= %f\n", $1); } ; expression : NUMBER { $$ = $1; } | VAR { $$ = $1->value.var; } | VAR '=' expression { $$ = $3; $1->value.var = $3; } | FNCT '(' expression ')' { $$ = (*($1->value.fnctptr))($3); } | expression '*' expression { $$ = $1 * $3; } | expression '/' expression { $$ = $1 / $3; } | expression '+' expression { $$ = $1 + $3; } | expression '-' expression { $$ = $1 - $3; } | expression '^' expression { $$ = pow($1, $3); } | '-' expression %prec NEG { $$ = -$2; } | '(' expression ')' { $$ = $2; } ; %% struct init { char const *fname; double (*fnct) (double); }; struct init const arith_fncts[] = { "sin" , sin , "asin" , asin , "cos" , cos , "acos" , acos , "tan" , tan , "atan" , atan , "ceil" , ceil , "floor" , floor , "abs" , fabs , "ln" , log , "log" , log10 , "lg" , log2 , "exp" , exp , "sqrt" , sqrt , 0 , 0 }; /* The symbol table: a chain of `struct symrec'. */ symrec *sym_table; /* Put arithmetic functions in table. */ void init_table (void) { int i; symrec *ptr; for (i = 0; arith_fncts[i].fname != 0; i++) { ptr = putsym (arith_fncts[i].fname, FNCT); ptr->value.fnctptr = arith_fncts[i].fnct; } } int main() { init_table(); while (yyparse() == 0) ; return 0; } void yyerror(const char *msg) { fprintf(stderr, "Error: %s\n", msg); } symrec * putsym (char const *sym_name, int sym_type) { symrec *ptr; ptr = (symrec *) malloc (sizeof (symrec)); ptr->name = (char *) malloc (strlen (sym_name) + 1); strcpy (ptr->name,sym_name); ptr->type = sym_type; ptr->value.var = 0; /* Set value to 0 even if fctn. */ ptr->next = (struct symrec *)sym_table; sym_table = ptr; return ptr; } symrec * getsym (char const *sym_name) { symrec *ptr; for (ptr = sym_table; ptr != (symrec *) 0; ptr = (symrec *)ptr->next) if (strcmp (ptr->name,sym_name) == 0) return ptr; return 0; }

Language features

Feature Supported Example Token
MultiLine Comments
/* A comment
*/
/* */
Comments
// A comment
Line Comments
// A comment
//
Semantic Indentation ϴ

Books about Yacc from ISBNdb

title authors year publisher
Compiler Design Using FLEX and YACC Das, Vinu V. 2007 PHI
Lex & Yacc Doug Brown Doug and John R. Levine and Tony Mason and Tony Mason and Doug Brown 2012 O’Reilly Media
Compiler Construction Using Java, JavaCC, and Yacc Anthony J. Dos Reis 2012-02-23 Wiley
Compiler Construction Using Java, JavaCC, and Yacc Anthony J. Dos Reis 2012 Wiley

Publications about Yacc from Semantic Scholar

title authors year citations influentialCitations
Yacc in sasl — an exercise in functional programming S. Jones 1985 20 0
sagemath.html · yacc.html · graphql.html

View source

PLDB - Build the next great programming language · v2022 · Day 31 · Docs · Build · Acknowledgements · Traffic Today · Traffic Trends · Mirrors · GitHub · feedback@pldb.com