Last active
November 10, 2015 03:57
-
-
Save tyage/9594048b2f8679d4fd3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asts = %w(translation_unit external_declaration function_definition_list argument_list argument declaration_statement_list declaration_statement statement_list statement parameter_list parameter identifier integer_literal character_literal expression) | |
%w(compound expression while if for return).each do |statement| | |
asts.push(statement + '_statement') | |
end | |
%w(assign or and comparative additive multiplicative unary postfix function_call primary parentheses).each do |expression| | |
asts.push(expression + '_expression') | |
end | |
asts.each do |ast| | |
camelCase = ast.split('_').map{|exp| exp[0].upcase + exp.slice(1, exp.size) } | |
upcase = ast.upcase | |
File.open("#{ast}.hpp", "w+") do |f| | |
body = <<"EOF" | |
#ifndef KMC_C89_COMPILER_AST_#{upcase}_HPP | |
#define KMC_C89_COMPILER_AST_#{upcase}_HPP | |
class AST#{camelCase.join('')} : public ASTBase { | |
}; | |
#endif | |
EOF | |
f.write(body) | |
end | |
File.open("#{ast}.cpp", "w+") do |f| | |
body = <<"EOF" | |
#include "#{ast}.hpp" | |
EOF | |
f.write(body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment