help-bison
[Top][All Lists]
Advanced

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

Bison string processing


From: Vladimir Rykov
Subject: Bison string processing
Date: Wed, 29 Nov 2000 12:10:16 +0300

Hello all!
 
I could not find a good Bison reference - so -
 
I have a little problem with Bison string processing and maybe anybody will be able to help me a little.

I have to write a program which converts the input string:

   vv implies ww ;

in the output line :

<s><r><b>
Imp
<a>vv</a>
<a>ww</a>
</b></r></s>

Actually - it is a XML format file.

Of course - I simplified the problem.

But the thing that stops me is: how to describe string operations in Bison?

I include my little program based on CALC sample Bison one - so that maybe
someone will show me what to do with it.

Actually - it is a problem of concatenation of five strings - incl $1 and $3

BP


Vladimir Rykov, PhD in Computational Linguistics,
MOCKBA, Linguistic Institute of RAS

%{

#include <string.h>

%}

%union {char *sval}

%type <sval> NAME

%token <sval> NAME

%left '-' '+'

%left '*' '/'

%left NEG

%left "implies"

%right '^'



%%



input:

      | input line

;



line:   '\n'

      | exp '\n' { printf ("\t%.10g\n", $1); }

;



exp:    NAME { $$ = $1; }

      | exp "implies" exp {



Concatenation of strings  $$ = "aaa" + $1 "bbb"  + $3 + "ccc";



}

;

%%

#include <ctype.h>



yylex ()

{

  int c;



  while ((c = getchar ()) == ' ' || c == '\t')

    ;

/*  if (c == '.' || isdigit (c))

    {

      ungetc (c, stdin);

      scanf ("%lf", &yylval);

      return NUM;

    }

  */

  if (c == EOF)

    return 0;



  return c;

}



main ()

{

  yyparse ();

}



#include <stdio.h>



yyerror (s)

     char *s;

{

  printf ("%s\n", s);

}





Vladimir Rykov, PhD in Computational Linguistics,
MOCKBA, Linguistic Institute of RAS

reply via email to

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