YACC and LEX question

YACC and LEX question

Post by Gary Barwi » Sun, 10 Sep 1995 04:00:00



Hello all unix programmers,

Can you please help me? I have an assignment to do for university
and haven't a clue how to do it. The Lecturer has not been very
helpful and time is running out. If anyone out there can help I
would be very happy if you could post me a solution or at least
how to do it. It is a minor, my main purpose is to learn how to use
YACC and LEX!

Thanks
Gary

The Problem
-----------

Demonstrate your understanding to LEX and YACC specifications by designing,
implementing and testing a LEX/YACC specification for a recogniser for uni-variate
polynomials with real co-efficients and non-negative exponents. You may assume
the "variable" is only "x". The acceptable format of such polynomials should
be flexible as is sensible. Illegal polynomials MUST be reported and rejected.
In a single run of the recogniser a sequence of polynomials (NOT just one) should
be recognised (simpler error recover should be designed-in).

By the way of acceptable sample polynomials, I consider the following as minimal:

(i)     12345
(ii)    123.456x + 75x - x^3 + x^9
(iii)   +3x^5 + x^0 - 65.4 -7x^12

Notes:

1. the "order" of the powers of x should be irrelevant
2. it should be possible to have the same power appearing more than once.
3. while the examples above did not have any co-efficients with exponents, this
   would be useful.
4. develop your design - start out simple (e.g. integer coefficients and other
   simplifying assumptions) and then relax the restrictions one at a time.
5. your design description should be for the complete "polynomial" even though
   your implementation may not be as complete.
6. use railroad diagrams as well as YACC notation to describe your mini-lannguage.

 
 
 

YACC and LEX question

Post by Erik D. McWillia » Sun, 10 Sep 1995 04:00:00



>Hello all unix programmers,
>Can you please help me? I have an assignment to do for university
>and haven't a clue how to do it. The Lecturer has not been very
>helpful and time is running out. If anyone out there can help I
>would be very happy if you could post me a solution or at least
>how to do it. It is a minor, my main purpose is to learn how to use
>YACC and LEX!

I recommend studying up on lex/yacc yourself instead of waiting for
someone on the net to do your homework.  

Try the O'Reilly book.  It even has an example on parsing algebraic
expressions.

Quote:>Thanks
>Gary
>The Problem
>-----------
>Demonstrate your understanding to LEX and YACC specifications by designing,
>implementing and testing a LEX/YACC specification for a recogniser for uni-variate
>polynomials with real co-efficients and non-negative exponents. You may assume
>the "variable" is only "x". The acceptable format of such polynomials should
>be flexible as is sensible. Illegal polynomials MUST be reported and rejected.
>In a single run of the recogniser a sequence of polynomials (NOT just one) should
>be recognised (simpler error recover should be designed-in).
>By the way of acceptable sample polynomials, I consider the following as minimal:
>(i)         12345
>(ii)        123.456x + 75x - x^3 + x^9
>(iii)       +3x^5 + x^0 - 65.4 -7x^12
>Notes:
>1. the "order" of the powers of x should be irrelevant
>2. it should be possible to have the same power appearing more than once.
>3. while the examples above did not have any co-efficients with exponents, this
>   would be useful.
>4. develop your design - start out simple (e.g. integer coefficients and other
>   simplifying assumptions) and then relax the restrictions one at a time.
>5. your design description should be for the complete "polynomial" even though
>   your implementation may not be as complete.
>6. use railroad diagrams as well as YACC notation to describe your mini-lannguage.

--
                              The CRT Corporation
                      Computer Based Research and Training


 
 
 

YACC and LEX question

Post by Jonathan Ch » Tue, 12 Sep 1995 04:00:00



Quote:>Hello all unix programmers,

>Can you please help me? I have an assignment to do for university
>and haven't a clue how to do it. The Lecturer has not been very
>helpful and time is running out. If anyone out there can help I
>would be very happy if you could post me a solution or at least
>how to do it. It is a minor, my main purpose is to learn how to use
>YACC and LEX!

Pick up "lex & yacc" published by O'Reilly & Associates. It's a good
tutorial and reference for these tools

[You didn't think that I'd do your homework for you, didja?]
--
-------------------------------------------------------------------

-------------------------------------------------------------------

 
 
 

1. Simple lex v. yacc question

I have never used either lex or yacc, but I read the documentation
for both. I have no idea which is better suited for my task though.
Basically, I have a simple file format in which I have multiple items,
each with different attributes. Each item is bounded by { }, and the
attributes are not all necessarily present. They are case-insensitive
and predefined. Comments are permitted. For example:

% foo
{ NAME = foo; COLOR=bar; QUANTITY=3} {name=fubar} {name =barfoo;;; COLOR=blue}

Should I use lex and or yacc?
Thank you very much

        Joseph

                                                           ---
                                                joseph p turian

"I must Create a System or be enslav'd by another Man's.
I will not Reason & Compare: my business is to Create."
---William Blake

2. Keyboard/font problems

3. Lex (Flex) and Yacc (or Bison) questions.

4. TV ?

5. LEX / YACC yywrap() question

6. Two boot networking problems

7. Followup YACC & LEX Question

8. losing default route -> crash?

9. lex/yacc question

10. lex, yacc question

11. Yacc & Lex Question

12. lex/yacc/cc/unix question

13. YACC and LEX question