OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [treelang/] [lex.l] - Diff between revs 154 and 816

Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* -*- c -*- = mode for emacs editor
/* -*- c -*- = mode for emacs editor
   TREELANG lexical analysis
   TREELANG lexical analysis
   ---------------------------------------------------------------------
   ---------------------------------------------------------------------
   Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003,
   Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003,
   2004, 2005, 2007 Free Software Foundation, Inc.
   2004, 2005, 2007 Free Software Foundation, Inc.
   This program is free software; you can redistribute it and/or modify it
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3, or (at your option) any
   Free Software Foundation; either version 3, or (at your option) any
   later version.
   later version.
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING3.  If not see
   along with this program; see the file COPYING3.  If not see
   .
   .
   In other words, you are welcome to use, share and improve this program.
   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!
   what you give them.   Help stamp out software-hoarding!
   ---------------------------------------------------------------------
   ---------------------------------------------------------------------
   Written by Tim Josling 1999-2001, based in part on other parts of
   Written by Tim Josling 1999-2001, based in part on other parts of
   the GCC compiler.  */
   the GCC compiler.  */
%{
%{
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "tm.h"
#include "tm.h"
#include "input.h"
#include "input.h"
#include "tree.h"
#include "tree.h"
/* Token defs.  */
/* Token defs.  */
#include "treelang.h"
#include "treelang.h"
#include "parse.h"
#include "parse.h"
#include "treetree.h"
#include "treetree.h"
#include "toplev.h"
#include "toplev.h"
extern int option_lexer_trace;
extern int option_lexer_trace;
int yylex (void);
int yylex (void);
void update_yylval (int a);
void update_yylval (int a);
static int next_tree_charno = 1;
static int next_tree_charno = 1;
static int lineno = 1;
static int lineno = 1;
static void update_lineno_charno (void);
static void update_lineno_charno (void);
static void dump_lex_value (int lexret);
static void dump_lex_value (int lexret);
#define SAVE_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
#define SAVE_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
   {fprintf (stderr, "\nlexer returning"); dump_lex_value (a);} return a;}
   {fprintf (stderr, "\nlexer returning"); dump_lex_value (a);} return a;}
#define NOT_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
#define NOT_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
   {fprintf (stderr, "\nlexer swallowing"); dump_lex_value (a);}}
   {fprintf (stderr, "\nlexer swallowing"); dump_lex_value (a);}}
#ifndef USE_MAPPED_LOCATION
#ifndef USE_MAPPED_LOCATION
#undef LINEMAP_POSITION_FOR_COLUMN
#undef LINEMAP_POSITION_FOR_COLUMN
#define LINEMAP_POSITION_FOR_COLUMN(INPUT, LINETABLE, COL)
#define LINEMAP_POSITION_FOR_COLUMN(INPUT, LINETABLE, COL)
#endif
#endif
%}
%}
%option nostack
%option nostack
%option nounput
%option nounput
%option noyywrap
%option noyywrap
%option pointer
%option pointer
%option nodefault
%option nodefault
%%
%%
 {
 {
   /* ??? Should really allocate only what we need.  */
   /* ??? Should really allocate only what we need.  */
   yylval = my_malloc (sizeof (struct prod_token_parm_item));
   yylval = my_malloc (sizeof (struct prod_token_parm_item));
   LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
   LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
                                next_tree_charno);
                                next_tree_charno);
   ((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
   ((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
   ((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
   ((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
 }
 }
[ \n\t]+ {
[ \n\t]+ {
  update_lineno_charno ();
  update_lineno_charno ();
  NOT_RETURN (WHITESPACE);
  NOT_RETURN (WHITESPACE);
}
}
"//".*  {
"//".*  {
  /* Comment.  */
  /* Comment.  */
  update_lineno_charno ();
  update_lineno_charno ();
  NOT_RETURN (COMMENT);
  NOT_RETURN (COMMENT);
}
}
"{" {
"{" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (LEFT_BRACE);
  SAVE_RETURN (LEFT_BRACE);
}
}
"}" {
"}" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (RIGHT_BRACE);
  SAVE_RETURN (RIGHT_BRACE);
}
}
"(" {
"(" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (LEFT_PARENTHESIS);
  SAVE_RETURN (LEFT_PARENTHESIS);
}
}
")" {
")" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (RIGHT_PARENTHESIS);
  SAVE_RETURN (RIGHT_PARENTHESIS);
}
}
"," {
"," {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (COMMA);
  SAVE_RETURN (COMMA);
}
}
";" {
";" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (SEMICOLON);
  SAVE_RETURN (SEMICOLON);
}
}
"+" {
"+" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (tl_PLUS);
  SAVE_RETURN (tl_PLUS);
}
}
"-" {
"-" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (tl_MINUS);
  SAVE_RETURN (tl_MINUS);
}
}
"=" {
"=" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (ASSIGN);
  SAVE_RETURN (ASSIGN);
}
}
"==" {
"==" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (EQUALS);
  SAVE_RETURN (EQUALS);
}
}
[+-]?[0-9]+ {
[+-]?[0-9]+ {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (INTEGER);
  SAVE_RETURN (INTEGER);
}
}
"external_reference" {
"external_reference" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (EXTERNAL_REFERENCE);
  SAVE_RETURN (EXTERNAL_REFERENCE);
}
}
"external_definition" {
"external_definition" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (EXTERNAL_DEFINITION);
  SAVE_RETURN (EXTERNAL_DEFINITION);
}
}
"static" {
"static" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (STATIC);
  SAVE_RETURN (STATIC);
}
}
"automatic" {
"automatic" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (AUTOMATIC);
  SAVE_RETURN (AUTOMATIC);
}
}
"int" {
"int" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (INT);
  SAVE_RETURN (INT);
}
}
"char" {
"char" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (CHAR);
  SAVE_RETURN (CHAR);
}
}
"void" {
"void" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (VOID);
  SAVE_RETURN (VOID);
}
}
"unsigned" {
"unsigned" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (UNSIGNED);
  SAVE_RETURN (UNSIGNED);
}
}
"return" {
"return" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (tl_RETURN);
  SAVE_RETURN (tl_RETURN);
}
}
"if" {
"if" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (IF);
  SAVE_RETURN (IF);
}
}
"else" {
"else" {
  update_lineno_charno ();
  update_lineno_charno ();
  SAVE_RETURN (ELSE);
  SAVE_RETURN (ELSE);
}
}
[A-Za-z_]+[A-Za-z_0-9]* {
[A-Za-z_]+[A-Za-z_0-9]* {
  update_lineno_charno ();
  update_lineno_charno ();
  update_yylval (NAME);
  update_yylval (NAME);
  if (option_lexer_trace)
  if (option_lexer_trace)
    {
    {
      fprintf (stderr, "\nlexer returning");
      fprintf (stderr, "\nlexer returning");
      dump_lex_value (NAME);
      dump_lex_value (NAME);
    }
    }
  return NAME;
  return NAME;
}
}
[^\n]  {
[^\n]  {
  update_lineno_charno ();
  update_lineno_charno ();
  error ("%HUnrecognized character %qc.",
  error ("%HUnrecognized character %qc.",
         &((struct prod_token_parm_item *)yylval)->tp.tok.location,
         &((struct prod_token_parm_item *)yylval)->tp.tok.location,
         yytext[0]);
         yytext[0]);
}
}
%%
%%
/*
/*
   Update line number (1-) and character number (1-).  Call this
   Update line number (1-) and character number (1-).  Call this
   before processing the token.  */
   before processing the token.  */
