* byacc - Exception trapped
@ 1997-10-02 10:09 Earnie Boyd
0 siblings, 0 replies; only message in thread
From: Earnie Boyd @ 1997-10-02 10:09 UTC (permalink / raw)
To: gnu-win32
[-- Attachment #1: Type: text/plain, Size: 784 bytes --]
This should be simple:
I wanted to learn lex & yacc. So I bought the O'Reilly & Associates
book. I begin compiling and linking the examples. Things are looking
good and working fine; until, I get to the yacc section in chapter 1.
I have the lex examples coded from Example 1.6 and the yacc examples
coded from Example 1.7 and 1.8. I then do:
flex ch1-05.flex
byacc ch1-05.byacc
gcc -c lex.yy.c y.tab.c
gcc -o ch1-05 lex.yy.o y.tab.o -lfl
Now here is where the problem starts:
I execute ch1-05 and get the attached dump. 8^(
I've also attached the flex and byacc source files.
Does anyone have a solution?
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
ch1_05_error
ch1_05_byacc
ch1_05_flex
[-- Attachment #2: ch1_05_byacc --]
[-- Type: text/x-c, Size: 522 bytes --]
%{
/*
* Example 1-7: Simple yacc sentence parser ch1-05.byacc
*
* A lexer for the basic grammer to use for recognizing English sentences.
*/
#include <stdio.h>
%}
%token NOUN PRONOUN VERB ADVERB ADJECTIVE PREPOSITION CONJUNCTION
%%
sentence: subject VERB object { printf("Sentence is valid.\n"); }
;
subject: NOUN
| PRONOUN
;
object: NOUN
;
%%
extern FILE *yyin;
main()
{
while(!feof(yyin)) {
yyparse();
}
}
yyerror(s)
char *s;
{
fprintf(stderr, "%s\n", s);
}
[-- Attachment #3: ch1_05_error --]
[-- Type: text/plain, Size: 1558 bytes --]
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) In cygwin_except_handler
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) Exception trapped!
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) exception C0000005 at 402C75
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) exception: ax 0 bx 0 cx 10047814 dx 0
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) exception: si 5 di 1000B8B3 bp 240F01C sp 240F01C
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) exception is: STATUS_ACCESS_VIOLATION
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) Stack trace:
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 0: sp = 0x240EE58, pc = 0x1000CEC2
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 1: sp = 0x240EE74, pc = 0x77FA9182
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 2: sp = 0x240EE98, pc = 0x77FA037B
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 3: sp = 0x240EF1C, pc = 0x77F903C2
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 4: sp = 0x240F01C, pc = 0x1000C102
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 5: sp = 0x240FFC4, pc = 0x1000C113
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 6: sp = 0x240FFD0, pc = 0x4032F1
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 7: sp = 0x240FFE0, pc = 0x40103B
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) frame 8: sp = 0x240FFF0, pc = 0x0
(c:\users\bcoeeb0\My Projects\learn\lex\ch1-05.exe 4057) End of stack trace
[-- Attachment #4: ch1_05_flex --]
[-- Type: text/x-c, Size: 2854 bytes --]
%{
/*
* Example 1-6: Lexer to be called from the parser ch1-05.flex
*
* We now build a lexical analyzer to be used by a higher-level parser.
*
*/
#include "y.tab.h" /* token codes from the parser */
#define LOOKUP 0 /* default - not a defined word type. */
int state;
int add_word(int typ, char *word);
int lookup_word(char *word);
%}
%%
/*
* end of line, return to default state
*/
\n {
state = LOOKUP;
}
/*
* end of sentence
*/
\.\n { state = LOOKUP;
return 0;
}
/* whenever a line starts with a reserved part of speech name
* start defining words of that type.
*/
^verb { state = VERB; }
^adj { state = ADJECTIVE; }
^adv { state = ADVERB; }
^noun { state = NOUN; }
^prep { state = PREPOSITION; }
^pron { state = PRONOUN; }
^conj { state = CONJUNCTION; }
/*
* a normal word, define it or look it up
*/
[A-Za-z]+ {
if (state != LOOKUP) {
add_word(state, yytext); /* define the current word */
} else {
switch (lookup_word(yytext)) {
case VERB: return(VERB);
case ADJECTIVE: return(ADJECTIVE);
case ADVERB: return(ADVERB);
case NOUN: return(NOUN);
case PREPOSITION: return(PREPOSITION);
case PRONOUN: return(PRONOUN);
case CONJUNCTION: return(CONJUNCTION);
default: printf("%s: don't recognize\n", yytext);
/* don't return, just ignore it */
}
}
}
. /* ignore anything else */ ;
%%
/*
* define a linked list of words and types
*/
struct word {
char *word_name;
int word_type;
struct word *next;
};
struct word *word_list; /* first element in word list */
extern void *malloc();
int
add_word(int type, char *word)
{
struct word *wp;
if (lookup_word(word) != LOOKUP) {
printf("!!! warning: word %s already defined \n", word);
return 0;
}
/* word not there allocate a new entry and link it on the list */
wp = (struct word *) malloc(sizeof(struct word));
wp->next = word_list;
/* have to copy the word itself as well */
wp->word_name = (char *) malloc(strlen(word)+1);
strcpy(wp->word_name, word);
wp->word_type = type;
word_list = wp;
return 1; /* it worked */
}
int
lookup_word(char *word)
{
struct word *wp = word_list;
/* search down the list looking for the word */
for (; wp; wp = wp->next) {
if (strcmp(wp->word_name, word) == 0)
return wp->word_type
; /* endif */
}
return LOOKUP; /* not found */
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-10-02 10:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-02 10:09 byacc - Exception trapped Earnie Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).