From 26dd574284aecedaada76026817bd1d66117bcc6 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Mon, 20 May 2013 12:25:38 -0400 Subject: some more use of production names, lowercased enum name --- colm/colm.lm | 54 +++++++++++----------- colm/exports.cc | 6 +-- colm/loadcolm.cc | 134 ++++++++++++++++++++++++++++++------------------------- 3 files changed, 102 insertions(+), 92 deletions(-) diff --git a/colm/colm.lm b/colm/colm.lm index c974b3d4..59e77161 100644 --- a/colm/colm.lm +++ b/colm/colm.lm @@ -183,23 +183,23 @@ def start [RootItemList: root_item*] def root_item - [RlDef: rl_def] :RlProd commit -| [LiteralDef: literal_def] :LiteralProd commit -| [TokenDef: token_def] :TokenProd commit -| [IgnoreDef: ignore_def] :IgnoreProd commit -| [CflDef: cfl_def] :CflProd commit -| [RegionDef: region_def] :RegionProd commit -| [ContextDef: context_def] :ContextProd commit -| [NamespaceDef: namespace_def] :NamespaceProd commit -| [FunctionDef: function_def] :FunctionProd commit -| [IterDef: iter_def] :IterProd commit -| [Statement: statement] :StatementProd commit -| [GlobalDef: global_def] :GlobalProd commit -| [ExportDef: export_def] :ExportProd commit -| [PreEofDef: pre_eof_def] :PreEofProd commit -| [PrecedenceDef: precedence_def] :PrecedenceProd commit -| [AliasDef: alias_def] :AliasProd commit -| [Include: include] :IncludeProd commit + [RlDef: rl_def] :Rl commit +| [LiteralDef: literal_def] :Literal commit +| [TokenDef: token_def] :Token commit +| [IgnoreDef: ignore_def] :Ignore commit +| [CflDef: cfl_def] :Cfl commit +| [RegionDef: region_def] :Region commit +| [ContextDef: context_def] :Context commit +| [NamespaceDef: namespace_def] :Namespace commit +| [FunctionDef: function_def] :Function commit +| [IterDef: iter_def] :Iter commit +| [Statement: statement] :Statement commit +| [GlobalDef: global_def] :Global commit +| [ExportDef: export_def] :Export commit +| [PreEofDef: pre_eof_def] :PreEof commit +| [PrecedenceDef: precedence_def] :Precedence commit +| [AliasDef: alias_def] :Alias commit +| [Include: include] :Include commit def include [INCLUDE File: lit] @@ -652,22 +652,22 @@ def qual # def lex_expr - [Expr: lex_expr Bar: LEX_BAR Term: lex_term] -| [Expr: lex_expr Amp: LEX_AMP Term: lex_term] -| [Expr: lex_expr Dash: LEX_DASH Term: lex_term] -| [Expr: lex_expr DashDash: LEX_DASHDASH Term: lex_term] -| [Term: lex_term] + [Expr: lex_expr Bar: LEX_BAR Term: lex_term] :Bar +| [Expr: lex_expr Amp: LEX_AMP Term: lex_term] :Amp +| [Expr: lex_expr Dash: LEX_DASH Term: lex_term] :Dash +| [Expr: lex_expr DashDash: LEX_DASHDASH Term: lex_term] :DashDash +| [Term: lex_term] :Base def opt_lex_dot [LEX_DOT] | [] def lex_term - [Term: lex_term OptDot: opt_lex_dot FactorRep: lex_factor_rep] -| [Term: lex_term ColonGt: LEX_COLON_GT FactorRep: lex_factor_rep] -| [Term: lex_term ColonGtGt: LEX_COLON_GTGT FactorRep: lex_factor_rep] -| [Term: lex_term LtColon: LEX_LT_COLON FactorRep: lex_factor_rep] -| [FactorRep: lex_factor_rep] + [Term: lex_term OptDot: opt_lex_dot FactorRep: lex_factor_rep] :Dot +| [Term: lex_term ColonGt: LEX_COLON_GT FactorRep: lex_factor_rep] :ColonGt +| [Term: lex_term ColonGtGt: LEX_COLON_GTGT FactorRep: lex_factor_rep] :ColonGtGt +| [Term: lex_term LtColon: LEX_LT_COLON FactorRep: lex_factor_rep] :LtColon +| [FactorRep: lex_factor_rep] :Base def lex_factor_rep [FactorRep: lex_factor_rep Star: LEX_STAR] diff --git a/colm/exports.cc b/colm/exports.cc index 07cb5b03..aeeea62a 100644 --- a/colm/exports.cc +++ b/colm/exports.cc @@ -147,14 +147,14 @@ void Compiler::generateExports() } if ( prodNames ) { - out << " enum ProdName {\n"; + out << " enum prod_name {\n"; for ( LelDefList::Iter prod = lel->defList; prod.lte(); prod++ ) { if ( prod->name.length() > 0 ) out << "\t\t_" << prod->name << " = " << prod->prodNum << ",\n"; } out << " };\n"; - out << " enum ProdName prodName() " << - "{ return (enum ProdName)__tree->prodNum; }\n"; + out << " enum prod_name prodName() " << + "{ return (enum prod_name)__tree->prodNum; }\n"; } diff --git a/colm/loadcolm.cc b/colm/loadcolm.cc index 0d3be57d..58fe2b3b 100644 --- a/colm/loadcolm.cc +++ b/colm/loadcolm.cc @@ -289,31 +289,6 @@ struct LoadColm return retList; } - LexExpression *walkLexExpr( lex_expr LexExprTree ) - { - if ( LexExprTree.Expr() != 0 ) { - LexExpression *leftExpr = walkLexExpr( LexExprTree.Expr() ); - LexTerm *term = walkLexTerm( LexExprTree.Term() ); - - LexExpression *expr = 0; - if ( LexExprTree.Bar() != 0 ) - expr = LexExpression::cons( leftExpr, term, LexExpression::OrType ); - else if ( LexExprTree.Amp() != 0 ) - expr = LexExpression::cons( leftExpr, term, LexExpression::IntersectType ); - else if ( LexExprTree.Dash() != 0 ) - expr = LexExpression::cons( leftExpr, term, LexExpression::SubtractType ); - else if ( LexExprTree.DashDash() != 0 ) - expr = LexExpression::cons( leftExpr, term, LexExpression::StrongSubtractType ); - return expr; - } - else { - lex_term LexTermTree = LexExprTree.Term(); - LexTerm *term = walkLexTerm( LexTermTree ); - LexExpression *expr = LexExpression::cons( term ); - return expr; - } - } - void walkTokenDef( token_def TokenDef ) { String name = TokenDef.Id().text().c_str(); @@ -919,34 +894,69 @@ struct LoadColm return factorRep; } - LexTerm *walkLexTerm( lex_term LexTermTree ) + LexTerm *walkLexTerm( lex_term lexTerm ) { LexTerm *term = 0; - if ( LexTermTree.Term() != 0 ) { - LexTerm *leftTerm = walkLexTerm( LexTermTree.Term() ); - LexFactorAug *factorAug = walkLexFactorAug( LexTermTree.FactorRep() ); + lex_term::prod_name pn = lexTerm.prodName(); - if ( LexTermTree.OptDot() != 0 ) { - term = LexTerm::cons( leftTerm, factorAug, LexTerm::ConcatType ); - } - else if ( LexTermTree.ColonGt() != 0 ) { - term = LexTerm::cons( leftTerm, factorAug, LexTerm::RightStartType ); - } - else if ( LexTermTree.ColonGtGt() != 0 ) { - term = LexTerm::cons( leftTerm, factorAug, LexTerm::RightFinishType ); - } - else if ( LexTermTree.LtColon() != 0 ) { - term = LexTerm::cons( leftTerm, factorAug, LexTerm::LeftType ); - } - } - else { - lex_factor_rep LexFactorRepTree = LexTermTree.FactorRep(); - LexFactorAug *factorAug = walkLexFactorAug( LexFactorRepTree ); + LexTerm *leftTerm = 0; + if ( pn != lex_term::_Base ) + leftTerm = walkLexTerm( lexTerm.Term() ); + + LexFactorAug *factorAug = walkLexFactorAug( lexTerm.FactorRep() ); + + switch ( pn ) { + case lex_term::_Dot: + term = LexTerm::cons( leftTerm, factorAug, LexTerm::ConcatType ); + break; + case lex_term::_ColonGt: + term = LexTerm::cons( leftTerm, factorAug, LexTerm::RightStartType ); + break; + case lex_term::_ColonGtGt: + term = LexTerm::cons( leftTerm, factorAug, LexTerm::RightFinishType ); + break; + case lex_term::_LtColon: + term = LexTerm::cons( leftTerm, factorAug, LexTerm::LeftType ); + break; + default: term = LexTerm::cons( factorAug ); + break; } + return term; } + LexExpression *walkLexExpr( lex_expr lexExpr ) + { + LexExpression *expr = 0; + lex_expr::prod_name pn = lexExpr.prodName(); + + LexExpression *leftExpr = 0; + if ( pn != lex_expr::_Base ) + leftExpr = walkLexExpr( lexExpr.Expr() ); + + LexTerm *term = walkLexTerm( lexExpr.Term() ); + + switch ( pn ) { + case lex_expr::_Bar: + expr = LexExpression::cons( leftExpr, term, LexExpression::OrType ); + break; + case lex_expr::_Amp: + expr = LexExpression::cons( leftExpr, term, LexExpression::IntersectType ); + break; + case lex_expr::_Dash: + expr = LexExpression::cons( leftExpr, term, LexExpression::SubtractType ); + break; + case lex_expr::_DashDash: + expr = LexExpression::cons( leftExpr, term, LexExpression::StrongSubtractType ); + break; + case lex_expr::_Base: + expr = LexExpression::cons( term ); + } + return expr; + } + + void walkRlDef( rl_def rlDef ) { String id = rlDef.Id().text().c_str(); @@ -1790,63 +1800,63 @@ struct LoadColm void walkRootItem( root_item &rootItem, StmtList *stmtList ) { switch ( rootItem.prodName() ) { - case root_item::_RlProd: + case root_item::_Rl: walkRlDef( rootItem.RlDef() ); break; - case root_item::_TokenProd: + case root_item::_Token: walkTokenDef( rootItem.TokenDef() ); break; - case root_item::_IgnoreProd: + case root_item::_Ignore: walkIgnoreDef( rootItem.IgnoreDef() ); break; - case root_item::_LiteralProd: + case root_item::_Literal: walkLiteralDef( rootItem.LiteralDef() ); break; - case root_item::_CflProd: + case root_item::_Cfl: walkCflDef( rootItem.CflDef() ); break; - case root_item::_RegionProd: + case root_item::_Region: walkLexRegion( rootItem.RegionDef() ); break; - case root_item::_StatementProd: { + case root_item::_Statement: { LangStmt *stmt = walkStatement( rootItem.Statement() ); if ( stmt != 0 ) stmtList->append( stmt ); break; } - case root_item::_ContextProd: + case root_item::_Context: walkContextDef( rootItem.ContextDef() ); break; - case root_item::_NamespaceProd: + case root_item::_Namespace: walkNamespaceDef( rootItem.NamespaceDef() ); break; - case root_item::_FunctionProd: + case root_item::_Function: walkFunctionDef( rootItem.FunctionDef() ); break; - case root_item::_IterProd: + case root_item::_Iter: walkIterDef( rootItem.IterDef() ); break; - case root_item::_PreEofProd: + case root_item::_PreEof: walkPreEof( rootItem.PreEofDef() ); break; - case root_item::_ExportProd: { + case root_item::_Export: { LangStmt *stmt = walkExportDef( rootItem.ExportDef() ); if ( stmt != 0 ) stmtList->append( stmt ); break; } - case root_item::_AliasProd: + case root_item::_Alias: walkAliasDef( rootItem.AliasDef() ); break; - case root_item::_PrecedenceProd: + case root_item::_Precedence: walkPrecedenceDef( rootItem.PrecedenceDef() ); break; - case root_item::_IncludeProd: { + case root_item::_Include: { StmtList *includeList = walkInclude( rootItem.Include() ); stmtList->append( *includeList ); break; } - case root_item::_GlobalProd: { + case root_item::_Global: { LangStmt *stmt = walkGlobalDef( rootItem.GlobalDef() ); if ( stmt != 0 ) stmtList->append( stmt ); -- cgit v1.2.1