help-bison
[Top][All Lists]
Advanced

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

help with parser syntax


From: cwcaceres
Subject: help with parser syntax
Date: Mon, 6 Aug 2007 04:43:29 -0700 (PDT)

Hi, I am trying to make a very simple parser. Here's what I have so far that
works:
parser.y
%{
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "commandlist.h"
using namespace std;
extern int yylex();

extern "C"
{
        int yywrap()
        {
                return 1;
        } 
        void yyerror(const char *str)
        {
                fprintf(stderr,"error: %s\n",str);
        }
        int yyparse(void);
}
%}
%token PROGRAM PLUS NUMBER MODULE TALK COLON
%%
programs: /*empty*/
        |programs program
        ;

program:
        program_set
        ;

program_set:
        PROGRAM statements
        ;
statements:
        | statements statement
        ;

statement:
        NUMBER PLUS NUMBER 
        {
                Commandlist comlist;
                comlist.addCommand("plus");
                cout << comlist.queryCommandlist();
                system("pause");

        }
        |
        MODULE COLON TALK
        {
                Commandlist comlist;
                comlist.addCommand("talk");
                cout << comlist.queryCommandlist();
                system("pause");
        }
        ;

%%

For each command, I had to make a new commandlist. How do I do it so that I
make Commandlist comlist; only once, at the start of the program?





-- 
View this message in context: 
http://www.nabble.com/help-with-parser-syntax-tf4223626.html#a12014778
Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.





reply via email to

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