help-bison
[Top][All Lists]
Advanced

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

newbie (... and with a Bizon q)


From: Fiordean Dacian
Subject: newbie (... and with a Bizon q)
Date: Mon, 3 Jun 2002 16:10:04 +0200

Hello list,
 
I'm new to bizon and I like to solve a problem (banal I guess) that I've encountered these days when I've tried to create a very simple grammer.
 
Here we goes:
 
================Lex file=============================

/* Msc lexer */
%{
class String;
class StringList;
class Document;
#include "mscparse.cpp.h"
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
    { \
    int c = getchar(); \
    result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
    }
%}
 
/* macros */
BLANK       [ \t\n]
LETTER       [A-Za-z]
DIGIT       [0-9]
NATIONAL      address@hidden|\}\~\^]
ALPHA       {LETTER}|{DIGIT}|{NATIONAL}
WORD       ({ALPHA}|".")*{ALPHA}({ALPHA}|".")*
OTHER       [\?\&]
SPECIAL       [\+\-\%\!\/\>\*\(\)\"\,\=\:]
NQTEXT       {ALPHA}|{OTHER}|{SPECIAL}|[\.\_\ \;]
NAME       {WORD}("_"{WORD})*
 

%%
 
{BLANK}+       {/* do nothing */  }
 
"+"                              { return '+';  }
"-"                              { return '-';  }
"%"                              { return '%';  }
"!"                              { return '!';  }
"/"                              { return '/';  }
">"                              { return '>';  }
"*"                              { return '*';  }
"("                              { return '(';  }
")"                           { return ')';  }
"\""        { return '\"'; }
","                              { return ',';  }
"="                            { return '=';  }
":"                              { return ':';  }
";"         { return ';';  }
 
(m|M)(s|S)(c|C)(d|D)(o|O)(c|C)(u|U)(m|M)(e|E)(n|N)(t|T)     {
                   printf("%s\n", mscparsetext);
                   return KW_MSCDOCUMENT;
                  }
{NAME} {
   mscparselval.string_type = mscparsetext;
   printf("%s\n", mscparsetext);
   return TK_NAME;
  }
.                  { printf("%s\n", mscparsetext); return TK_STRING; }
 
%%
 

========================Bizon file==================
 
%{
#include <iostream.h>
#include <mscdoc.h>
#include "String.h"
#include "StringList.h"
#include "Document.h"
%}
 
%{
extern Document *document;
extern int mscparselex();
extern int mscparseerror(const char *s);
%}
 
%union
{
 int integer_type;
 char* string_type;
 StringList* string_list_type;
 StringList* instance_name_list_type;
 Document* document_type;
}
 
%token <string_type> TK_NAME
%token <string_type> TK_STRING
%token KW_MSCDOCUMENT
%type <string_type> char_string
%type <string_type> name possible_name
%type <string_type> comment possible_comment
%type <string_type> end
%type <document_type> msc_document msc_document_head
%%
 


/* 2. Message sequence char document
*/
 
msc_document
   : msc_document_head 
    { 
      $$=$1;
    }
   ;
   
msc_document_head
   : KW_MSCDOCUMENT name end 
     { 
       document = new Document;
      document->m_pDocument->Name($2);
      delete $2;
      delete $3;
      $$ = document;
     }
   ;
 
/* 3.1 General rules
*/
 
char_string 
   : TK_STRING
   ;
 
name
 : TK_NAME
 ;
 
possible_name
    : name
     | /* empty */ { $$=0; }
     ;
 
/* 3.2 comment
*/
 
end
 : possible_comment ';'
    ;
 
possible_comment
    : comment
    | /* empty */ 
     { 
      $$=0;
     }
    ;
comment
  : KW_COMMENT char_string { $$=$2; }
     ;
 
 
Well, my question is when a write down an input like this;
 
mscdocument xyz;
 
why I can't receive in $2 parameter of msc_document_head production the value xyz.
 
Anyone can help me with it?
 
Thx in advance,
// D.
 
 

reply via email to

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