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

shift/reduce conflicts while writing rule to resolve nested preprocessor inside a structure.How to resolve this?

This gives 66 shift/reduce conflicts initializer : '{' initializer_list '}' | '{' initializer_list ',' '}' | '{' preprocessor_list initializer_list '}' ; preprocessor_list : preprocessor |…
Pinky
  • 11
  • 2
0
votes
2 answers

is it possible to separate the concept of precedence and association in yacc

I would like to have a clear example of precedence and one of associativity in yacc, but I find myself yet in having troubles separating these two concepts. Perhaps this is due to the fact that I'm associating these two concepts to math and…
LMG
  • 966
  • 1
  • 12
  • 28
0
votes
1 answer

syntax error when using byacc

When using byacc, getting following error. byacc -d -p ws_yy_ wmlscript/wsgram.y && mv y.tab.c wmlscript/wsgram.c byacc: e - line 111 of "wmlscript/wsgram.y", syntax error %pure_parser ^ make: *** [wmlscript/wsgram.c] Error 1 byacc version: 1.9…
Nandeesh Bijoor
  • 173
  • 2
  • 16
0
votes
1 answer

using yyparse() and fprintf

I've a piece of code for a compiler for basic arithmetic (add, diff). In my mparse.y yacc file, I've read input from a file in main function. To invoke parsing, I've put the condition as follows: if(yyparse()==0) fprintf(stderr,"Parsing…
0
votes
1 answer

How to solve this ambiguous grammar?

I am creating a compiler and I am using lex and bison. This is a part of my grammar : math : math binop math | VAR | INT | GREEK | "(" math ")" | math comp math | "-" math | math math | "\\sqrt" "{" math…
0
votes
1 answer

Correct order in YACC left-recursion

Suppose we have the following simplistic YACC grammar: start: list { if ($1 != NULL) { Reverse(&$1); /*correct order*/ } Generate($1); } ; list: list item { $$ = Node($2, $1); …
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
0
votes
2 answers

Why is my C Yacc/lex calculator not parsing correctly?

I have built a calculator using C Yacc and Lex that can store 26 variables for the letters of the alphabet. Here's what it is supposed to look like: Example Input: a = 55-3; b = c = a-42; a+b*c; c = 6; a = b; a = 10000; b =…
0
votes
1 answer

Bison: Getting/Storing Values of nonterminals

I wrote a simple C-like grammar in Bison, and I have a weird problem. In the following rule: declaration: "identifier" length init_values {symbolTable.add($3,$4,$5);} I want to get the int values of…
0
votes
1 answer

Regular expression for string excluding literal quotation marks

I have the following config file that I am trying to parse. [ main ] e_type=0x1B username="username" appname="applicationname" In the lex file (test.l) specified below,the regular expression for STR is \"[^\"]*\" so that it recognizes everything…
liv2hak
  • 14,472
  • 53
  • 157
  • 270
0
votes
1 answer

Trying to Resolve Shift Reduce Conflicts by Changing Grammar

Given the following specification for a grammar: Statement → { Statement* } → VarDecl → if ( Exp ) Statement else Statement → while ( Exp ) Statement → System.out.println ( Exp ) ; → id = Exp ; → id [ Exp ]= Exp…
user2116243
  • 303
  • 2
  • 10
0
votes
1 answer

Input buffer overflow in spite of reading character by character

In order to overcome the issue of input buffer overflow in lex, I wrote code to read the incoming stream character by character whenever I expect to see a long string, however, still get the error input buffer overflow, can't enlarge buffer because…
mickeyj
  • 91
  • 7
0
votes
1 answer

What about very long input and yacc /lex?

I consider how is solve problem with too long input for yacc and lex. I have got no possibility to control length of length of input and I am afraid of bufferflow attack, for example. What do you think?
J. Doe
  • 101
  • 8
0
votes
1 answer

yacc error handling for missing left parenthesis

I have written a yacc file. currently error function looks like this : void yyerror(char *s) { fprintf(stderr, "line %d: %s\n", yylineno, s); } Now while giving input to it, if there is a left parenthesis is missing it gives simple…
ronny
  • 11
0
votes
0 answers

Need Help In Parser starting

Hi I am trying to follow the book "Modern Compiler Implementation in C" in the 3 chapter PARSER I am not able execute the parser exercise. %{ #include #include "util.h" #include "errormsg.h" int yylex(void); /* function prototype */…
KARTHIK BHAT
  • 1,410
  • 13
  • 23
0
votes
1 answer

yylval undefined with lex and yacc

I was trying a simple program to create an abstract syntax tree using lex and yacc. My yacc_file.y is %{ #include #include #include typedef struct node { struct node *left; struct node *right; char…
Apoorva Somani
  • 515
  • 1
  • 6
  • 23
1 2 3
99
100