[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bison's semantic parser

From: Hans Aberg
Subject: Bison's semantic parser
Date: Wed, 18 Oct 2000 15:11:09 +0200

I attach some code using Bison's semantic parser that I was able to get at
least some working output from, even though it is buggy.

It is a variation of the RPN calculator in the Bisosn manual. I can type
   2 2 + <return> ... <return>
with several <return> to finally get 4 as output.

The idea I have in mind is once the bugs have been ironed out, to modify
tit with a hashtable for names, and insert a new command say
    define <name>
in order to create a semantic dependance. The one insert a syntax variable
    expression: NAME '=' expression %guard { check_name_defined(); }
                               { /* Assign variable value to variable */ }
where check_name_defined() should set yyerror to 1 if the name is not
defined and also some yyguard penalty recovering value.

Some observations:

The C-code before the Bsion definitions seems to be put in a header, the
stuff after in the .tab.c file.

yyerror is here an int. Instead it has yyabort, which seems to correspond
to yyerror of the non-semantic parsers. One also has to define the

 yyrecover() -- Don't know what this is for, set to nothing here.
 char* yymsg -- Don't know how this should be used; just a generic default
 int timeclock -- Don't know how this is used.

struct mytype {
        clock_t timestamp;    -- Measuerd in favorite time units.
        int first_line, last_line, first_column, last_column;
        char* text;
typedef struct mytype mytype;
#define YYLTYPE mytype

Attachment: rpcalc_semantic.y
Description: Text document

  Hans Aberg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]