help-bison
[Top][All Lists]
Advanced

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

compile, but no output


From: matthew.ouyang
Subject: compile, but no output
Date: Mon, 27 Sep 2004 19:44:49 -0400

Hello, 
I am trying to compile a file in bison using the following command line.

bison -dvty soop.y

What I am hoping to get is a generated parser file along with definitions for 
my token types for use in flex scanner.  However, all I get is a y.output file 
which spells out all my states and their transitions.

If anyone can help me on this at their earliest convenience, that would be 
appreciated.  Thanks in advance.

Matthew 





///////soop.y

%{
        #include "soop.h"
%}

/* Tokens for the SOOP language */
/* SOOP reserved words */
%token T_Void
%token T_Int
%token T_Double
%token T_Bool
%token T_Class
%token T_While
%token T_If
%token T_Else
%token T_Return
%token T_Public
%token T_Private
%token T_New
%token T_NewArray
%token T_Print
%token T_ReadInteger
%token T_Null
/*
%token T_For
%token T_Switch
%token T_Case
%token T_Default
%token T_Break
*/
%token T_While
/* Constants */
%token T_IntConstant
%token T_BoolConstant
%token T_DoubleConstant
%token T_StringConstant
/* Logical Operators */
%token T_And
%token T_Or
%token T_Equal
%token T_NotEqual
%token T_GreaterEqual
%token T_LessEqual 
/*
%token T_Increment
%token T_Decrement
*/
/* Generic token for arbitrary alphanumeric strings */
%token T_Identifier

/* Union */
%union {
        int integerConstant;
        bool boolConstant;
        double doubleConstant;
}

/* Precedence */
%right '='
%nonassoc T_Or
%nonassoc T_And 
%nonassoc T_Equal T_NotEqual
%nonassoc '<' T_GreaterEqual '>' T_LessEqual
%left '+' '-'
%left '*' '/' '%'
%right UNARY_OP
%left '[' ']' '.'
%left If_Then
%nonassoc T_Else

/* Start Production */
%start Program

%%

Program :
DeclarationList
;

DeclarationList :
DeclarationList Declaration 
|
;

Declaration     :
ClassDefinition
|
ClassDeclaration
|
FunctionDefinition
|
FunctionDeclaration
|
VariableDeclaration
;

VariableDeclaration     :
Variable ';'
;
        
Variable :
Type T_Identifier ArrayModifiers
;

ArrayModifiers : 
'[' T_IntConstant ']' ArrayModifiers
|
;
        
Type :
T_Int
|
T_Void
|
T_Bool
|
T_Double
|
T_Class T_Identifier
;

ClassDeclaration :
T_Class T_Identifier ';'
;

ClassDefinition :
T_Class T_Identifier OptionalInheritance '{'  ClassDefinitionList '}'
;

OptionalInheritance : 
':' T_Identifier
|
;

ClassDefinitionList     :
ClassDefinitionList OptionalClassAccessLevel ClassField 
|
;

OptionalClassAccessLevel :
T_Public 
|
T_Private
|
;

ClassField :
InstanceVariableDeclaration
|
FunctionDefinition
|
FunctionDeclaration
;

InstanceVariableDeclaration :
Variable ';'
;

FunctionDeclaration     :
Type T_Identifier '(' ParameterListOrVoid ')' ';'
;

ParameterListOrVoid     :
T_Void 
|
ParameterList
;

ParameterList :
ParameterList ',' Parameter 
|
Parameter
;

Parameter       :
Variable
;

FunctionDefinition :
Type T_Identifier '(' ParameterListOrVoid ')' CompoundStatement 
;

CompoundStatement       :
'{' OptionalVariableDeclarationList OptionalStatementList '}' 
;

OptionalVariableDeclarationList :
VariableDeclarationList
|
;

VariableDeclarationList :
VariableDeclarationList VariableDeclaration 
|
VariableDeclaration
;

OptionalStatementList :
StatementList
|
;

StatementList :
StatementList Statement 
|
Statement
;

Statement       :
SimpleStatement ';'
|
IfStatement
|
WhileStatement
|
ReturnStatement ';'
|
CompoundStatement
|
PrintStatement ';'
;

SimpleStatement :
Designator '=' Expression
|
Var '=' Expression
|
Expression
;

Designator :
Expression '.' T_Identifier
|
Expression '[' Expression ']'
;

Call :
T_Identifier '(' ArgumentList ')' 
|
Expression '.' T_Identifier '(' ArgumentList ')' 
;

Expression :
Designator
|
Call
|
Var
|
Constant
|
Expression '+' Expression
|
Expression '-' Expression
|
Expression '/' Expression
|
Expression '*' Expression
|
Expression '%' Expression
|
Expression T_Equal Expression
|
Expression T_NotEqual Expression
|
Expression '<' Expression
|
Expression '>' Expression
|
Expression T_LessEqual Expression
|
Expression T_GreaterEqual Expression
|
Expression T_And Expression
|
Expression T_Or Expression
|
'(' Expression ')'
|
'-' Expression %prec UNARY_OP
|
'!' Expression %prec UNARY_OP 
|
T_ReadInteger '(' ')'
|
T_New '(' T_Identifier ')'
|
T_NewArray '(' Expression ')' 
;
        
Var :
T_Identifier
;

Constant :
T_IntConstant
|
T_BoolConstant
|
T_DoubleConstant
|
T_StringConstant
|
T_Null
;
                                
ArgumentList :
ExpressionList
|
;

ExpressionList : 
ExpressionList ',' Expression 
|
Expression
;

BooleanExpression       :
Expression
;

WhileStatement :
T_While '(' BooleanExpression ')' Statement
;

IfStatement :
T_If '(' BooleanExpression ')' Statement %prec If_Then
|
T_If '(' BooleanExpression ')' Statement T_Else Statement
;

ReturnStatement :
T_Return 
|
T_Return Expression
;

PrintStatement :
T_Print '(' ExpressionList ')'
;

%%

main() {
}





reply via email to

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