diff options
Diffstat (limited to 'colm')
-rw-r--r-- | colm/conscolm.cc | 2 | ||||
-rw-r--r-- | colm/consinit.cc | 2 | ||||
-rw-r--r-- | colm/load.cc | 111 | ||||
-rw-r--r-- | colm/load.h | 180 | ||||
-rw-r--r-- | colm/main.cc | 7 | ||||
-rw-r--r-- | colm/parser.h | 4 |
6 files changed, 123 insertions, 183 deletions
diff --git a/colm/conscolm.cc b/colm/conscolm.cc index 8c5a330c..e359af88 100644 --- a/colm/conscolm.cc +++ b/colm/conscolm.cc @@ -316,6 +316,8 @@ void LoadColm::consExportStmt( StmtList *stmtList ) void LoadColm::go() { + LoadColm::init(); + StmtList *stmtList = new StmtList; const char *argv[2]; diff --git a/colm/consinit.cc b/colm/consinit.cc index 0692acdf..cb76f38b 100644 --- a/colm/consinit.cc +++ b/colm/consinit.cc @@ -768,6 +768,8 @@ void ConsInit::exportTree( StmtList *stmtList ) void ConsInit::go() { + ConsInit::init(); + StmtList *stmtList = new StmtList; /* The token region */ diff --git a/colm/load.cc b/colm/load.cc index 3dc92f27..4492f992 100644 --- a/colm/load.cc +++ b/colm/load.cc @@ -35,6 +35,115 @@ extern RuntimeData main_runtimeData; +struct LoadSource +: + public BaseParser +{ + LoadSource( Compiler *pd, const char *inputFileName ) + : + BaseParser( pd ), + inputFileName( inputFileName ) + {} + + const char *inputFileName; + + void go(); + + ObjectField *walkVarDef( var_def varDef ); + NamespaceQual *walkRegionQual( region_qual regionQual ); + RepeatType walkOptRepeat( opt_repeat OptRepeat ); + TypeRef *walkTypeRef( type_ref typeRef ); + + ReOrItem *walkRegOrChar( reg_or_char regOrChar ); + ReOrBlock *walkRegOrData( reg_or_data regOrData ); + + LexFactor *walkLexFactor( lex_factor &LexFactorTree ); + LexFactorNeg *walkLexFactorNeg( lex_factor_neg &LexFactorNegTree ); + LexFactorRep *walkLexFactorRep( lex_factor_rep &LexFactorRepTree ); + LexFactorAug *walkLexFactorAug( lex_factor_rep &LexFactorRepTree ); + LexTerm *walkLexTerm( lex_term &LexTerm ); + LexExpression *walkLexExpr( lex_expr &LexExpr ); + ExprVect *walkCodeExprList( _repeat_code_expr codeExprList ); + LangExpr *walkCodeExpr( code_expr codeExpr ); + void walkLexRegion( region_def regionDef ); + void walkProdElList( ProdElList *list, prod_el_list ProdElList ); + void walkProdList( LelDefList *lelDefList, prod_list &ProdList ); + void walkCflDef( cfl_def cflDef ); + LangTerm *walkIterCall( iter_call IterCall ); + LangStmt *walkOptionalElse( optional_else optionalElse ); + LangStmt *walkElsifClause( elsif_clause elsifClause ); + LangStmt *walkElsifList( elsif_list elsifList ); + LangStmt *walkStatement( statement Statement ); + LangStmt *walkPrintStmt( print_stmt &PrintStmt ); + LangExpr *walkCodeUnary( code_unary codeUnary ); + LangExpr *walkCodeFactor( code_factor codeFactor ); + LangStmt *walkExprStmt( expr_stmt &ExprStmt ); + QualItemVect *walkQual( qual &Qual ); + LangVarRef *walkVarRef( var_ref varRef ); + void walkRootItem( root_item &rootItem, StmtList *stmtList ); + StmtList *walkRootItemList( _repeat_root_item rootItemList ); + void walkNamespaceDef( namespace_def NamespaceDef ); + StmtList *walkLangStmtList( lang_stmt_list LangStmtList ); + StmtList *walkBlockOrSingle( block_or_single blockOrSingle ); + + void walkLiteralItem( literal_item literalItem ); + void walkLiteralList( literal_list literalList ); + void walkLiteralDef( literal_def literalDef ); + + void walkTokenDef( token_def TokenDef ); + void walkIgnoreDef( ignore_def IgnoreDef ); + void walkContextDef( context_def contextDef ); + void walkContextItem( context_item contextItem ); + void walkContextVarDef( context_var_def contextVarDef ); + CodeBlock *walkOptReduce( opt_reduce optReduce ); + + void walkFieldInit( FieldInitVect *list, field_init fieldInit ); + FieldInitVect *walkOptFieldInit( opt_field_init optFieldInit ); + + ConsItemList *walkLitAccumEl( lit_accum_el litAccumEl ); + ConsItemList *walkLitAccumElList( _repeat_lit_accum_el litAccumElList ); + ConsItemList *walkAccumTopEl( accum_top_el accumTopEl ); + ConsItemList *walkAccumList( accum_list accumList ); + ConsItemList *walkAccumulate( accumulate Accumulate ); + ConsItemList *walkAccumEl( accum_el accumEl ); + ConsItemList *walkAccumElList( _repeat_accum_el accumElList ); + + void walkRlDef( rl_def RlDef ); + + ConsItemList *walkLitConsEl( lit_cons_el litConsEl ); + ConsItemList *walkLitConsElList( _repeat_lit_cons_el litConsElList ); + ConsItemList *walkConsTopEl( cons_top_el consTopEl ); + ConsItemList *walkConsList( cons_list consList ); + ConsItemList *walkConstructor( constructor Constructor ); + ConsItemList *walkConsEl( cons_el consEl ); + ConsItemList *walkConsElList( _repeat_cons_el consElList ); + + LangExpr *walkCodeRelational( code_relational codeRelational ); + LangExpr *walkCodeAdditive( code_additive codeAdditive ); + LangExpr *walkCodeMultiplicitive( code_multiplicitive codeMultiplicitive ); + + ConsItemList *walkLitStringEl( lit_string_el litStringEl ); + ConsItemList *walkLitStringElList( _repeat_lit_string_el litStringElList ); + ConsItemList *walkStringTopEl( string_top_el stringTopEl ); + ConsItemList *walkStringList( string_list stringList ); + ConsItemList *walkString( cstring String ); + ConsItemList *walkStringEl( string_el stringEl ); + ConsItemList *walkStringElList( _repeat_string_el stringElList ); + void walkFunctionDef( function_def functionDef ); + + TypeRef *walkReferenceTypeRef( reference_type_ref ReferenceTypeRef ); + ObjectField *walkParamVarDef( param_var_def ParamVarDef ); + ParameterList *walkParamVarDefList( _repeat_param_var_def ParamVarDefList ); + void walkIterDef( iter_def IterDef ); +}; + + +BaseParser *consLoadSource( Compiler *pd, const char *inputFileName ) +{ + return new LoadSource( pd, inputFileName ); +} + + String unescape( const String &s ) { String out( String::Fresh(), s.length() ); @@ -1258,6 +1367,8 @@ StmtList *LoadSource::walkRootItemList( _repeat_root_item rootItemList ) void LoadSource::go() { + LoadSource::init(); + const char *argv[2]; argv[0] = inputFileName; argv[1] = 0; diff --git a/colm/load.h b/colm/load.h index 35ec3d47..fab559e9 100644 --- a/colm/load.h +++ b/colm/load.h @@ -24,182 +24,4 @@ #include "parsedata.h" #include "parser.h" -struct lex_factor; -struct lex_factor_neg; -struct lex_factor_rep; -struct lex_term; -struct lex_expr; -struct token_list; -struct prod_el_list; -struct prod_list; -struct root_item; -struct region_def; -struct cfl_def; -struct statement; -struct print_stmt; -struct expr_stmt; -struct var_ref; -struct code_expr; -struct _repeat_code_expr; -struct qual; -struct region_qual; -struct opt_repeat; -struct type_ref; -struct root_item; -struct _repeat_root_item; -struct namespace_def; -struct var_def; -struct block_or_single; -struct iter_call; -struct lang_stmt_list; -struct elsif_list; -struct elsif_clause; -struct optional_else; -struct code_factor; -struct reg_or_char; -struct reg_or_data; -struct literal_item; -struct literal_list; -struct literal_def; -struct token_def; -struct ignore_def; -struct context_def; -struct context_item; -struct context_var_def; -struct opt_reduce; -struct field_init; -struct opt_field_init; -struct lit_accum_el; -struct _repeat_lit_accum_el; -struct accum_top_el; -struct accum_list; -struct accumulate; -struct accum_el; -struct _repeat_accum_el; -struct rl_def; -struct lit_cons_el; -struct _repeat_lit_cons_el; -struct cons_top_el; -struct cons_list; -struct constructor; -struct cons_el; -struct _repeat_cons_el; -struct code_relational; -struct code_additive; -struct lit_string_el; -struct _repeat_lit_string_el; -struct string_top_el; -struct string_list; -struct cstring; -struct string_el; -struct _repeat_string_el; -struct function_def; -struct reference_type_ref; -struct param_var_def; -struct _repeat_param_var_def; -struct iter_def; -struct code_unary; -struct code_multiplicitive; - -struct LoadSource -: - public BaseParser -{ - LoadSource( Compiler *pd, const char *inputFileName ) - : - BaseParser( pd ), - inputFileName( inputFileName ) - {} - - const char *inputFileName; - - void go(); - - ObjectField *walkVarDef( var_def varDef ); - NamespaceQual *walkRegionQual( region_qual regionQual ); - RepeatType walkOptRepeat( opt_repeat OptRepeat ); - TypeRef *walkTypeRef( type_ref typeRef ); - - ReOrItem *walkRegOrChar( reg_or_char regOrChar ); - ReOrBlock *walkRegOrData( reg_or_data regOrData ); - - LexFactor *walkLexFactor( lex_factor &LexFactorTree ); - LexFactorNeg *walkLexFactorNeg( lex_factor_neg &LexFactorNegTree ); - LexFactorRep *walkLexFactorRep( lex_factor_rep &LexFactorRepTree ); - LexFactorAug *walkLexFactorAug( lex_factor_rep &LexFactorRepTree ); - LexTerm *walkLexTerm( lex_term &LexTerm ); - LexExpression *walkLexExpr( lex_expr &LexExpr ); - ExprVect *walkCodeExprList( _repeat_code_expr codeExprList ); - LangExpr *walkCodeExpr( code_expr codeExpr ); - void walkTokenList( token_list &TokenList ); - void walkLexRegion( region_def regionDef ); - void walkProdElList( ProdElList *list, prod_el_list ProdElList ); - void walkProdList( LelDefList *lelDefList, prod_list &ProdList ); - void walkCflDef( cfl_def cflDef ); - LangTerm *walkIterCall( iter_call IterCall ); - LangStmt *walkOptionalElse( optional_else optionalElse ); - LangStmt *walkElsifClause( elsif_clause elsifClause ); - LangStmt *walkElsifList( elsif_list elsifList ); - LangStmt *walkStatement( statement Statement ); - LangStmt *walkPrintStmt( print_stmt &PrintStmt ); - LangExpr *walkCodeUnary( code_unary codeUnary ); - LangExpr *walkCodeFactor( code_factor codeFactor ); - LangStmt *walkExprStmt( expr_stmt &ExprStmt ); - QualItemVect *walkQual( qual &Qual ); - LangVarRef *walkVarRef( var_ref varRef ); - void walkRootItem( root_item &rootItem, StmtList *stmtList ); - StmtList *walkRootItemList( _repeat_root_item rootItemList ); - void walkNamespaceDef( namespace_def NamespaceDef ); - StmtList *walkLangStmtList( lang_stmt_list LangStmtList ); - StmtList *walkBlockOrSingle( block_or_single blockOrSingle ); - - void walkLiteralItem( literal_item literalItem ); - void walkLiteralList( literal_list literalList ); - void walkLiteralDef( literal_def literalDef ); - - void walkTokenDef( token_def TokenDef ); - void walkIgnoreDef( ignore_def IgnoreDef ); - void walkContextDef( context_def contextDef ); - void walkContextItem( context_item contextItem ); - void walkContextVarDef( context_var_def contextVarDef ); - CodeBlock *walkOptReduce( opt_reduce optReduce ); - - void walkFieldInit( FieldInitVect *list, field_init fieldInit ); - FieldInitVect *walkOptFieldInit( opt_field_init optFieldInit ); - - ConsItemList *walkLitAccumEl( lit_accum_el litAccumEl ); - ConsItemList *walkLitAccumElList( _repeat_lit_accum_el litAccumElList ); - ConsItemList *walkAccumTopEl( accum_top_el accumTopEl ); - ConsItemList *walkAccumList( accum_list accumList ); - ConsItemList *walkAccumulate( accumulate Accumulate ); - ConsItemList *walkAccumEl( accum_el accumEl ); - ConsItemList *walkAccumElList( _repeat_accum_el accumElList ); - - void walkRlDef( rl_def RlDef ); - - ConsItemList *walkLitConsEl( lit_cons_el litConsEl ); - ConsItemList *walkLitConsElList( _repeat_lit_cons_el litConsElList ); - ConsItemList *walkConsTopEl( cons_top_el consTopEl ); - ConsItemList *walkConsList( cons_list consList ); - ConsItemList *walkConstructor( constructor Constructor ); - ConsItemList *walkConsEl( cons_el consEl ); - ConsItemList *walkConsElList( _repeat_cons_el consElList ); - - LangExpr *walkCodeRelational( code_relational codeRelational ); - LangExpr *walkCodeAdditive( code_additive codeAdditive ); - LangExpr *walkCodeMultiplicitive( code_multiplicitive codeMultiplicitive ); - - ConsItemList *walkLitStringEl( lit_string_el litStringEl ); - ConsItemList *walkLitStringElList( _repeat_lit_string_el litStringElList ); - ConsItemList *walkStringTopEl( string_top_el stringTopEl ); - ConsItemList *walkStringList( string_list stringList ); - ConsItemList *walkString( cstring String ); - ConsItemList *walkStringEl( string_el stringEl ); - ConsItemList *walkStringElList( _repeat_string_el stringElList ); - void walkFunctionDef( function_def functionDef ); - - TypeRef *walkReferenceTypeRef( reference_type_ref ReferenceTypeRef ); - ObjectField *walkParamVarDef( param_var_def ParamVarDef ); - ParameterList *walkParamVarDefList( _repeat_param_var_def ParamVarDefList ); - void walkIterDef( iter_def IterDef ); -}; +BaseParser *consLoadSource( Compiler *pd, const char *inputFileName ); diff --git a/colm/main.cc b/colm/main.cc index 1acc963e..0f568429 100644 --- a/colm/main.cc +++ b/colm/main.cc @@ -575,14 +575,13 @@ int main(int argc, const char **argv) Compiler *pd = new Compiler; #if defined(CONS_INIT) - ConsInit *parser = new ConsInit( pd ); + BaseParser *parser = new ConsInit( pd ); #elif defined(LOAD_COLM) - LoadColm *parser = new LoadColm( pd, inputFileName ); + BaseParser *parser = new LoadColm( pd, inputFileName ); #else - LoadSource *parser = new LoadSource( pd, inputFileName ); + BaseParser *parser = consLoadSource( pd, inputFileName ); #endif - parser->init(); parser->go(); /* Parsing complete, check for errors.. */ diff --git a/colm/parser.h b/colm/parser.h index 41f83428..0ac8d612 100644 --- a/colm/parser.h +++ b/colm/parser.h @@ -35,6 +35,8 @@ struct BaseParser : pd(pd), enterRl(false) {} + virtual ~BaseParser() {} + Compiler *pd; RegionSetVect regionStack; @@ -133,6 +135,8 @@ struct BaseParser void pushScope(); void popScope(); + + virtual void go() = 0; }; #endif |