Skip to content

Commit

Permalink
xorp: Automatically generate lex and yacc files
Browse files Browse the repository at this point in the history
In xorp/site_scons/config/allconfig.py added checks if 'flex' and 'bison' are installed.
If they aren't instructs user how to install them (instructions are for Ubuntu and Fedora).

Change xorp/rtrmgr/SConscript to automatically generate yacc and lex files with bison and flex.
In CPPPATH added env['xorp_sorcedir'] so generated files could include necessary files.
Also did minor changes in .yy and .ll files, so they would compile.

Unfortunately Eclipse striped whitespaces from changed files, so they are meshed up with the changed code.

Signed-off-by: Igor Maravic <igorm@etf.rs>
  • Loading branch information
Igor Maravic authored and greearb committed Mar 13, 2012
1 parent 31b0f5e commit e7a9b50
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 114 deletions.
79 changes: 56 additions & 23 deletions xorp/rtrmgr/SConscript
Expand Up @@ -30,9 +30,10 @@ SConscript(dirs = subdirs, exports='env')
env = env.Clone()

env.AppendUnique(CPPPATH = [
'#',
'$BUILDDIR',
])
'.',
'$BUILDDIR',
env['xorp_sourcedir'], #this is needed for lex and yacc generated files
])

env.PrependUnique(LIBPATH = [
'$BUILDDIR/libxorp',
Expand All @@ -50,20 +51,52 @@ env.PrependUnique(LIBPATH = [

libxorp_rtrmgr_env = env.Clone()

# FIXME generate lex/yacc from source
# shorthand this plz
# see http://209.85.229.132/search?q=cache:3j0AsRORc6MJ:https://gforge.inria.fr/plugins/scmsvn/viewcvs.php/scons_util/trunk/src/platform.py%3Frev%3D18%26root%3Dopenalea%26view%3Dmarkup+scons+lexflags+append&cd=2&hl=en&ct=clnk&gl=uk&client=firefox-a
# ... needs toolchain check for flex 2.5.4 or poss more recent.
# known to work with freebsd base system flex.
#tplt_env = env.Clone()
#tplt_env.AppendUnique(LEXFLAGS='-Ptplt')
#tplt_env.CXXFile(source='template.ll', target='lex.tplt.cc')
#boot_env = env.Clone()
#boot_env.AppendUnique(LEXFLAGS='-Pboot')
#boot_env.CXXFile(source='boot.ll', target='lex.boot.cc')
#opcmd_env = env.Clone()
#opcmd_env.AppendUnique(LEXFLAGS='-Popcmd')
#opcmd_env.CXXFile(source='op_commands.ll', target='lex.opcmd.cc')
# Automatically generate flex and yacc files

#Create yacc files
yacc_env = env.Clone()
yacc_env.Replace(YACCHXXFILESUFFIX='.hh')
yacc_env.AppendUnique(YACCFLAGS='-d')


tplt_env_y = yacc_env.Clone()
tplt_env_y.AppendUnique(YACCFLAGS='-ptplt')

tplt_yacc = tplt_env_y.CXXFile(target='y.tplt_tab.cc',
source='template.yy')

boot_env_y = yacc_env.Clone()
boot_env_y.AppendUnique(YACCFLAGS='-pboot')

boot_yacc = boot_env_y.CXXFile(target='y.boot_tab.cc',
source='boot.yy')

opcmd_env_y = yacc_env.Clone()
opcmd_env_y.AppendUnique(YACCFLAGS='-popcmd')

opcmd_yacc = opcmd_env_y.CXXFile(target='y.opcmd_tab.cc',
source='op_commands.yy')

#create lex files
lex_env = env.Clone()

tplt_env_l = lex_env.Clone()
tplt_env_l.AppendUnique(LEXFLAGS='-Ptplt')

tplt_lex = tplt_env_l.CXXFile(target='lex.tplt.cc',
source='template.ll')

boot_env_l = lex_env.Clone()
boot_env_l.AppendUnique(LEXFLAGS='-Pboot')

boot_lex = boot_env_l.CXXFile(target='lex.boot.cc',
source='boot.ll')

opcmd_env_l = lex_env.Clone()
opcmd_env_l.AppendUnique(LEXFLAGS='-Popcmd')

opcmd_lex = opcmd_env_l.CXXFile(target='lex.opcmd.cc',
source='op_commands.ll')

libxorp_rtrmgr_srcs = [
'command_tree.cc',
Expand All @@ -72,9 +105,12 @@ libxorp_rtrmgr_srcs = [
'config_operators.cc',
'generic_module_manager.cc',
'glob_win32.c',
'lex.boot.cc',
'lex.opcmd.cc',
'lex.tplt.cc',
tplt_lex[0],
opcmd_lex[0],
boot_lex[0],
opcmd_yacc[0],
boot_yacc[0],
tplt_yacc[0],
'master_conf_tree.cc',
'master_conf_tree_node.cc',
'master_template_tree.cc',
Expand All @@ -95,9 +131,6 @@ libxorp_rtrmgr_srcs = [
'unexpanded_xrl.cc',
'userdb.cc',
'xorp_client.cc',
'y.boot_tab.cc',
'y.opcmd_tab.cc',
'y.tplt_tab.cc',
]

# Runtime XRL syntax validation for developers.
Expand Down
6 changes: 4 additions & 2 deletions xorp/rtrmgr/boot.ll
Expand Up @@ -9,16 +9,18 @@
#undef __unused
#endif

#define YYSTYPE char*

#include "libxorp/xorp.h"
#include "y.boot_tab.h"
#include "y.boot_tab.hh"

#ifdef __xorp_unused
#define __unused __xorp_unused
#undef __xorp_unused
#endif

%}
int boot_linenum = 1;
extern char* bootlval;
string parsebuf;
int arith_nesting;
bool arith_op_allowed;
Expand Down
64 changes: 47 additions & 17 deletions xorp/rtrmgr/boot.yy
Expand Up @@ -18,6 +18,49 @@
/* XXX: sigh - -p flag to yacc should do this for us */
#define yystacksize bootstacksize
#define yysslim bootsslim

/**
* Forward declarations
*/
extern void boot_scan_string(const char *configuration);
extern int boot_linenum;
extern "C" int bootparse();
extern int bootlex();

void booterror(const char *s) throw (ParseError);

static ConfigTree *config_tree = NULL;
static string boot_filename;
static string lastsymbol;
static string node_id;

/**
* Function declarations
*/
static void
extend_path(char* segment, int type, const string& node_id_str);

static void
push_path();

static void
pop_path();

static void
terminal(char* value, int type, ConfigOperator op);

void
booterror(const char *s) throw (ParseError);

int
init_bootfile_parser(const char *configuration,
const char *filename,
ConfigTree *ct);

void
parse_bootfile() throw (ParseError);

ConfigOperator boot_lookup_operator(const char* s);
%}

%token UPLEVEL
Expand Down Expand Up @@ -190,20 +233,7 @@ syntax_error: SYNTAX_ERROR {

%%

extern void boot_scan_string(const char *configuration);
extern int boot_linenum;
extern "C" int bootparse();
extern int bootlex();

void booterror(const char *s) throw (ParseError);

static ConfigTree *config_tree = NULL;
static string boot_filename;
static string lastsymbol;
static string node_id;


static void
void
extend_path(char* segment, int type, const string& node_id_str)
{
lastsymbol = segment;
Expand All @@ -221,19 +251,19 @@ extend_path(char* segment, int type, const string& node_id_str)
}
}

static void
void
push_path()
{
config_tree->push_path();
}

static void
void
pop_path()
{
config_tree->pop_path();
}

static void
void
terminal(char* value, int type, ConfigOperator op)
{
push_path();
Expand Down
8 changes: 4 additions & 4 deletions xorp/rtrmgr/op_commands.cc
Expand Up @@ -7,13 +7,13 @@
// 1991 as published by the Free Software Foundation. Redistribution
// and/or modification of this program under the terms of any other
// version of the GNU General Public License is not permitted.
//
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
// see the GNU General Public License, Version 2, a copy of which can be
// found in the XORP LICENSE.gpl file.
//
//
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

Expand Down Expand Up @@ -48,7 +48,7 @@
#include "slave_conf_tree.hh"
#include "template_tree.hh"
#include "slave_module_manager.hh"
#include "y.opcmd_tab.h"
#include "y.opcmd_tab.hh"


#ifdef HOST_OS_WINDOWS
Expand Down Expand Up @@ -358,7 +358,7 @@ OpCommand::execute(EventLoop& eventloop, const list<string>& command_line,
_command_executable_filename,
resolved_command_argument_list,
print_cb, done_cb);

return opinst;
}

Expand Down
4 changes: 2 additions & 2 deletions xorp/rtrmgr/op_commands.ll
Expand Up @@ -9,17 +9,17 @@
#undef __unused
#endif

#define YYSTYPE char*
#include "libxorp/xorp.h"
#include <string.h>
#include "y.opcmd_tab.h"
#include "y.opcmd_tab.hh"

#ifdef __xorp_unused
#define __unused __xorp_unused
#undef __xorp_unused
#endif
%}
int opcmd_linenum = 1;
extern char* opcmdlval;
string opcmd_parsebuf;
%option noyywrap
%option nounput
Expand Down

0 comments on commit e7a9b50

Please sign in to comment.