static void
static void
update_lineno_charno (void)
update_lineno_charno (void)
{
{
   /* Update the values we send to caller in case we sometimes don't
   /* Update the values we send to caller in case we sometimes don't
      tell them about all the 'tokens' eg comments etc.  */
      tell them about all the 'tokens' eg comments etc.  */
   int yyl;
   int yyl;
   LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
   LINEMAP_POSITION_FOR_COLUMN (input_location, &line_table,
                                next_tree_charno);
                                next_tree_charno);
   ((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
   ((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
   ((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
   ((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
   for ( yyl = 0; yyl < yyleng; ++yyl )
   for ( yyl = 0; yyl < yyleng; ++yyl )
      {
      {
         if ( yytext[yyl] == '\n' )
         if ( yytext[yyl] == '\n' )
            {
            {
#ifdef USE_MAPPED_LOCATION
#ifdef USE_MAPPED_LOCATION
              source_location s = linemap_line_start (&line_table, ++lineno,
              source_location s = linemap_line_start (&line_table, ++lineno,
                                                      80);
                                                      80);
              input_location = s;
              input_location = s;
#else
#else
              input_line = ++lineno;
              input_line = ++lineno;
#endif
#endif
              next_tree_charno = 1;
              next_tree_charno = 1;
            }
            }
         else
         else
           next_tree_charno++;
           next_tree_charno++;
      }
      }
}
}
/* Fill in the fields of yylval - the value of the token.  The token
/* Fill in the fields of yylval - the value of the token.  The token
   type is A.  */
   type is A.  */
void
void
update_yylval (int a)
update_yylval (int a)
{
{
  struct prod_token_parm_item * tok;
  struct prod_token_parm_item * tok;
  tok = yylval;
  tok = yylval;
  tok->category = token_category;
  tok->category = token_category;
  tok->type = a;
  tok->type = a;
  tok->tp.tok.length = yyleng;
  tok->tp.tok.length = yyleng;
  /* Have to copy yytext as it is just a ptr into the buffer at the
  /* Have to copy yytext as it is just a ptr into the buffer at the
     moment.  */
     moment.  */
  tok->tp.tok.chars = (unsigned char*) get_string (yytext, yyleng);
  tok->tp.tok.chars = (unsigned char*) get_string (yytext, yyleng);
}
}
/* Trace the value LEXRET and the position and token details being
/* Trace the value LEXRET and the position and token details being
   returned by the lexical analyser.  */
   returned by the lexical analyser.  */
static void
static void
dump_lex_value (int lexret)
dump_lex_value (int lexret)
{
{
  int ix;
  int ix;
  fprintf (stderr, " %d l:%d c:%d ln:%d text=", lexret,
  fprintf (stderr, " %d l:%d c:%d ln:%d text=", lexret,
           LOCATION_LINE (((struct prod_token_parm_item *)
           LOCATION_LINE (((struct prod_token_parm_item *)
                          yylval)->tp.tok.location),
                          yylval)->tp.tok.location),
           ((struct prod_token_parm_item *) yylval)->tp.tok.charno,
           ((struct prod_token_parm_item *) yylval)->tp.tok.charno,
           ((struct prod_token_parm_item *) yylval)->tp.tok.length);
           ((struct prod_token_parm_item *) yylval)->tp.tok.length);
  for (ix = 0; ix < yyleng; ix++)
  for (ix = 0; ix < yyleng; ix++)
    {
    {
      fprintf (stderr, "%c", yytext[ix]);
      fprintf (stderr, "%c", yytext[ix]);
    }
    }
  fprintf (stderr, " in hex:");
  fprintf (stderr, " in hex:");
  for (ix = 0; ix < yyleng; ix++)
  for (ix = 0; ix < yyleng; ix++)
    {
    {
      fprintf (stderr, " %2.2x", yytext[ix]);
      fprintf (stderr, " %2.2x", yytext[ix]);
    }
    }
  fprintf (stderr, "\n");
  fprintf (stderr, "\n");
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.