Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

what is the value in yacc?

Posted on 1998-10-30
14
Medium Priority
?
556 Views
Last Modified: 2010-04-15
Hi I need to put the the value of a yacc token into a char variable. How do I do it?
I need an answer quick.
0
Comment
Question by:laeuchli
14 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1253938
Sorry, what it is yacc?
0
 
LVL 1

Expert Comment

by:MatthewL
ID: 1253939
yacc - yet another compiler compiler

common utility in unix systems.  laeuchli must be using to write a C compiler.  I had a simular assignment in 4th year university.

unfortunately I can't remember the answer to laeuchli's question.  
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253940
that right. Please look it up if you can. If you feel I am  offering to few points I will offer more.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:elfie
ID: 1253941
if inside your yylval union s stands for your strings, you can have something like

strcpy (chararray, $1->s);

where $1 refers to another rule.

When using lex, inside lex you would have something that looks like yylval.s as a string representation of your token for identifier.


0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253942
I am not a yacc expert I am just starting. What is the yylval union? I have not set it up.Please explane a little more.

0
 
LVL 3

Expert Comment

by:elfie
ID: 1253943
if you are using lex and yacc.

Inside lex a variable(array) yytext is defined (check your generated .c source file after running lex on the .l file.
If yytext exist, it will contain the value you want.

in your yacc when you encounter a token (eg. IDENT), you can use the value in the variable yytext, it will contain what you have put in it in your lex rule

If this answer is not enough, please specify your OS, as i'm using different version of lex/yacc on each system
0
 
LVL 3

Accepted Solution

by:
elfie earned 300 total points
ID: 1253944
if you are using lex and yacc.

Inside lex a variable(array) yytext is defined (check your generated .c source file after running lex on the .l file.
If yytext exist, it will contain the value you want.

in your yacc when you encounter a token (eg. IDENT), you can use the value in the variable yytext, it will contain what you have put in it in your lex rule

If this answer is not enough, please specify your OS, as i'm using different version of lex/yacc on each system
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253945
I am useing LINUX. The way I understand it is that you setup a %union union and put the variable you want to use yylval with like this:
%union
{
char test[100];
}
However this does not work. Why?

0
 
LVL 3

Expert Comment

by:elfie
ID: 1253946
did you refer to the variable yylval.test ?
eg. printf ("%s\n", yylval.test);
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253947
elfie sorry two more question. one what does $1 mean? please explain. is there any other thing I can put the data in besides a union?


0
 
LVL 3

Expert Comment

by:elfie
ID: 1253948
$1 refers to the first part of your current rule in yaac, with $1 you can refer to the contents of that part.
eg if you have a rule

float: integers DOT integers { first_part = $1; second_part=$2}

and integers is a rule inside yacc, $1 refers to the part before the DOT, and $2 to the part after the dot.
I would suggest to search a book on LEX and YACC, and read something about how to program lex/yacc.

FYI: flex/bison are the GNU equivalents

As you maybe know when working with lex and yacc, both parts will be combined into one program. So if you define some global variables, you can always put some data inside them, but just remember that each you execute a rule, the same variables will used (and thus overwritten). On the other hand inside the union you can put as much variables as you want.

(Sorry for the sometimes late answers, i'm currently quite busy, and working on a number of different locations)

0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253949
Are there any sites on the internet that have examples of this?
P.S. If you give me a hand this last time I will give you some more points. I think I short changed you.

0
 
LVL 3

Expert Comment

by:elfie
ID: 1253950
http://www.enc.hull.ac.uk/people/pjp/Teaching/08208-9697/08208IntroductoryLab.html

This gives a short introduction.
To find it www.altavista.com search engine, and specified
"+lex +yacc +example +yylval +union". this gave more 49 hits.

0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253951
Thanks. Standby I will post a blank question with points for you.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question